Reading problem using LINAPI

CAN FD and LIN Interface for High-Speed USB 2.0
Locked
ZymDap
Posts: 2
Joined: Mon 27. Jan 2020, 22:02

Reading problem using LINAPI

Post by ZymDap » Tue 28. Jan 2020, 08:01

Hello,

I am using LINAPI with Windows/CVI IDE (C language) and trying to communicate with a board via LIN interface. I successfuly managed to connect and initialize PCAN-Pro FD; sending LIN_Write() is working and controling the board, but using LIN_Read() I just get random nosense values. With PLIN-View Pro everything is OK. I use (suppose) the same settings.

The sequence I have implemented in my code is:
1. Initialization
1.1. LIN_GetAvailableHardware()
1.2. LIN_IdentifyHardware()
1.3. LIN_RegisterClient()
1.4. LIN_ConnectClient()
1.5. LIN_InitializeHardware()
1.6. LIN_GetStatus()

No errors, hardware found and configured successfuly here.

2. Setting params
2.1. LIN_SetClientParam(m_hClient, clpReceiveStatusFrames, 1); // Allow to Receive
2.2. LIN_RegisterFrameId(m_hClient, hwHandles[0], 0x00, 0x3F); // ID range from 0 to 63
2.3. LIN_SetClientFilter(m_hClient, hwHandles[0], 0xFFFFFFFFFFFFFFFF); // ID Mask. Allow from all

Seems to be good too?

3. Writing
3.1. Declaring TX structure
3.2. Setting FrameID, Length, Direction (Publisher), ChecksumType, Data.
3.3. LIN_Write()

Sending works properly.

4. Reading the response
// Declaring RX structure
TLINRcvMsg RX_BUFFER;
TLINRcvMsg *pRX_BUFFER;
pRX_BUFFER = &RX_BUFFER;

pRX_BUFFER->Type = 0; // 0 - Standard
pRX_BUFFER->FrameId = 0x24;
pRX_BUFFER->Length = 8;
pRX_BUFFER->Direction = 2; // 1 - Publisher, 2 - Subscriber
pRX_BUFFER->ChecksumType = 2; // 0 - Custom, 1 - Classic, 2 - Enchanced, 3 - Auto

LIN_GetPID(&(RX_BUFFER.FrameId)); // Calculate PID

err = LIN_Read(m_hClient, &RX_BUFFER);


Here sometimes I get random values of the response, sometimes somehow the message from TX_BUFFER, which was sent, is shown. Sometimes err = 3 which means the queue is empty nevertheless it shouldn't as the response is coming after the writing command.
Maybe I am missing some steps in Initialization/configuration or Reading procedures. Any help will be appreciated as I tried almost every function stated in the programming manual. Thanks in advance!

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

Re: Reading problem using LINAPI

Post by PEAK-Support » Tue 28. Jan 2020, 11:47

Please keep in mind that we do not support the Labview CVI - you need to check that functions that need parameters as reference, like read LIN Frames, have the correct data types.
The Labview CVI is not 100% compatible to real C/C++ compiler on Windows/Linux - which we support to 100% - so please conatct Labwindows support for help how to convert the data.
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

K.Wagner
Software Development
Software Development
Posts: 1080
Joined: Wed 22. Sep 2010, 13:36

Re: Reading problem using LINAPI

Post by K.Wagner » Tue 28. Jan 2020, 12:10

Hello,

The problem seems to be that you are not writing the header, since you are using the LIN_Read function only.
ZymDap wrote:
Tue 28. Jan 2020, 08:01
4. Reading the response
...

pRX_BUFFER->Type = 0; // 0 - Standard
pRX_BUFFER->FrameId = 0x24;
pRX_BUFFER->Length = 8;
pRX_BUFFER->Direction = 2; // 1 - Publisher, 2 - Subscriber
pRX_BUFFER->ChecksumType = 2; // 0 - Custom, 1 - Classic, 2 - Enchanced, 3 - Auto

LIN_GetPID(&(RX_BUFFER.FrameId)); // Calculate PID

err = LIN_Read(m_hClient, &RX_BUFFER);
Note that you first need to "write" the header, before a slave can fill it with data. So, what you need is to use LIN_Write to send the header, and then, call LIN_Read to get the data. Something like this (not tested since we do not support CVI ):

Code: Select all

TLINMsg TX_BUFFER
TLINMsg *pTX_BUFFER;
pTX_BUFFER = &TX_BUFFER;

pTX_BUFFER->FrameId = 0x24;
pTX_BUFFER->Length = 8;
pTX_BUFFER->Direction = 2; // 1 - Publisher, 2 - Subscriber
pTX_BUFFER->ChecksumType = 2; // 0 - Custom, 1 - Classic, 2 - Enchanced, 3 - Auto

LIN_GetPID(&(TX_BUFFER.FrameId)); // Calculate PID
LIN_CalculateChecksum(&TX_BUFFER); // Calculate Checksum

err = LIN_Write(m_hClient, m_hHw, &TX_BUFFER)

// Wait some time...

TLINRcvMsg RX_BUFFER;

err = LIN_Read(m_hClient, &RX_BUFFER)
Best regards,
Keneth

ZymDap
Posts: 2
Joined: Mon 27. Jan 2020, 22:02

Re: Reading problem using LINAPI

Post by ZymDap » Tue 28. Jan 2020, 12:37

Yes, that's the point. Now everything is working. Just thought that LIN_Read() function sends the request at first and then reads. Thanks for help.

K.Wagner
Software Development
Software Development
Posts: 1080
Joined: Wed 22. Sep 2010, 13:36

Re: Reading problem using LINAPI

Post by K.Wagner » Tue 28. Jan 2020, 12:38

you're welcome. Closed.
Best regards,
Keneth

Locked