Unable to process the Read msg

The free CAN Software API (Application Programming Interface) for Windows®
Post Reply
ankur17
Posts: 9
Joined: Wed 1. Dec 2021, 14:10

Unable to process the Read msg

Post by ankur17 » Tue 21. Dec 2021, 07:18

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!!
Last edited by M.Gerber on Tue 21. Dec 2021, 10:12, edited 1 time in total.
Reason: Inserted [code] tags for improved readability

M.Heidemann
Sales & Support
Sales & Support
Posts: 1083
Joined: Fri 20. Sep 2019, 13:31

Re: Unable to process the Read msg

Post by M.Heidemann » Tue 21. Dec 2021, 09:39

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
---
Marvin Heidemann
PEAK-Support Team

Post Reply