Error codes in linux driver

This forum covers PCAN-Linux and Linux development issues concerning our products
Post Reply
fmauch
Posts: 2
Joined: Thu 19. May 2016, 09:09

Error codes in linux driver

Post by fmauch » Thu 19. May 2016, 09:11

Hello,

I have a question regarding the error handling in the peak-linux-driver with char devices:

The pcan-API defines certain error codes of length 2 bytes. However, the user manual states that:

"Depending on the kind of error detailed CAN_ERR_... information is
set in the DATA[3] field of the same structure."

Since DATA is an array of type BYTE this structure can however never reach the higher error codes. So if I would just be checking for the DATA[3] byte, I'd get a CAN_ERR_OK if there were a CAN_ERR_RESOURCE for example.

Is there a second byte assigned to the error codes or are those higher-level error codes not reachable in the linux driver?

M.Maidhof
Support
Support
Posts: 1753
Joined: Wed 22. Sep 2010, 14:00

Re: Error codes in linux driver

Post by M.Maidhof » Thu 19. May 2016, 12:37

Hi,

you can use the whole 4 bytes of a status message to build an error information:

Data[0] Data[1] Data[2] Data[3]

For the standard CAN errors, the last byte (Data[3]) will be enough (see Busheavy, BusOff etc).

Those >8 bit errors will not be part of a status message, but will be returned by the function you have called as return value.

regards

Michael

fmauch
Posts: 2
Joined: Thu 19. May 2016, 09:09

Re: Error codes in linux driver

Post by fmauch » Thu 19. May 2016, 13:20

Hi, thank you for the quick answer.

So I check the return value of LINUX_CAN_Read_Timeout() against the error codes? So is the error code returned in the CAN message redundant to that return value or will only those >8 bit errors be returned?

Cheers
Felix

M.Maidhof
Support
Support
Posts: 1753
Joined: Wed 22. Sep 2010, 14:00

Re: Error codes in linux driver

Post by M.Maidhof » Thu 19. May 2016, 14:13

Hi,

please don´t mix up status messages with return values of the API. A status messages will be received similar to a real CAN message with the CAN_Read() function, in which the databytes will contain some errorcodes, which are relevant for the CAN system (error messages related to the CAN-Controller error counter or bus status). This will be helpfull to have an exact timing when such an error occured.
All other errors, like "handle errors" etc, will only be returned by an API call, and will never be in a status message.

regards

Michael

Post Reply