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.
Содержание USB-2CAN-M
Страница 1: ...Titan Electronics Inc Web www titan tw USB 2CAN M USB CAN SI M USER S MANUAL 2019 Edition ...
Страница 5: ...4 9 6 13 Using the API in Python 70 9 6 14 Using the API in LabVIEW 71 ...
Страница 36: ...35 Connected to XXX kbits s firmware version VXXXX and operation mode at the bottom of the main panel ...
Страница 43: ...42 ...
Страница 62: ...61 Sample Command CAN_Status 2508 Checks the status bits of device connected to channel with the handle 2508 ...
Страница 66: ...65 break Status CAN_Close Handle printf Test finish n return 0 ...