Communication (Read Messages) discrepancy

The free CAN Software API (Application Programming Interface) for Windows®
Post Reply
abhishek1808
Posts: 18
Joined: Tue 6. Jan 2015, 09:03

Communication (Read Messages) discrepancy

Post by abhishek1808 » Tue 1. Nov 2016, 10:16

Hello

We are using a miniPCIe (2 Channels).
The Card is on Bus 6 (Firmware 1.3.0)
The Development package is PCAN Basic API and development platform is .Net (C#, 4.2)

Somehow, I am not able to read a particular ID. Below is my code

Code: Select all

 do
            {
                //TPCANMsg msg = new TPCANMsg();
                statusCAN = PCANBasic.Read(channel, out msg, out _timeStamp);
                if (statusCAN == TPCANStatus.PCAN_ERROR_OK)
                {
                    
                    if (msg.ID == 0x18FF0221)
                    {
                       
                        temp = (TwoBitStates)((msg.DATA[5] & 0x30) >> 4);// 0x30 = 0011 0000
                  
                    }
                    else if (msg.ID == 0x18FF0421)
                    {
                        temp = msg.DATA[5];
                    }
                    else if (msg.ID == 0x18FF0921)
                    {
                       temp = msg.DATA[5];
                       
                    }
                    else
                    { /* ignore other messages*/ }
                }
                else
                {
                     LogWriter.LogWrite("Component CAN Error in Reading: " + statusCAN.ToString() + _timeStamp.ToString());
                }
            } while (!Convert.ToBoolean(statusCAN & TPCANStatus.PCAN_ERROR_QRCVEMPTY));
On PCAN View I can see all the 3 messages, but somehow msg.ID = 0x18FF0921 is never read. I put a breakpoint there.
But it never Enters the Else if statement.
All message are on same bus. Is the Code not okay?

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

Re: Communication (Read Messages) discrepancy

Post by PEAK-Support » Tue 1. Nov 2016, 12:18

Looks OK - but i would do it this way...

Code: Select all

do
 {
   statusCAN = PCANBasic.Read(channel, out msg, out _timeStamp);
   if (statusCAN == TPCANStatus.PCAN_ERROR_OK)
   {
     switch (msg.ID)
     {
        case 0x18FF0221:                      
            temp = (TwoBitStates)((msg.DATA[5] & 0x30) >> 4);// 0x30 = 0011 0000
        break;

        case  0x18FF0421:
            temp = msg.DATA[5];
        break;

        case 0x18FF0921:
            temp = msg.DATA[5];                      
        break;	

        default:
           /* ignore other messages*/ 
        break;
     }
   }
   else
   {
     LogWriter.LogWrite("Component CAN Error in Reading: " + statusCAN.ToString() + timeStamp.ToString());
   }
 } while (!Convert.ToBoolean(statusCAN & TPCANStatus.PCAN_ERROR_QRCVEMPTY));
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

abhishek1808
Posts: 18
Joined: Tue 6. Jan 2015, 09:03

Re: Communication (Read Messages) discrepancy

Post by abhishek1808 » Tue 1. Nov 2016, 12:30

Dear U.Wilhelm

I started with SWITCH but when i saw the example code from PEAK, I started using IF, ELSE thinking that maybe (which is a big maybe) I need to use IF, Else.

The Curious case is that I have a Dual Channel CAN Card from PEAK. The Other CAN channel works perfectly. :?: :?: :?: :?:

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

Re: Communication (Read Messages) discrepancy

Post by PEAK-Support » Tue 1. Nov 2016, 12:50

Did you set any Filter? I do not see any reason why a card should not transmit exact this ID ...
Have you DEBUG the code, and set a Breakpoint in the switch when the case is called?
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

abhishek1808
Posts: 18
Joined: Tue 6. Jan 2015, 09:03

Re: Communication (Read Messages) discrepancy

Post by abhishek1808 » Tue 1. Nov 2016, 13:04

Hi
I have not set any filter!
I use breakpoints off course.
Will filter help? and why shall it?

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

Re: Communication (Read Messages) discrepancy

Post by PEAK-Support » Tue 1. Nov 2016, 13:16

Filter will not fix your results. Please start your Application and connect to the Channel that loos this ID.
Now start PCAN-View and select the in use CAN Channel (you will see a info "hardware in use" - ignore it )
Now the PCAN-View works side by side to your application. All your Application send will be shown in PCAN-View. And all IDs you send with PCAN-View will also been transmitted to your Applications queue. Now send the ID from PCAN-View and see if it will be received.
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

abhishek1808
Posts: 18
Joined: Tue 6. Jan 2015, 09:03

Re: Communication (Read Messages) discrepancy

Post by abhishek1808 » Tue 1. Nov 2016, 14:08

I can see the message on PCAN View!
I have attached a Screen shot and using SWITCH CASE! Still the same issue.
Screen Shot of PCAN, whree the Message can be seen.
Screen Shot of PCAN, whree the Message can be seen.
xdfdsfsdf.PNG (13.78 KiB) Viewed 10936 times
The actual code is attached here :
a.txt
Code
(3.53 KiB) Downloaded 621 times
I hope I have provided enough Information.

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

Re: Communication (Read Messages) discrepancy

Post by PEAK-Support » Tue 1. Nov 2016, 15:26

1. I do not see if you connected the PCAN-View to the SAME CAN Hardware. If yes send the Frame one time from the PCAN-View to see if this will be received by your application. Thats what i say in my last post.

You say that PCAN-View see it - so the CAN PC Hardware read it - looks like no Hardware problem.

2. Download our sample, start it and see if the ID will be shown in the receive window.
http://www.peak-system.com/produktcd/De ... xample.exe

3. Please also send me the Initialize code to my by e-mail (support@peak-system.com)
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

Post Reply