I have python code running on a linux based device which has the following OS specifications:
NAME=Buildroot
VERSION=2020.11.1
This device is connected to a PLC using a three wire interface (CAN_H,CAN_L,GND).
I have written a code that sends a message to the PLC using the CAN-bus protocol. This is being done with the python-can
package.
I have the following code:
import can
def send():
#USB interface
#bus = can.interface.Bus(bustype='pcan', channel='PCAN_USBBUS1', bitrate=500000)
#on linux
bus = can.interface.Bus(bustype='socketcan', channel='vcan0', bitrate=500000)
#on windows
#bus = can.interface.Bus(bustype='serial', channel='COM1', bitrate=500000)
msg = can.Message(arbitration_id=0x68005,data=[0x10,0x11,0x12],is_extended_id=True)
try:
bus.send(msg)
print("Message sent on {}".format(bus.channel_info))
except can.CanError:
print("Message NOT sent")
if __name__ == '__main__':
send()
The problem faced is that the device is not sending any data to the PLC. This is probably due to incorrect options set for bustype
and channel
.
Can anyone advise on what to provide for bustype
and channel
for this physical interface with three CAN wires?