EasyManua.ls Logo

Titan Electronics USB-2CAN-M - Page 71

Titan Electronics USB-2CAN-M
76 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
70
9.6.13 Using the API in Python
6. Ensure that the DLL file is placed in the same folder as your application executable.
7. Import the DLL using the ctypes library function LoadLibrary.
from ctypes import windll
DLL = windll.LoadLibrary("CANDLL_STDCALL.dll")
8. Create a definition of the CAN_MSG structure for the CAN_Write and CAN_Read
functions, if needed.
from ctypes import Structure, c_uint, c_ubyte, c_ushort
class CAN_MSG(Structure):
_fields_ = [("Id", c_uint),
("Size", c_ubyte),
("Data", c_ubyte * 8 ),
("Flags", c_ubyte),
("Timestamp", c_ushort)]
To use the CAN_MSG structure, you will need to create an instance of the structure
you just defined.
myCANMSG = CAN_MSG()
9. In order to communicate with the channel with other functions after opening it
with CAN_Open, you need to create a variable to store the handle value.
myHandle = DLL.CAN_Open(b"COM3", b"50", b"00000000", b"00000000",
1, 2)
10. This concludes the basic setup process of using the DLL in Python. Imported
functions can then be easily called form the DLL with the parameters created
above.

Table of Contents