Package: pyneurosdk2
Python NeuroSDK 2Welcome to the Python NeuroSDK 2. The Neurosdk library is designed to work with BrainBit, BrainBitBlack, Callibri and Kolibri devices. The library is intended for python version 3.7 and higher, Windows version 10 and higher.DocumentationInstallingDescriptionSearching deviceConnectionParametersReceiving signalReceiving resistanceElectrodes connectionClean upInstallingpip install pyneurosdk2DescriptionThe package has the following structure:neurosdk - the main package with the implementation of methodssample - is into the neurosdk package, filesample.pylibs - also into neurosdk package, contain dll library filesThe library provides three main modules:scanner - to search for devicesfromneurosdk.scannerimportScannersensor - methods of interaction with the devicefromneurosdk.callibri_sensorimportCallibriSensorfromneurosdk.brainbit_sensorimportBrainBitSensorfromneurosdk.brainbit_black_sensorimportBrainBitBlackSensortypes - implementation of all types of the library, you can either connect everything or only those necessary for a specific taskfromneurosdk.cmn_typesimport*Searching deviceTheScannerclass is used to search for a device. For a correct search, you must specify the list of device types. You can search for one or more device types at the same time. For example, to search for BrainBit and Callibri, you need to create a scanner as follows:scanner=Scanner([SensorFamily.LEBrainBit,SensorFamily.LECallibri])Search start:scanner.start()Stop search:scanner.stop()All found devices can be obtained using the method:sensors=scanner.sensors()During the search, ansensorsChangedcallback will be called, which will display a list of found devices. If the device leaves the scanner's field of view for any reason, the device will disappear from the list after 12 seconds.defsensorFound(scanner,sensors):foriinrange(len(sensors)):print('Sensor%s'%sensors[i])scanner.sensorsChanged=sensorFoundThe sensor's list will contain records of the SensorInfo type with fields:SensFamily: SensorFamilySensModel: intName: strAddress: strSerialNumber: strPairingRequired: boolRSSI: intImportant!
The serial number of the Callibri and Kolibri does not appear in the SensorInfo recieving during the search. To get this value, you need to connect to the device and request the serial number manually:sn=sensor.serial_numberConnectionNext, you can create any device from the list using the method:sensor=scanner.create_sensor(sensInfo)When created, the device will connect automatically. This is a blocking function, so it is desirable to call it from an separate thread. Upon successful connection, a sensor instance will be returned. If unsuccessful, an exception is thrown. On subsequent connections and disconnections, a callback will be called indicating the state of the device.To disconnect from the device, use the following method:sensor.disconnect()To connect to a device created but not connected for any reason, the method:sensor.connect()It is blocking too.ParametersSDK allows you to get information about the connected device:print(sensor.sens_family)# SensorFamily.LEBrainBitprint(sensor.features)# [<SensorFeature.Signal: 0>, ...]print(sensor.commands)# [<SensorCommand.StartSignal: 0>,...]print(sensor.parameters)print(sensor.name)# BrainBitprint(sensor.state)# SensorState.StateInRangeprint(sensor.address)# AA:BB:CC:DD:EE:FFprint(sensor.serial_number)# 123456print(sensor.batt_power)# 50print(sensor.sampling_frequency)# SensorSamplingFrequency.FrequencyHz250print(sensor.gain)# SensorGain.Gain6print(sensor.data_offset)# SensorDataOffset.DataOffset0print(sensor.version)# SensorVersion(FwMajor=50, FwMinor=0, FwPatch=0, HwMajor=1, HwMinor=0, HwPatch=0, ExtMajor=65)You can distinguish BrainBit device from Flex by the firmware version number: if theSensorVersion.FwMajoris more than 100 - it's Flex, if it's less than BrainBit.If you need to change any property, you first need to check if it is writable. This can be done by reading the list of device parameters, where each parameter will have an access level:[ParameterInfo(Param=<SensorParameter.Offset: 8>, ParamAccess=<SensorParamAccess.Read: 0>),  
 ParameterInfo(Param=<SensorParameter.State: 1>,  ParamAccess=<SensorParamAccess.ReadNotify: 2>)
 ...]And also check the support of certain modules:sensor.is_supported_feature(sensor_future)sensor.is_supported_command(sensor_command)sensor.is_supported_parameter(sensor_parameter)Receiving signalFor any device that supports recieving signal, you can run the following commands for starting:sensor.exec_command(SensorCommand.StartSignal)Stop:sensor.exec_command(SensorCommand.StopSignal)BrainBit, BrainBitBlack, FlexYou can get the signal value using the callback:defonBrainBitSignalDataReceived(sensor,data):print(data)sensor.brainBitSignalDataReceived=onBrainBitSignalDataReceivedAfter you have finished working with the signal, you can unsubscribe from the callback as follows:sensor.brainBitSignalDataReceived=NoneIt gives a list of packages. Each package contains:PackNum: intMarker: intO1: floatO2: floatT3: floatT4: floatIt is values from 4 channels in volts, a number for each packet and a marker if it was sent and this feature is supported by the device.Callibri, KolibriYou can get the signal value using the callback:defonCallibriSignalDataReceived(sensor,data):print(data)sensor.callibriSignalDataReceived=onCallibriSignalDataReceivedAfter you have finished working with the signal, you can unsubscribe from the callback as follows:sensor.callibriSignalDataReceived=NoneIt gives a list of packages. Each package contains:PackNum: intSamples: [float]It is values in volts and a number for each packet.Receiving resistanceResistance is only supported by BrainBit, BrainBitBlack and Flex. You can also check the availability of these features using the methodsensor.is_supported_feature(SensorFeature.Resist).To get resistance values:defonBrainBitResistDataReceived(sensor,data):print(data)sensor.brainBitResistDataReceived=onBrainBitResistDataReceivedsensor.exec_command(SensorCommand.StartResist)sensor.exec_command(SensorCommand.StopResist)The callback returns one packet of samples, each packet contains the resistance values in volts:O1: floatO2: floatT3: floatT4: floatAfter you have finished working with the resistance, you can unsubscribe from the callback as follows:sensor.brainBitResistDataReceived=NoneBrainBit cannot be in the resistance and signal readout mode at the same time, so you must first get the resistance values, but only after this signal, or vice versa. For example:sensor.exec_command(SensorCommand.StartResist)sleep(10)sensor.exec_command(SensorCommand.StopResist)...sensor.exec_command(SensorCommand.StartSignal)sleep(10)sensor.exec_command(SensorCommand.StopSignal)Electrodes connectionElectrode placement check is available for Callibri and Kolibri devices. This data shows whether the electrodes are attached to the skin.defonCallibriElectrodeStateChanged(sensor,data):print(data)sensor.electrodeStateChanged=onCallibriElectrodeStateChangedFor unsubscribe from callback:sensor.electrodeStateChanged=NoneElectrodes state can be one of values of enum:ElStNormal = 0ElStHighResistance = 1ElStDetached = 2To get the state of the electrodes, you need to start a signal from the device.You can receive electrode and signal values at the same time.Clean upAfter you finish working with the device, you need to clean up the resources used. This happens in the destructor of the scanner and sensor, so if they were not called by the system, you must call them manually.delsensordelscannerLicenseCopyright (c) Brainbit Inc. All rights reserved.Licensed under theMIT license.