PCANBasic Receiving Data

USB to CAN Interface
Locked
MansillSmithLICA
Posts: 2
Joined: Thu 19. Nov 2020, 04:11

PCANBasic Receiving Data

Post by MansillSmithLICA » Thu 19. Nov 2020, 04:19

Hello,
I am able to write messages using the PCAN-USB, however it doesn't seem to be able to read messages.
I am attempting to do the following:

Code: Select all

 while (true)
            {
                TPCANStatus result = TPCANStatus.PCAN_ERROR_OK;
                do
                {
                    TPCANMsg msg;
                    TPCANTimestamp time;

                    Console.WriteLine(result.ToString());

                    result = PCANBasic.Read(PCANBasic.PCAN_USBBUS1, out msg, out time);
                    if (result != TPCANStatus.PCAN_ERROR_QRCVEMPTY)
                    {
                        ProcessMessage(msg, time);
                    }
                } while ((result & TPCANStatus.PCAN_ERROR_QRCVEMPTY) != TPCANStatus.PCAN_ERROR_QRCVEMPTY);
            }
However, when I was stepping through the code and it got to the PCANBasic.Read line, the program would always exit with code 0, even though the code was in an infinite loop (the while true).
If I had done something wrong, I would've assumed that the error would repeatedly occur, due to the loop, but this is not the case.
Does anyone know what I'm doing wrong?
Thank You.

MansillSmithLICA
Posts: 2
Joined: Thu 19. Nov 2020, 04:11

Re: PCANBasic Receiving Data

Post by MansillSmithLICA » Thu 19. Nov 2020, 04:34

Solved, was to do with how the thread was setup

User avatar
PEAK-Support
Sales & Support
Sales & Support
Posts: 1646
Joined: Fri 10. Sep 2010, 19:34

Re: PCANBasic Receiving Data

Post by PEAK-Support » Thu 19. Nov 2020, 10:14

Thank´s for the feedback!
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

Locked