Page 1 of 1

Unable to process the Read msg

Posted: Tue 21. Dec 2021, 07:18
by ankur17
Hello Support
I'm developing the python script for PCAN USB, I'm facing problem with reading the CAN msg. The read object is returning with 3-tuple and stored in status, msg, time. The return status is 0 (PCAN_ERROR_OK). The other two return values as follows
<PCANBasic.TPCANMsg object at 0x00000269780E4940>
<PCANBasic.TPCANTimestamp object at 0x0000026978178840>

How can I represent my msg in the readable manner with the timestamp?

Below i found a solution on the internet they have used ProcessMessage and HandleReadError to which my script is returning with ProcessMessage not defined.

Code: Select all

if readResult[0] != PCAN_ERROR_QRCVEMPTY:
        # Process the received message
        #
        print ("A message was received")
        ProcessMessage(result[1],result[2])
    else:
        # An error occurred, get a text describing the error and show it
        #
        result = objPCAN.GetErrorText(readResult[0])
        print (result[1])
        HandleReadError(readResult[0])
PLS help!!

Re: Unable to process the Read msg

Posted: Tue 21. Dec 2021, 09:39
by M.Heidemann
Hello,

You might want to check out the latest PCANBasic API package,
we have added console examples for python:

https://www.peak-system.com/fileadmin/m ... -basic.zip

With the examples provided you should not need to look for
solutions online.

I would recommend to have a look at the example
Samples\Console\Python\03_ManualRead, see how processing the message including the timestamp is handled here.

Code: Select all

    def ProcessMessageCan(self,msg,itstimestamp):
         """
         Processes a received CAN message
         
         Parameters:
             msg = The received PCAN-Basic CAN message
             itstimestamp = Timestamp of the message as TPCANTimestamp structure
         """
         microsTimeStamp = itstimestamp.micros + 1000 * itstimestamp.millis + 0x100000000 * 1000 * itstimestamp.millis_overflow
         
         print("Type: " + self.GetTypeString(msg.MSGTYPE))
         print("ID: " + self.GetIdString(msg.ID, msg.MSGTYPE))
         print("Length: " + str(msg.LEN))
         print("Time: " + self.GetTimeString(microsTimeStamp))
         print("Data: " + self.GetDataString(msg.DATA,msg.MSGTYPE))
         print("----------------------------------------------------------")

Best Regards

marvin