Detect when a specific CAN-ID has been received in an interface

CAN Software API for Windows®. REGARD! This API is out-dated. Please use PCAN-Basic for new software developments.
Post Reply
YourAverageDevelope
Posts: 3
Joined: Fri 11. Jun 2021, 21:33

Detect when a specific CAN-ID has been received in an interface

Post by YourAverageDevelope » Sat 12. Jun 2021, 00:46

Hello, im working in a (legacy) interface application in C# that communicates to an actuator software via PCAN.
This interface implemented the PCAN-Light library.

What im currently trying to do is to, based on a text file, perform the following actions:

1. Send specific commands
2. Wait for the specific CAN-ID before proceding to the next instruction

Heres how these text files look like:

Image

So far i have no problem sending the extracted commands, but im having a hard time figuring out how i am supposed
to detect when a specific CAN-ID has been received, heres how my method that executes these send commands from the text file looks like:

Image

When using Trace on PCAN-View, i can see that after sending the message command, the actuator is replying back with the
CAN-ID that is specified on the text file, the problem that i have is how i am supposed to read and detect these CAN-ID's in my interface.

I know that PCAN-Light is outdated but i think that what im asking for is possible to do, i will greatly appreciate any feedback.

Thank you in advance.

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

Re: Detect when a specific CAN-ID has been received in an interface

Post by M.Maidhof » Mon 14. Jun 2021, 12:49

Hi,

the commands you have listed is a PCAN-Explorer standard macro. Best solution will be to use PCAN-Explorer for such a task, isn't it?

If you want to do the same application with an own application, you need a timer or use an event to read the CAN frames, and synchronize this with your "macro".

And yes, PCAN-Light is outdated since more than 10 years, for a new application it will be better to switch to the PCANBasic API, which is avaialble for free on our website.

regards

Michael

YourAverageDevelope
Posts: 3
Joined: Fri 11. Jun 2021, 21:33

Re: Detect when a specific CAN-ID has been received in an interface

Post by YourAverageDevelope » Mon 14. Jun 2021, 20:10

Thank you for your reply.

I do want to implement this in my own application, i do know how to read the received CAN frames,
but what i dont know is how to read the CAN-ID from those received CAN frames in my application,

Any guidance on where to look in the documentation to be able to perform this would be appreciated, thank you.

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

Re: Detect when a specific CAN-ID has been received in an interface

Post by M.Maidhof » Tue 15. Jun 2021, 09:09

Hi,

please have a look in the PCAN-Light or PCANBasic help files or headerfiles. With the Read() function you will receice a message structure in which you have a CAN ID member.

Here an example of the old PCAN-Light (pcan_usb.dll) API:

Code: Select all

// CAN Message
//
typedef struct {
    DWORD ID;        // 11/29 bit identifier
    BYTE  MSGTYPE;   // Bits from MSGTYPE_*
    BYTE  LEN;       // Data Length Code of the Msg (0..8)
    BYTE  DATA[8];   // Data 0 .. 7
} TPCANMsg;
Please have a look in the examples which we deliver with the API packages.

regards

Michael

YourAverageDevelope
Posts: 3
Joined: Fri 11. Jun 2021, 21:33

Re: Detect when a specific CAN-ID has been received in an interface

Post by YourAverageDevelope » Fri 18. Jun 2021, 07:56

Thank you i finally accomplished what i wanted, i was not aware that the message structure contained the MSG ID, silly me.

Best regards.

Post Reply