首頁>技術>

首先利用ES581使用的動態鏈庫(C++封裝)icsneo40.dll,本文將icsneo40.dll進行了二次封裝(僅封裝了icsneo40.dll中的原始函式),本文將用python實現ES581的傳送與接收,即透過呼叫C#的庫實現收發,若想進一步瞭解函式介面,可查閱ics文件。

實現核心程式碼在ES581.py中,在ES581Demo.py中展示呼叫示例:

ES581.py:from enum import Enumimport win32api,win32conimport  clrimport timeclr.FindAssembly("ICSNeoDevice.dll")clr.AddReference('ICSNeoDevice')from ICSNeoDevice import  *icsNeo = ICSNeo()m_bPortOpen = Falsem_hObject = 0;  # handle for deviceiOpenDeviceType = 0;  # Storage for the device type that is openarbIDHeader = '101'class eHardwardTypes(Enum):    NEODEVICE_UNKNOWN = 0x00000000    NEODEVICE_BLUE = 0x00000001    NEODEVICE_ECU_AVB = 0x00000002    NEODEVICE_RADSUPERMOON = 0x00000003    NEODEVICE_DW_VCAN = 0x00000004    NEODEVICE_RADMOON2 = 0x00000005    NEODEVICE_RADGIGALOG = 0x00000006    NEODEVICE_VCAN41 = 0x00000007    NEODEVICE_FIRE = 0x00000008    NEODEVICE_RADPLUTO = 0x00000009    NEODEVICE_VCAN42_EL = 0x0000000a    NEODEVICE_RADIO_CANHUB = 0x0000000b    NEODEVICE_NEOECU12 = 0x0000000c    NEODEVICE_OBD2_LCBADGE = 0x0000000d    NEODEVICE_RAD_MOON_DUO = 0x0000000e    NEODEVICE_VCAN3 = 0x00000010    NEODEVICE_RADJUPITER = 0x00000011    NEODEVICE_VCAN4_IND = 0x00000012    NEODEVICE_GIGASTAR = 0x00000013    NEODEVICE_ECU22 = 0x00000015    NEODEVICE_RED = 0x00000040    NEODEVICE_ECU = 0x00000080    NEODEVICE_IEVB = 0x00000100    NEODEVICE_PENDANT = 0x00000200    NEODEVICE_OBD2_PRO = 0x00000400    NEODEVICE_PLASMA = 0x00001000    NEODEVICE_NEOANALOG = 0x00004000    NEODEVICE_CT_OBD = 0x00008000    NEODEVICE_ION = 0x00040000    NEODEVICE_RADSTAR = 0x00080000    NEODEVICE_VCAN44 = 0x00200000    NEODEVICE_VCAN42 = 0x00400000    NEODEVICE_CMPROBE = 0x00800000    NEODEVICE_EEVB = 0x01000000    NEODEVICE_VCANRF = 0x02000000    NEODEVICE_FIRE2 = 0x04000000    NEODEVICE_FLEX = 0x08000000    NEODEVICE_RADGALAXY = 0x10000000    NEODEVICE_RADSTAR2 = 0x20000000    NEODEVICE_VIVIDCAN = 0x40000000    NEODEVICE_OBD2_SIM = 0x80000000    NEODEVICE_ALL = 0xFFFFBFFFclass eDATA_STATUS_BITFIELD_1(Enum):    SPY_STATUS_GLOBAL_ERR = 0x01    SPY_STATUS_TX_MSG = 0x2    SPY_STATUS_XTD_FRAME = 0x04    SPY_STATUS_REMOTE_FRAME = 0x08    SPY_STATUS_CRC_ERROR = 0x10    SPY_STATUS_CAN_ERROR_PASSIVE = 0x20    SPY_STATUS_INCOMPLETE_FRAME = 0x40    SPY_STATUS_LOST_ARBITRATION = 0x80    SPY_STATUS_UNDEFINED_ERROR = 0x100    SPY_STATUS_CAN_BUS_OFF = 0x200    SPY_STATUS_CAN_ERROR_WARNING = 0x400    SPY_STATUS_BUS_SHORTED_PLUS = 0x800    SPY_STATUS_BUS_SHORTED_GND = 0x1000    SPY_STATUS_CHECKSUM_ERROR = 0x2000    SPY_STATUS_BAD_MESSAGE_BIT_TIME_ERROR = 0x4000    SPY_STATUS_IFR_DATA = 0x8000    SPY_STATUS_COMM_IN_OVERFLOW = 0x10000    SPY_STATUS_COMM_OUT_OVERFLOW = 0x20000    SPY_STATUS_COMM_MISC_ERROR = 0x40000    SPY_STATUS_BREAK = 0x80000    SPY_STATUS_AVSI_REC_OVERFLOW = 0x100000    SPY_STATUS_TEST_TRIGGER = 0x200000    SPY_STATUS_AUDIO_COMMENT = 0x400000    SPY_STATUS_GPS_DATA = 0x800000    SPY_STATUS_ANALOG_DIGITAL_INPUT = 0x1000000    SPY_STATUS_TEXT_COMMENT = 0x2000000    SPY_STATUS_NETWORK_MESSAGE_TYPE = 0x4000000    SPY_STATUS_VSI_TX_UNDERRUN = 0x8000000    SPY_STATUS_VSI_IFR_CRC_BIT = 0x10000000    SPY_STATUS_INIT_MESSAGE = 0x20000000    SPY_STATUS_HIGH_SPEED = 0x40000000    SPY_STATUS_FLEXRAY_SECOND_STARTUP_FRAME = 0x40000000    SPY_STATUS_EXTENDED = 0x80000000    # if this bit is set than decode status bitfield3 in the ackbytesclass eNumberOfBytes(Enum):    NUMBER_OF_BYTES_0 = 0    NUMBER_OF_BYTES_1 = 1    NUMBER_OF_BYTES_2 = 2    NUMBER_OF_BYTES_3 = 3    NUMBER_OF_BYTES_4 = 4    NUMBER_OF_BYTES_5 = 5    NUMBER_OF_BYTES_6 = 6    NUMBER_OF_BYTES_7 = 7    NUMBER_OF_BYTES_8 = 8class ePROTOCOL(Enum):        SPY_PROTOCOL_CUSTOM = 0        SPY_PROTOCOL_CAN = 1        SPY_PROTOCOL_GMLAN = 2        SPY_PROTOCOL_J1850VPW = 3        SPY_PROTOCOL_J1850PWM = 4        SPY_PROTOCOL_ISO9141 = 5        SPY_PROTOCOL_Keyword2000 = 6        SPY_PROTOCOL_GM_ALDL_UART = 7        SPY_PROTOCOL_CHRYSLER_CCD = 8        SPY_PROTOCOL_CHRYSLER_SCI = 9        SPY_PROTOCOL_FORD_UBP = 10        SPY_PROTOCOL_BEAN = 11        SPY_PROTOCOL_LIN = 12        SPY_PROTOCOL_J1708 = 13        SPY_PROTOCOL_CHRYSLER_JVPW = 14        SPY_PROTOCOL_J1939 = 15        SPY_PROTOCOL_FLEXRAY = 16        SPY_PROTOCOL_MOST = 17        SPY_PROTOCOL_CGI = 18        SPY_PROTOCOL_GME_CIM_SCL_KLINE = 19        SPY_PROTOCOL_SPI = 20        SPY_PROTOCOL_I2C = 21        SPY_PROTOCOL_GENERIC_UART = 22        SPY_PROTOCOL_JTAG = 23        SPY_PROTOCOL_UNIO = 24        SPY_PROTOCOL_DALLAS_1WIRE = 25        SPY_PROTOCOL_GENERIC_MANCHSESTER = 26        SPY_PROTOCOL_SENT_PROTOCOL = 27        SPY_PROTOCOL_UART = 28        SPY_PROTOCOL_ETHERNET = 29        SPY_PROTOCOL_CANFD = 30        SPY_PROTOCOL_GMFSA = 31        SPY_PROTOCOL_TCP = 32class eNETWORK_ID(Enum):    NETID_DEVICE = 0    NETID_HSCAN = 1    NETID_MSCAN = 2    NETID_SWCAN = 3    NETID_LSFTCAN = 4    NETID_ISO = 9    NETID_ISO2 = 14    NETID_ISO14230 = 15    NETID_LIN = 16    NETID_OP_ETHERNET1 = 17    NETID_OP_ETHERNET2 = 18    NETID_OP_ETHERNET3 = 19    NETID_ISO3 = 41    NETID_HSCAN2 = 42    NETID_HSCAN3 = 44    NETID_OP_ETHERNET4 = 45    NETID_OP_ETHERNET5 = 46    NETID_ISO4 = 47    NETID_LIN2 = 48    NETID_LIN3 = 49    NETID_LIN4 = 50    NETID_MOST = 51    NETID_CGI = 53    NETID_HSCAN4 = 61    NETID_HSCAN5 = 62    NETID_UART = 64    NETID_UART2 = 65    NETID_UART3 = 66    NETID_UART4 = 67    NETID_SWCAN2 = 68    NETID_ETHERNET_DAQ = 69    NETID_OP_ETHERNET6 = 73    NETID_OP_ETHERNET7 = 75    NETID_OP_ETHERNET8 = 76    NETID_OP_ETHERNET9 = 77    NETID_OP_ETHERNET10 = 78    NETID_OP_ETHERNET11 = 79    NETID_FLEXRAY1A = 80    NETID_FLEXRAY1B = 81    NETID_FLEXRAY2A = 82    NETID_FLEXRAY2B = 83    NETID_LIN5 = 84    NETID_FLEXRAY = 85    NETID_FLEXRAY2 = 86    NETID_OP_ETHERNET12 = 87    NETID_MOST25 = 90    NETID_MOST50 = 91    NETID_MOST150 = 92    NETID_ETHERNET = 93    NETID_HSCAN6 = 96    NETID_HSCAN7 = 97    NETID_LIN6 = 98    NETID_LSFTCAN2 = 99class stCM_ISO157652_TxMessage_Flags(Enum):        id_29_bit_enable = 1 # Enables 29 bit arbId for transmitted frames.  Set to 1 so transmitted frames use 29 bit ids, not supported.        fc_id_29_bit_enable = 2 #< Enables 29 bit arbId for Flow Control filter.  Set to 1 if receiver response uses 29 bit ids, not supported.        ext_address_enable = 4 # Enables Extended Addressing, Set to 1 if transmitted frames should have extended addres byte, not supported.        fc_ext_address_enable = 8 #< Enables Extended Addressing for Flow Control filter.  Set to 1 if receiver responds with extended address byte, not supported.        overrideSTmin = 16 #Uses member stMin and not receiver's flow control's stMin.        overrideBlockSize = 32 #< Uses member BlockSize and not receiver's flow control's BlockSize.        paddingEnable = 64 #Enable's padding        iscanFD = 128 #Enables CAN FD        isBSREnabled = 256 #Enables BSRclass filter:    arbID = 0    data0 = 0    data1 = 0    data2 = 0    data3 = 0    data4 = 0def OpenDevice():    bNetwork = bytearray(255)    iNumberOfDevices = 0 #Number of hardware devices to look for    iCount = 0 #counter    stringSize = 6    bSN = bytearray(6)    #check if the port is already open    global  m_bPortOpen    if m_bPortOpen == True:        return    #file NetworkID array    for iCount in range(0, 255):        bNetwork.insert(iCount, iCount)#int(iCount).to_bytes(length=2, byteorder='big', signed=True))    # Set the number of devices to find,for this example look for 16.  This example will only work with the first.    iNumberOfDevices = 15    deviceClass = NeoDevice()    #search for connected hardware    iResult = icsNeo.icsneoFindNeoDevices(eHardwardTypes.NEODEVICE_ALL.value, deviceClass, iNumberOfDevices)    deviceClass = iResult[1]    iNumberOfDevices = iResult[2]    if iResult[0] == 0:        win32api.MessageBox(0, "Problem finding devices", "提示", win32con.MB_OK)        return    if(iNumberOfDevices < 1):        win32api.MessageBox(0, "No devices found", "提示", win32con.MB_OK)        return    global m_hObject    global iOpenDeviceType    m_hObject = icsNeo.GetIntPtr()    iOpenDeviceType = 10    iResult = icsNeo.icsneoOpenNeoDevice(deviceClass, m_hObject, bNetwork, 1, 0)    iOpenDeviceType = iResult[1] #set the device types for later use    m_hObject = iResult[2]    bNetwork = iResult[3]    if iResult[0] == 1:        # win32api.MessageBox(0, "Port Opened OK!", "提示", win32con.MB_OK)        print('Port Opened OK!')    else:        win32api.MessageBox(0, "Problem Opening Port!", "提示", win32con.MB_OK)        return    #display the connect hardware type    if deviceClass.DeviceType == eHardwardTypes.NEODEVICE_BLUE.value:        print('neoVI Blue SN', deviceClass.SerialNumber)    elif deviceClass.DeviceType == eHardwardTypes.NEODEVICE_DW_VCAN.value:        print('Value CAN 2 SN', deviceClass.SerialNumber)    elif deviceClass.DeviceType == eHardwardTypes.NEODEVICE_FIRE.value:        print('neoVI FIRE SN ', deviceClass.SerialNumber)    elif deviceClass.DeviceType == eHardwardTypes.NEODEVICE_VCAN3.value:        print('ValueCAN 3 SN', deviceClass.SerialNumber)    elif deviceClass.DeviceType == eHardwardTypes.NEODEVICE_FIRE2.value:        neoResult = icsNeo.icsneoSerialNumberToString(deviceClass.SerialNumber, bSN[0], stringSize)        bSN = neoResult[1]        stringSize = neoResult[2]        print('neoVI FIRE 2 SN ',str(bSN, encoding = "utf-8"))    elif deviceClass.DeviceType == eHardwardTypes.NEODEVICE_PLASMA.value:        print('neoVI PLASMA SN ', deviceClass.SerialNumber)    elif deviceClass.DeviceType == eHardwardTypes.NEODEVICE_ION.value:        print('neoVI ION SN ', deviceClass.SerialNumber)    elif deviceClass.DeviceType == eHardwardTypes.NEODEVICE_VCANRF.value:        neoResult = icsNeo.icsneoSerialNumberToString(deviceClass.SerialNumber, bSN[0], stringSize)        bSN = neoResult[1]        stringSize = neoResult[2]        print('ValueCAN.rf SN ', str(bSN, encoding = "utf-8"))    elif deviceClass.DeviceType == eHardwardTypes.NEODEVICE_RADGALAXY.value:        neoResult = icsNeo.icsneoSerialNumberToString(deviceClass.SerialNumber, bSN[0], stringSize)        bSN = neoResult[1]        stringSize = neoResult[2]        print('RadGalaxy SN ', str(bSN, encoding = "utf-8"))    elif deviceClass.DeviceType == eHardwardTypes.NEODEVICE_VCAN41.value:        neoResult = icsNeo.icsneoSerialNumberToString(deviceClass.SerialNumber, bSN[0], stringSize)        bSN = neoResult[1]        stringSize = neoResult[2]        print('ValueCAN 4-1 SN ', str(bSN, encoding = "utf-8"))    elif deviceClass.DeviceType == eHardwardTypes.NEODEVICE_VCAN42.value:        neoResult = icsNeo.icsneoSerialNumberToString(deviceClass.SerialNumber, bSN[0], stringSize)        bSN = neoResult[1]        stringSize = neoResult[2]        print('ValueCAN 4-2 SN ', str(bSN, encoding = "utf-8"))    elif deviceClass.DeviceType == eHardwardTypes.NEODEVICE_VCAN42_EL.value:        neoResult = icsNeo.icsneoSerialNumberToString(deviceClass.SerialNumber, bSN[0], stringSize)        bSN = neoResult[1]        stringSize = neoResult[2]        print('ValueCAN 4-2 SN ', str(bSN, encoding = "utf-8"))    elif deviceClass.DeviceType == eHardwardTypes.NEODEVICE_RADPLUTO.value:        neoResult = icsNeo.icsneoSerialNumberToString(deviceClass.SerialNumber, bSN[0], stringSize)        bSN = neoResult[1]        stringSize = neoResult[2]        print('RAD Pluto SN ', str(bSN, encoding = "utf-8"))    elif deviceClass.DeviceType == eHardwardTypes.NEODEVICE_RADSUPERMOON.value:        neoResult = icsNeo.icsneoSerialNumberToString(deviceClass.SerialNumber, bSN[0], stringSize)        bSN = neoResult[1]        stringSize = neoResult[2]        print('RAD SuperMoon SN ', str(bSN, encoding = "utf-8"))    else:        print('Unknown neoVI SN ', deviceClass.SerialNumber)    m_bPortOpen = True    time.sleep(1)def SendCANMessage(lNetworkID, IsExtendedID, data):    if data.__len__() <= 0:        print('send data of length is not 8 bytes')        return    messageClass = icsSpyMessage()    # Has the uset open neoVI yet?    if m_bPortOpen == False:        win32api.MessageBox(0, "neoVI not opened!", "提示", win32con.MB_OK)        return    if IsExtendedID == True:        # Make id Extended        messageClass.StatusBitField = eDATA_STATUS_BITFIELD_1.SPY_STATUS_XTD_FRAME.value    else:        messageClass.StatusBitField = 0    messageClass.ArbIDOrHeader = int(arbIDHeader, 16)    messageClass.NumberBytesData = eNumberOfBytes.NUMBER_OF_BYTES_8.value    if messageClass.NumberBytesData > 8:        messageClass.NumberBytesData = 8    messageClass.Data1 = data[0]    messageClass.Data2 = data[1]    messageClass.Data3 = data[2]    messageClass.Data4 = data[3]    messageClass.Data5 = data[4]    messageClass.Data6 = data[5]    messageClass.Data7 = data[6]    messageClass.Data8 = data[7]    # Transmit the assembled message    numberMessage = 1    iResult = icsNeo.icsneoTxMessages(m_hObject, messageClass, lNetworkID, numberMessage)    # messageClass = iResult[1]    if iResult[0] != 1:        win32api.MessageBox(0, "Problem Transmitting Message!", "提示", win32con.MB_OK)    else:        print('send CAN message success!')    time.sleep(1)def SendISO15765Message(networkID, arbID, flowControlArbID, numberOfDataSize, IsCheckPadding, IsCheckExtenedID, IsCheckFCExtenedID, IsUseCANFD, bydata):    # Has the uset open neoVI yet?    if m_bPortOpen == False:# check to see if the port is opened first        print('Device is Not Opened!')        return    # Create Message and adjust array to proper size    txMsg = stCM_ISO157652_TxMessage()    txMsg.data = bytearray(4096)    lResult = icsNeo.icsneoISO15765_EnableNetworks(m_hObject, networkID)    txMsg.id = int(arbID, 16) #int    txMsg.vs_netid = networkID #int    txMsg.num_bytes = numberOfDataSize #int    txMsg.padding = 0xAA # set padding byte    txMsg.flags = 0    iFlags = 0    if IsCheckPadding == True:        iFlags = iFlags | stCM_ISO157652_TxMessage_Flags.paddingEnable    if IsCheckExtenedID == True:        iFlags = iFlags | stCM_ISO157652_TxMessage_Flags.id_29_bit_enable    if IsCheckFCExtenedID == True:        iFlags = iFlags | stCM_ISO157652_TxMessage_Flags.fc_id_29_bit_enable    if IsUseCANFD == True:        iFlags  = iFlags | stCM_ISO157652_TxMessage_Flags.iscanFD    if IsUseCANFD == True:        iFlags = iFlags | stCM_ISO157652_TxMessage_Flags.isBSREnabled    txMsg.flags = iFlags    txMsg.fc_id = int(flowControlArbID, 16)    txMsg.fc_id_mask = 0xfff # The flow control arb filter mask (response id from receiver)    txMsg.flowControlExtendedAddress = int(IsCheckExtenedID) #Extended ID    txMsg.fs_timeout = 0x100 #Flow Control Time out in ms    txMsg.fs_wait = 0x3000 #Flow Control FS=Wait Timeout ms    txMsg.blockSize = 0 #Block size (for sending flow Control)    txMsg.stMin = 0    # fill data    blockTimeout = 3000    for iCount in range(0, len(bydata)):        txMsg.data[iCount] = bydata[iCount]    lResult = icsNeo.icsneoISO15765Message(m_hObject, networkID, txMsg, blockTimeout)    # txMsg = lResult[1]    # Test the returned result    if lResult[0] != 1:        print('Problem Transmitting Message')    print('send iso15756 message success!')    time.sleep(1)def GetMessage(filter):    if m_bPortOpen != True:        return    lNumberOfMessages = 0    lNumberOfErrors = 0    stJMsg = icsSpyMessageJ1850()    iByteCount = 0    iLongMessageTotalByteCount = 0    dTime = 0    iDataBytes = bytearray()    if m_hObject == False:        win32api.MessageBox(0, "neoVI not opened!", "提示", win32con.MB_OK)    # read the messages from the driver    global  icsSpyMessage    icsSpyMessage = icsSpyMessage()    # icsSpyMessageArray = icsNeo.getICSSpyMessageArray(1024 * 1024)#TempSpace for messages    icsSpyMessageArray = getNotBuidInArray(icsSpyMessage, 1024 * 1024);    print('object=', m_hObject)    iResult = icsNeo.icsneoGetMessages(m_hObject, icsSpyMessageArray, lNumberOfMessages, lNumberOfErrors)    icsSpyMessageArray = iResult[1]    lNumberOfMessages = iResult[2]    lNumberOfErrors = iResult[3]    print('Number Read:', lNumberOfMessages)    print('Number Errors:', lNumberOfErrors)    # was the read successful?    if iResult[0] != 1:        win32api.MessageBox(0, "Problem Reading Messages!", "提示", win32con.MB_OK)        return    icount = lNumberOfMessages + 1    for lCount in range(1, icount):        iResult = icsNeo.icsneoGetTimeStampForMsg(m_hObject, icsSpyMessageArray[lCount - 1], dTime)        dTime = iResult[2]        sListString = "time:" + str(dTime) + " lCount=" + str(lCount) + " ";        # Was it a tx or rx message        if (icsSpyMessageArray[lCount - 1].StatusBitField & eDATA_STATUS_BITFIELD_1.SPY_STATUS_TX_MSG.value) > 0:            sListString = sListString + "Tx "        else:            sListString = sListString + "Rx "        # Decode based on the protocol        if icsSpyMessageArray[lCount - 1].Protocol == ePROTOCOL.SPY_PROTOCOL_CAN.value:            sListString = sListString + "Network " + GetStringForNetworkID(icsSpyMessageArray[lCount - 1].NetworkID) + " ArbID:" + hex(icsSpyMessageArray[lCount - 1].ArbIDOrHeader) + " Data:"        elif icsSpyMessageArray[lCount - 1].Protocol == ePROTOCOL.SPY_PROTOCOL_CANFD.value:            sListString = sListString        elif icsSpyMessageArray[lCount - 1].Protocol == ePROTOCOL.SPY_PROTOCOL_ETHERNET.value:            if icsSpyMessageArray[lCount - 1].ExtraDataPtrEnabled == 0:                # 8 bytes of data                sListString = sListString + "Network " + GetStringForNetworkID(icsSpyMessageArray[lCount - 1].NetworkID) + " FD ArbID:" + hex(icsSpyMessageArray[lCount - 1].ArbIDOrHeader) + " Data:"            else :                if icsSpyMessageArray[lCount - 1].Protocol == ePROTOCOL.SPY_PROTOCOL_CANFD.value:                    #count for CAN FD                    iLongMessageTotalByteCount = icsSpyMessageArray[lCount - 1].NumberBytesData                else :                    #count for Ethernet                    iLongMessageTotalByteCount = icsSpyMessageArray[lCount - 1].NumberBytesHeader * 0x100 + icsSpyMessageArray[lCount - 1].NumberBytesData                #more than 8 bytes of data                iDataBytes = bytearray(iLongMessageTotalByteCount)                dataResult = icsNeo.GetMessageDataBuffer(icsSpyMessageArray, iDataBytes, iLongMessageTotalByteCount, lCount)                iDataBytes = dataResult[1]                sListString = sListString + "Network " + GetStringForNetworkID(icsSpyMessageArray[lCount - 1].NetworkID)                if icsSpyMessageArray[lCount - 1].Protocol == ePROTOCOL.SPY_PROTOCOL_CANFD:                    sListString = sListString + "FD ArbID : " +hex(icsSpyMessageArray[lCount - 1].ArbIDOrHeader)                sListString = sListString + " Data "                for iByteCount in range(0, iLongMessageTotalByteCount):                    sListString = sListString + hex(iDataBytes[iByteCount])        else:            # list the header bytes            dataResult = icsNeo.ConvertCANtoJ1850Message(icsSpyMessageArray[lCount - 1], stJMsg)            stJMsg = dataResult[1]            print('stJmsg=', dataResult[0])            print('len=', len(dataResult))            sListString = sListString + "Network " + GetStringForNetworkID(icsSpyMessageArray[lCount - 1].NetworkID) + " Data:"            #add the data bytes            if stJMsg.NumberBytesHeader >= 1:                sListString = sListString + stJMsg.Header1 + " "            if stJMsg.NumberBytesHeader >= 2:                sListString = sListString + stJMsg.Header2 + " "            if stJMsg.NumberBytesHeader >= 3:                sListString = sListString + stJMsg.Header3 + " "            sListString = sListString + " "        if icsSpyMessageArray[lCount - 1].NumberBytesData >= 1 and icsSpyMessageArray[lCount - 1].ExtraDataPtrEnabled == 0:            sListString = sListString + hex(icsSpyMessageArray[lCount - 1].Data1) + " "        if icsSpyMessageArray[lCount - 1].NumberBytesData >= 2 and icsSpyMessageArray[lCount - 1].ExtraDataPtrEnabled == 0:            sListString = sListString + hex(icsSpyMessageArray[lCount - 1].Data2) + " "        if icsSpyMessageArray[lCount - 1].NumberBytesData >= 3 and icsSpyMessageArray[lCount - 1].ExtraDataPtrEnabled == 0:            sListString = sListString + hex(icsSpyMessageArray[lCount - 1].Data3) + " "        if icsSpyMessageArray[lCount - 1].NumberBytesData >= 4 and icsSpyMessageArray[lCount - 1].ExtraDataPtrEnabled == 0:            sListString = sListString + hex(icsSpyMessageArray[lCount - 1].Data4) + " "        if icsSpyMessageArray[lCount - 1].NumberBytesData >= 5 and icsSpyMessageArray[lCount - 1].ExtraDataPtrEnabled == 0:            sListString = sListString + hex(icsSpyMessageArray[lCount - 1].Data5) + " "        if icsSpyMessageArray[lCount - 1].NumberBytesData >= 6 and icsSpyMessageArray[lCount - 1].ExtraDataPtrEnabled == 0:            sListString = sListString + hex(icsSpyMessageArray[lCount - 1].Data6) + " "        if icsSpyMessageArray[lCount - 1].NumberBytesData >= 7 and icsSpyMessageArray[lCount - 1].ExtraDataPtrEnabled == 0:            sListString = sListString + hex(icsSpyMessageArray[lCount - 1].Data7) + " "        if icsSpyMessageArray[lCount - 1].NumberBytesData >= 8 and icsSpyMessageArray[lCount - 1].ExtraDataPtrEnabled == 0:            sListString = sListString + hex(icsSpyMessageArray[lCount - 1].Data8) + " "        if icsSpyMessageArray[lCount - 1].Protocol == ePROTOCOL.SPY_PROTOCOL_LIN:            sListString = sListString + "CS=" + hex(stJMsg.ACK1)        if filter != None:            if icsSpyMessageArray[lCount - 1].ArbIDOrHeader == filter.arbID:  #set filter data                data = icsSpyMessageArray[lCount - 1]                # if filter.data1 == data.Data1 and filter.data2 == data.Data2 and filter.data3 == data.Data3:                print('receive:', sListString)        else:            print('receive:', sListString)    time.sleep(0.2)def GetStringForNetworkID(networkID):    if eNETWORK_ID.NETID_DEVICE.value == networkID:        return  eNETWORK_ID.NETID_DEVICE.name    elif eNETWORK_ID.NETID_HSCAN.value == networkID:        return  eNETWORK_ID.NETID_HSCAN.name    elif eNETWORK_ID.NETID_MSCAN.value == networkID:        return  eNETWORK_ID.NETID_MSCAN.name    elif eNETWORK_ID.NETID_SWCAN.value == networkID:        return  eNETWORK_ID.NETID_SWCAN.name    elif eNETWORK_ID.NETID_LSFTCAN.value == networkID:        return  eNETWORK_ID.NETID_LSFTCAN.name    elif eNETWORK_ID.NETID_ISO.value == networkID:        return  eNETWORK_ID.NETID_ISO.name    elif eNETWORK_ID.NETID_ISO2.value == networkID:        return  eNETWORK_ID.NETID_ISO2.name    elif eNETWORK_ID.NETID_ISO14230.value == networkID:        return  eNETWORK_ID.NETID_ISO14230.name    elif eNETWORK_ID.NETID_LIN.value == networkID:        return  eNETWORK_ID.NETID_LIN.name    elif eNETWORK_ID.NETID_ISO3.value == networkID:        return  eNETWORK_ID.NETID_ISO3.name    elif eNETWORK_ID.NETID_HSCAN2.value == networkID:        return  eNETWORK_ID.NETID_HSCAN2.name    elif eNETWORK_ID.NETID_HSCAN3.value == networkID:        return  eNETWORK_ID.NETID_HSCAN3.name    elif eNETWORK_ID.NETID_ISO4.value == networkID:        return  eNETWORK_ID.NETID_ISO4.name    elif eNETWORK_ID.NETID_LIN2.value == networkID:        return  eNETWORK_ID.NETID_LIN2.name    elif eNETWORK_ID.NETID_LIN3.value == networkID:        return  eNETWORK_ID.NETID_LIN3.name    elif eNETWORK_ID.NETID_LIN4.value == networkID:        return  eNETWORK_ID.NETID_LIN4.name    elif eNETWORK_ID.NETID_LIN5.value == networkID:        return  eNETWORK_ID.NETID_LIN5.name    elif eNETWORK_ID.NETID_MOST.value == networkID:        return  eNETWORK_ID.NETID_MOST.name    elif eNETWORK_ID.NETID_CGI.value == networkID:        return  eNETWORK_ID.NETID_CGI.name    elif eNETWORK_ID.NETID_HSCAN4.value == networkID:        return  eNETWORK_ID.NETID_HSCAN4.name    elif eNETWORK_ID.NETID_HSCAN5.value == networkID:        return  eNETWORK_ID.NETID_HSCAN5.name    elif eNETWORK_ID.NETID_UART.value == networkID:        return  eNETWORK_ID.NETID_UART.name    elif eNETWORK_ID.NETID_UART2.value == networkID:        return  eNETWORK_ID.NETID_UART2.name    elif eNETWORK_ID.NETID_UART3.value == networkID:        return  eNETWORK_ID.NETID_UART3.name    elif eNETWORK_ID.NETID_UART4.value == networkID:        return  eNETWORK_ID.NETID_UART4.name    elif eNETWORK_ID.NETID_SWCAN2.value == networkID:        return  eNETWORK_ID.NETID_SWCAN2.name    elif eNETWORK_ID.NETID_ETHERNET_DAQ.value == networkID:        return  eNETWORK_ID.NETID_ETHERNET_DAQ.name    elif eNETWORK_ID.NETID_FLEXRAY1A.value == networkID:        return  eNETWORK_ID.NETID_FLEXRAY1A.name    elif eNETWORK_ID.NETID_FLEXRAY1B.value == networkID:        return  eNETWORK_ID.NETID_FLEXRAY1B.name    elif eNETWORK_ID.NETID_FLEXRAY2A.value == networkID:        return  eNETWORK_ID.NETID_FLEXRAY2A.name    elif eNETWORK_ID.NETID_FLEXRAY2B.value == networkID:        return  eNETWORK_ID.NETID_FLEXRAY2B.name    elif eNETWORK_ID.NETID_FLEXRAY.value == networkID:        return  eNETWORK_ID.NETID_FLEXRAY.name    elif eNETWORK_ID.NETID_MOST25.value == networkID:        return  eNETWORK_ID.NETID_MOST25.name    elif eNETWORK_ID.NETID_MOST50.value == networkID:        return  eNETWORK_ID.NETID_MOST50.name    elif eNETWORK_ID.NETID_MOST150.value == networkID:        return  eNETWORK_ID.NETID_MOST150.name    elif eNETWORK_ID.NETID_ETHERNET.value == networkID:        return  eNETWORK_ID.NETID_ETHERNET.name    elif eNETWORK_ID.NETID_HSCAN6.value == networkID:        return  eNETWORK_ID.NETID_HSCAN6.name    elif eNETWORK_ID.NETID_HSCAN7.value == networkID:        return  eNETWORK_ID.NETID_HSCAN7.name    elif eNETWORK_ID.NETID_LIN6.value == networkID:        return  eNETWORK_ID.NETID_LIN6.name    elif eNETWORK_ID.NETID_LSFTCAN2.value == networkID:        return  eNETWORK_ID.NETID_LSFTCAN2.name    elif eNETWORK_ID.NETID_OP_ETHERNET1.value == networkID:        return  eNETWORK_ID.NETID_OP_ETHERNET1.name    elif eNETWORK_ID.NETID_OP_ETHERNET2.value == networkID:        return  eNETWORK_ID.NETID_OP_ETHERNET2.name    elif eNETWORK_ID.NETID_OP_ETHERNET3.value == networkID:        return  eNETWORK_ID.NETID_OP_ETHERNET3.name    elif eNETWORK_ID.NETID_OP_ETHERNET4.value == networkID:        return  eNETWORK_ID.NETID_OP_ETHERNET4.name    elif eNETWORK_ID.NETID_OP_ETHERNET5.value == networkID:        return  eNETWORK_ID.NETID_OP_ETHERNET5.name    elif eNETWORK_ID.NETID_OP_ETHERNET6.value == networkID:        return  eNETWORK_ID.NETID_OP_ETHERNET6.name    elif eNETWORK_ID.NETID_OP_ETHERNET7.value == networkID:        return  eNETWORK_ID.NETID_OP_ETHERNET7.name    elif eNETWORK_ID.NETID_OP_ETHERNET8.value == networkID:        return  eNETWORK_ID.NETID_OP_ETHERNET8.name    elif eNETWORK_ID.NETID_OP_ETHERNE9.value == networkID:        return  eNETWORK_ID.NETID_OP_ETHERNET9.name    elif eNETWORK_ID.NETID_OP_ETHERNET10.value == networkID:        return  eNETWORK_ID.NETID_OP_ETHERNET10.name    elif eNETWORK_ID.NETID_OP_ETHERNET11.value == networkID:        return  eNETWORK_ID.NETID_OP_ETHERNET11.name    elif eNETWORK_ID.NETID_OP_ETHERNET12.value == networkID:        return  eNETWORK_ID.NETID_OP_ETHERNET12.name    else:        return "Other"def CloseDevice():    pNumberOfErrors = 0    if m_bPortOpen == False:        return    if m_hObject == 0:        return    iResult = icsNeo.icsneoClosePort(m_hObject, pNumberOfErrors)    pNumberOfErrors = iResult[1]    print("close Device Status:", iResult[0])def getNotBuidInArray(object, size):    objects = []    for i in range(0, size):        objects.append(object)    return objects
ES581Demo.py:import  ES581 as es581es581.OpenDevice()lNetworkID = es581.eNETWORK_ID.NETID_HSCAN.valueIsExtendedID = False_CANdata = bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00')# es581.SendCANMessage(lNetworkID, IsExtendedID, _CANdata)networkID = es581.eNETWORK_ID.NETID_HSCAN.valuearbID = '7e0'flowControlArbID = '7e8'numberOfDataSize = 2IsCheckPadding = FalseIsCheckExtenedID = FalseIsCheckFCExtenedID = FalseIsUseCANFD = False_ISO15765data = bytearray(b'\x3b\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA\xBB\xCC\xDD\xEE\xFF')es581.SendISO15765Message(networkID,arbID ,flowControlArbID , numberOfDataSize, IsCheckPadding, IsCheckExtenedID, IsCheckFCExtenedID, IsUseCANFD, _ISO15765data)arbID = '7df'es581.SendISO15765Message(networkID,arbID ,flowControlArbID , numberOfDataSize, IsCheckPadding, IsCheckExtenedID, IsCheckFCExtenedID, IsUseCANFD, _ISO15765data)filter = es581.filter()filter.arbID = 0x7e8filter.data1 = 0x7ffilter.data2 = 0x3bfilter.data3 = 0x11es581.GetMessage(filter)es581.CloseDevice()

可根據自己需求進一步擴充套件與調整,執行部分截圖:

9
  • BSA-TRITC(10mg/ml) TRITC-BSA 牛血清白蛋白改性標記羅丹明
  • 現在學習程式設計的,恐怕沒幾個人看過程式設計書了吧?