import socket import struct import serial class AttrDict(dict): def __init__(self, *args, **kwargs): super(AttrDict, self).__init__(*args, **kwargs) self.__dict__ = self class TriggerNeuracle: def __init__(self, port, **kwargs): self.kwargs = kwargs # initiate triggerbox self.triggerbox = TriggerBox(port=port) def send_trigger(self, data): # directly using serial port self.triggerbox.OutputEventData(data) class TriggerBox(object): """docstring for TriggerBox""" functionIDSensorParaGet = 1 functionIDSensorParaSet = 2 functionIDDeviceInfoGet = 3 functionIDDeviceNameGet = 4 functionIDSensorSampleGet = 5 functionIDSensorInfoGet = 6 functionIDOutputEventData = 225 functionIDError = 131 sensorTypeDigitalIN = 1 sensorTypeLight = 2 sensorTypeLineIN = 3 sensorTypeMic = 4 sensorTypeKey = 5 sensorTypeTemperature = 6 sensorTypeHumidity = 7 sensorTypeAmbientlight = 8 sensorTypeDebug = 9 sensorTypeAll = 255 deviceID = 1 # TODO: get device ID # properties comportHandle = None deviceName = None deviceInfo = None sensorInfo = None tcpOutput = None def __init__(self, port=None, tcpPort=None): if tcpPort is not None: self.tcpOutput = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.tcpOutput.connect(('localhost', tcpPort)) self.comportHandle = serial.Serial(port, 115200, timeout=0.05) self.comportHandle.flush() self.GetDeviceName() self.GetDeviceInfo() self.GetSensorInfo() def OutputEventData(self, eventData): # directly mark trigger with serial # eventData is an unsigned short assert isinstance(eventData, int) msg = struct.pack('