Reading problem using LINAPI
Posted: 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!
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!