Failed to write value to characteristic(Error trying to issue command mid state)

Hi All:
I am using the class TestGpioAdcPulse(TestMetaWearBase) test example as a guide (https://github.com/mbientlab/MetaWear-SDK-Cpp/blob/0.16.3/test/test_dataprocessor.py#L289) to create a Gpio Pin monitor script.

Here's my code snippet:

class TestGpioSensor():
    def __init__(self, *args, **kwargs):
        self.device = MetaWear(sys.argv[1])
        self.handler_fn = FnVoid_VoidP_VoidP(self.proc_handler)
        self.state_handler_fn = FnVoid_VoidP_DataP(self.state_handler)
        self.status_handler_fn = FnVoid_VoidP_VoidP_Int(self.status_handler)
        self.pattern= LedPattern(repeat_count= 10)
        self.sensor_data_handler= FnVoid_VoidP_DataP(self.sensorDataHandler)
        self.event = Event()
        self.setUpGpio()
        self.t1 = Thread(target=self.flag)
        self.t2 = Thread(target=self.StartMonitoring)

    def handle_sensor_data(context, data):
        print("data received:  %s" % (parse_value(data)))

    def pulse_processor_created(self, context, pulse):
        self.pulse_signal= pulse
        libmetawear.mbl_mw_datasignal_subscribe(pulse, None, self.fn_wrapper)
        self.event.set()

    def setUpGpio(self):
        self.fn_wrapper = FnVoid_VoidP_DataP(self.handle_sensor_data)
        self.pulse_handler= FnVoid_VoidP_VoidP(self.pulse_processor_created)

    def WaitForGpio(self):
        self.gpio_adc_signal= libmetawear.mbl_mw_gpio_get_analog_input_data_signal(self.device.board, 0, GpioAnalogReadMode.ADC)
        libmetawear.mbl_mw_dataprocessor_pulse_create(self.gpio_adc_signal, PulseOutput.PEAK, 500.0, 10, None, self.pulse_handler)
        self.event.wait()

In WaitForGpio(self): calling libmetawear.mbl_mw_dataprocessor_pulse_create(self.gpio_adc_signal, PulseOutput.PEAK, 500.0, 10, None, self.pulse_handler) results in error:

             "Failed to write value to characteristic(Error trying to issue command mid state)"

rp@SS: python DC.py F9:4E:B7:A1:F7:CE
error 1542066425.108170: Error on line: 296 (src/blestatemachine.cc): Operation now in progress
Connected (1)
Failed to write value to characteristic(Error trying to issue command mid state)
Segmentation fault

I tried to google for the error but could not find any direction.

Can anyone please help what I'm missing here?

Thank you.

Comments

  • Post a script that consistently produces this issue that can be run as is.

    Monitor the BT adapter and post the activity log leading up to the crash.

  • Hi Eric:

    Since you added data_fuser.py, I did a clean build/install the MetaWear-SDK-Python (0.6.1) and MetaWear-SDK-Cpp (0.17.0).

    Then, to derive from data_fuser.py, first I ran data_fuser.py (unchanged, except adding the debug printfs) but the script seg faults when calling libmetawear.mbl_mw_datasignal_subscribe() on line 38 (https://github.com/mbientlab/MetaWear-SDK-Python/blob/0.6.1/examples/data_fuser.py):

    spy35_env) pi@SS:~/SSquare/sspy35_env/MB/MetaWear-SDK-Python/examples $ python data_fuser.py F9:4E:B7:A1:F7:CE
    error 1542810072.026808: Error on line: 296 (src/blestatemachine.cc): Operation now in progress
    Connected to F9:4E:B7:A1:F7:CE
    configuring F9:4E:B7:A1:F7:CE
    mbl_mw_settings_set_connection_parameters
    mbl_mw_acc_get_acceleration_data_signal
    mbl_mw_gyro_bmi160_get_rotation_data_signal
    mbl_mw_dataprocessor_fuser_create
    Segmentation fault
    (sspy35_env) pi@SS:~/SSquare/sspy35_env/MB/MetaWear-SDK-Python/examples $

    If I comment out the mbl_mw_datasignal_subscribe() then the output is:
    (sspy35_env) pi@SS:~/SSquare/sspy35_env/MB/MetaWear-SDK-Python/examples $ !py
    python data_fuser.py F9:4E:B7:A1:F7:CE
    error 1542811687.837156: Error on line: 296 (src/blestatemachine.cc): Operation now in progress
    Connected to F9:4E:B7:A1:F7:CE
    configuring F9:4E:B7:A1:F7:CE
    mbl_mw_settings_set_connection_parameters
    mbl_mw_acc_get_acceleration_data_signal
    mbl_mw_gyro_bmi160_get_rotation_data_signal
    mbl_mw_dataprocessor_fuser_create
    mbl_mw_datasignal_subscribe
    mbl_mw_gyro_bmi160_enable_rotation_sampling
    mbl_mw_acc_enable_acceleration_sampling
    mbl_mw_gyro_bmi160_start
    mbl_mw_acc_start
    resetting devices
    (sspy35_env) pi@SS:~/SSquare/sspy35_env/MB/MetaWear-SDK-Python/examples $

    Once I get through the above problem I can step forward modifying for my application.

    Thanks for your help.

  • Post the information I requested in my previous post.

  • Eric:
    Here is the script I added print statements.
    It crashes if I call libmetawear.mbl_mw_datasignal_subscribe().
    There is no output other than the print statements I sent earlier.

    Thanks

    from ctypes import c_void_p, cast, POINTER
    from mbientlab.metawear import MetaWear, libmetawear, parse_value, cbindings
    from time import sleep
    from threading import Event
    from sys import argv
    
    states = []
    
    class State:
        def __init__(self, device):
            self.device = device
            self.callback = cbindings.FnVoid_VoidP_DataP(self.data_handler)
            self.processor = None
    
        def data_handler(self, ctx, data):
            values = parse_value(data, n_elem = 2)
            print("acc: (%.4f,%.4f,%.4f), gyro; (%.4f,%.4f,%.4f)" % (values[0].x, values[0].y, values[0].z, values[1].x, values[1].y, values[1].z))
    
        def setup(self):
            libmetawear.mbl_mw_settings_set_connection_parameters(self.device.board, 7.5, 7.5, 0, 6000)
            print("mbl_mw_settings_set_connection_parameters")
            sleep(1.5)
    
            e = Event()
    
            def processor_created(context, pointer):
                self.processor = pointer
                e.set()
            fn_wrapper = cbindings.FnVoid_VoidP_VoidP(processor_created)
    
            acc = libmetawear.mbl_mw_acc_get_acceleration_data_signal(self.device.board)
            print("mbl_mw_acc_get_acceleration_data_signal")
            gyro = libmetawear.mbl_mw_gyro_bmi160_get_rotation_data_signal(self.device.board)
            print("mbl_mw_gyro_bmi160_get_rotation_data_signal")
    
            signals = (c_void_p * 1)()
            signals[0] = gyro
            libmetawear.mbl_mw_dataprocessor_fuser_create(acc, signals, 1, None, fn_wrapper)
            e.wait()
            print("mbl_mw_dataprocessor_fuser_create")
    
            #libmetawear.mbl_mw_datasignal_subscribe(self.processor, None, self.callback)
            print("mbl_mw_datasignal_subscribe")
    
        def start(self):
            libmetawear.mbl_mw_gyro_bmi160_enable_rotation_sampling(self.device.board)
            print("mbl_mw_gyro_bmi160_enable_rotation_sampling")
            libmetawear.mbl_mw_acc_enable_acceleration_sampling(self.device.board)
            print("mbl_mw_acc_enable_acceleration_sampling")
    
            libmetawear.mbl_mw_gyro_bmi160_start(self.device.board)
            print("mbl_mw_gyro_bmi160_start")
            libmetawear.mbl_mw_acc_start(self.device.board)
            print("mbl_mw_acc_start")
    
    for i in range(len(argv) - 1):
        d = MetaWear(argv[i + 1])
        d.connect()
        print("Connected to " + d.address)
        states.append(State(d))
    
    for s in states:
        print("configuring %s" % (s.device.address))
        s.setup()
    
    for s in states:
        s.start()
    
    sleep(10.0)
    
    print("resetting devices")
    events = []
    for s in states:
        e = Event()
        events.append(e)
    
        s.device.on_disconnect = lambda s: e.set()
        libmetawear.mbl_mw_debug_reset(s.device.board)
    
    for e in events:
        e.wait()
    
    
  • edited November 2018

    The data fuser script has nothing to do with the issue in this thread.

    Post the information I requested in my previous post.

  • Since the old code is no longer being used in the pre-(data fuser) release, consider this issue closed. I wlll open a new one.
    Thanks

This discussion has been closed.