I have code that communicates with a motor over CAN, originally written to work on a Linux machine. I want to run it on Windows, and I believe the socket-can libraries are not supported for Windows, and so I am trying to use python-can instead.
The original two lines are:
can_msg = struct.pack(self.motor_params["CAN_FRAME_FMT_SEND"], self.motor_id, can_dlc, data)
CanMotorController.motor_socket.send(can_msg)
Where self.motor_params["CAN_FRAME_FMT_SEND"]="=IB3x8s"
, self.motor_id=0x01
, can_dlc=8
, and data=b"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFC"
.
I have tried to translate this to python-can using the following two lines instead:
can_msg = can.Message(arbitration_id=self.motor_id, data=data, is_extended_id=False)
CanMotorController.bus.send(can_msg)
Printing can_msg in the first case results in: b'\x01\x00\x00\x00\x08\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xfc'
and in the second case: Timestamp: 0.000000 ID: 0000 S Rx DL: 8 ff ff ff ff ff ff ff fc
.
Although this successfully sends, and I can see the CAN Rx LED flash on the serial-can converter (implying something is sent), the motor doesn't appear to send anything back, as the recv function which later runs always returns None.
How should I write the can.Message() function to achieve the same result as with the original code?
Edit: Added CAN protocol for specific motor.
Screenshot of CAN Communication Protocol from AK10-9 V2 motor datasheet