The free CAN Software API (Application Programming Interface) for Windows®
- Posts: 1
- Joined: Wed 12. Jan 2022, 08:34
I'm making a python script which sends a CAN message through a PCAN-USB(IPEH-002021). The problem is when i want to send a float type data i receive the following error <unsupported operand type(s) for >>: 'float' and 'int'
This is my code:
Code: Select all
connect1 = PCANBasic()
# Initialize connection
res = connect1.Initialize(PCAN_USBBUS1,
msg = TPCANMsg()
msg.ID = 0xW8
msg.MSGTYPE = PCAN_MESSAGE_STANDARD
msg.LEN = 8
msg.DATA = (12.4>> 24) & 0xff
msg.DATA = (12.4 >> 16) & 0xff
msg.DATA = (12.4 >> 8) & 0xff
msg.DATA = (12.4) & 0xff
msg.DATA = (35.4 >> 24) & 0xff
msg.DATA = (35.4 >> 16) & 0xff
msg.DATA = (35.4 >> 8) & 0xff
msg.DATA = (35.4) & 0xff
result = connect1.Write(PCAN_USBBUS1,msg)
if result != PCAN_ERROR_OK:
# An error occurred, get a text describing the error and show it
result = connect1.GetErrorText(result,0x00)
print("VP_POSITION : Message sent successfully")
res = connect1.Uninitialize(PCAN_USBBUS1)
Is there anay way for it to accept float data and not just integer data ?
Thank you in advance.
- Sales & Support
- Posts: 1321
- Joined: Fri 10. Sep 2010, 19:34
A CAN 2.0a/b Message could handle up to 8 Data Bytes. What you put into this Data Bytes is up to you.
If you talking about a float value, you need to understand how your target(s) read/write a float value from the memory which store the Value.
Maybe you read this pages link
and try to understand how a float is stored in computer memory. In the same way you have to fill the CAN Data Bytes.
In C it is very easy, you define a VAR as float and you know that it will be stored in 4 Bytes (32 Bit). Then you could use this 4 Bytes to fill the first 4 CAN Databytes to send a float inside the CAN Frame in Byte 0..3. This could be easy done by using a union.
How you setup this in Python is a Python question, maybe you better post this question inside a Python Forum.
Technical Support Team