Page 1 of 1
Reading responses from message writes
Posted: Fri 22. May 2015, 10:02
by richClubb
Hello.
I'm using the PCAN-ISO TP in a project and am having problems interpreting a successful message response from the device.
The problem I have is after a transmission I do not know when the device has finished responding, is there an event handler or variable I can use to monitor a successful response? The PCAN-Basic API has the ability to trigger an event when a CAN message is received but the TP deals with all of that itself.
Currently I'm performing a read() until it responds with PCANTP_ERROR_NO_MESSAGE but when I perform a read() and it returns this value it will clear anything in the message object that has been passed to the function.
Thanks
Re: Reading responses from message writes
Posted: Fri 22. May 2015, 10:57
by K.Wagner
Hello,
richClubb wrote:Currently I'm performing a read() until it responds with PCANTP_ERROR_NO_MESSAGE but when I perform a read() and it returns this value it will clear anything in the message object that has been passed to the function.
The parameter "Message
Buffer" is a placeholder for a message, that is only valid after a sucessfull call to CANTP_Read, i.e. a positive RESULT and Message-Type. The buffers will be checked/reset entering the function to avoid returning uninitialized data. So don't use data as buffer that you still need or don't have saved/handled. Instead, you should use a local variable in each call and process the data of those messages received successfully
Code: Select all
int ReadMessage(TPCANTPHandle Channel)
{
TPCANTPMsg Message;
TPCANTPStatus Status;
TPCANTPTimestamp timestamp;
int nbErr = 0;
while((Status = CANTP_Read(Channel,&Message, ×tamp)) == PCANTP_ERROR_NO_MESSAGE)
Sleep(10);
if (Status == PCANTP_ERROR_OK) {
switch(Message.MSGTYPE)
{
case PCANTP_MESSAGE_REQUEST_CONFIRMATION:
printf("Received confirmation from 0x%02x (to 0x%02x, with RA 0x%02x) - result: %i - %s\n",
(int)Message.SA,
(int)Message.TA,
(int)Message.RA,
(int)Message.RESULT,
Message.RESULT != PCANTP_N_OK ? "ERROR !!!" : "OK !");
break;
case PCANTP_MESSAGE_INDICATION:
printf(" ... message pending from 0x%02x (to 0x%02x, with RA 0x%02x) LEN=%i - result: %i...\n",
(int)Message.SA,
(int)Message.TA,
(int)Message.RA,
(int)Message.LEN,
(int)Message.RESULT);
nbErr = ReadMessage(Channel);
break;
case PCANTP_MESSAGE_DIAGNOSTIC:
case PCANTP_MESSAGE_REMOTE_DIAGNOSTIC:
default:
printf("Received message from 0x%02x (to 0x%02x, with RA 0x%02x) - result: %i - %s, Length: %i\n",
(int)Message.SA,
(int)Message.TA,
(int)Message.RA,
(int)Message.RESULT,
Message.RESULT != PCANTP_N_OK ? "ERROR !!!" : "OK !",
(int)Message.LEN);
break;
}
if (Message.RESULT != PCANTP_N_OK)
nbErr++;
}
else {
nbErr++;
printf("Got error on reading message %i\n",(int)Status);
}
return nbErr;
}
richClubb wrote:is there an event handler or variable I can use to monitor a successful response
at the moment there is no other way to check for transmission completition as checking the result value of the CANTP_Read function
and the type of the message received (
TPCANTPMessageType). An event triggered read is not implemented.
Remarks: The message type (see TPCANTPMessageType) of a CAN ISO‐TP message indicates if the message is a
complete ISO‐TP message (diagnostic, remote diagnostic), a transmission confirmation or an indication of a
pending message. This value should be checked every time a message has been read successfully, along with
the RESULT value as it contains the network status of the message.
Re: Reading responses from message writes
Posted: Tue 26. May 2015, 11:13
by richClubb
Hello.
Thank you, I have managed to get a decent system working. Once I've got it working a bit better I'll post the C# code here.
Thanks for your time and help

Re: Reading responses from message writes
Posted: Thu 19. Nov 2015, 16:57
by spled
Hello,
I have been running a transmit function based on the supplied sample code, but the first (and here, it's the only) read always receives a copy of the original transmitted message, but with the message type PCANTP_MESSAGE_REQUEST_CONFIRMATION.
I understand this is some type of confirmation of transmission (and not reception), but how do I turn this off, so the read I make after a transmission is really the reply from the other CAN node? I might have thought it should be with PCANTP_MSG_PENDING_HIDE.
As a workaround, I am currently calling the read twice after the transmit.
Thanks in advance.
Ed.
Re: Reading responses from message writes
Posted: Thu 19. Nov 2015, 17:48
by F.Vergnaud
Hello Ed,
Well you cannot turn off the message's confirmation as it is part of the ISO-TP specification.
When you send an ISO-TP message, here is what happens (on the sender's side):
1. First the message is queued in the API, the transmission starts if there is no conflict with other transmissions in progress.
2. If the message does not fit in a single CAN frame, you will receive a message with the type PCANTP_MESSAGE_INDICATION. It states that the message is being transmitted, the duration depends on the CAN bitrate and the size of the ISO-TP message. You can hide those messages with the parameter PCANTP_MSG_PENDING_HIDE.
3. When the last segmented CAN frame is sent, you will receive a message with the type PCANTP_MESSAGE_REQUEST_CONFIRMATION. It states that the transmission has ended, but it is not guarenteed that it is a success: you MUST check the RESULT parameter for this.
If the message is successfully transmitted, you can expect a message response.
On the receiver side it is almost the same:
1. If the message does not fit in a single CAN frame, a message with the type PCANTP_MESSAGE_INDICATION is received.
2. When the last segmented CAN frame is received, a message with the type PCANTP_MESSAGE_DIAGNOSTIC or PCANTP_MESSAGE_REMOTE_DIAGNOSTIC is available. Once again this means that the reception is complete not successful, the RESULT parameter states if it is OK or not.
So for your application, when you call the CAN_Write function and expect a response, you need to:
1. read messages until you get a PCANTP_MESSAGE_REQUEST_CONFIRMATION message (corresponding to your request)
2. check the network status with the RESULT parameter,
3. if it is PCANTP_N_OK, you can start looking for another ISO-TP message. Otherwise you will not get a response.
Re: Reading responses from message writes
Posted: Sun 22. Nov 2015, 15:46
by spled
Thank you Fabrice. That makes sense.