Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

I'm trying to apply consecutive frames (KWP2000) with the NI CAN in VB

I'm trying to communicate with a device with consecutive can frames, but I can't.
The idea is to send the following frames

TX 0x720 10 08 2F 63 08 07 80 00
RX 0x728 30 00 00 00 00 00 00 00 (I have to wait until is receive this frame then I send the following message)
TX 0x720 21 FF FF 00 00 00 00 00
RX 0x728 10 08 6F 63 08 07 80 00 (I have to wait until is receive this frame then I send the following message)
TX 0x720 30 00 00 00 00 00 00 00
RX 0x728 21 FF FF 00 00 00 00 00
I'm usign the frame API in visual basic
I'm using two objects one for the TX and one for RX. The transmit object has as communication type transmit by call, and the RX object has the receive unsolicited type.
I send the first frame with TX object and I wait until I read by the RX object the desire value, until then I send the next frame. But my device seem to doesn't understand the frames, I don't know if it exist a better way to this if so, can you help me with that?

Catalina
0 Kudos
Message 1 of 5
(5,303 Views)
Could you post a SPY capture of this behavior?

Logan S.
0 Kudos
Message 2 of 5
(5,297 Views)
1. ncConfig ("CAN0", 8, {0x80000007,0x80000006,...}, {0x0007A120,0x00000001,...})
Process ID: 0x00000DDC Thread ID: 0x00000B7C
Start Time: 12:10:03.718 Call Duration: 00:00:00.071
Status: 0 (VI_SUCCESS)
2. ncOpenObject ("CAN0", 53412120)
Process ID: 0x00000DDC Thread ID: 0x00000B7C
Start Time: 12:10:03.799 Call Duration: 00:00:00.030
Status: 0 (VI_SUCCESS)
3. ncConfig ("CAN0::STD0x720", 7, {0x80000016,0x8000000F,...}, {0x00000001,0x000007D0,...})
Process ID: 0x00000DDC Thread ID: 0x00000B7C
Start Time: 12:10:10.378 Call Duration: 00:00:00.010
Status: 0 (VI_SUCCESS)
4. ncOpenObject ("CAN0::STD0x720", 53412456)
Process ID: 0x00000DDC Thread ID: 0x00000B7C
Start Time: 12:10:10.388 Call Duration: 00:00:00.000
Status: 0 (VI_SUCCESS)
5. ncConfig ("CAN0::STD0x728", 7, {0x80000016,0x8000000F,...}, {0x00000000,0x000007D0,...})
Process ID: 0x00000DDC Thread ID: 0x00000B7C
Start Time: 12:10:17.358 Call Duration: 00:00:00.010
Status: 0 (VI_SUCCESS)
6. ncOpenObject ("CAN0::STD0x728", 53412784)
Process ID: 0x00000DDC Thread ID: 0x00000B7C
Start Time: 12:10:17.368 Call Duration: 00:00:00.000
Status: 0 (VI_SUCCESS)
7. ncWrite (53412456, 8, "../c....")
Process ID: 0x00000DDC Thread ID: 0x00000B7C
Start Time: 12:10:46.100 Call Duration: 00:00:00.000
Status: 0 (VI_SUCCESS)
> 8. ncWaitForState (53412784, 1, 2000, 18)
> Process ID: 0x00000DDC Thread ID: 0x00000B7C
> Start Time: 12:10:46.100 Call Duration: 00:00:00.000
> Status: 0xBFF62021
9. ncWrite (53412456, 8, "../c....")
Process ID: 0x00000DDC Thread ID: 0x00000B7C
Start Time: 12:10:46.100 Call Duration: 00:00:00.000
Status: 0 (VI_SUCCESS)

10. ncWaitForState (53412784, 1, 2000, 3)
Process ID: 0x00000DDC Thread ID: 0x00000B7C
Start Time: 12:10:46.110 Call Duration: 00:00:00.000
Status: 0 (VI_SUCCESS)
11. ncRead (53412784, 16, "IN..La..0.......")
Process ID: 0x00000DDC Thread ID: 0x00000B7C
Start Time: 12:10:46.110 Call Duration: 00:00:00.000
Status: 0 (VI_SUCCESS)
12. ncWrite (53412456, 8, "!.......")
Process ID: 0x00000DDC Thread ID: 0x00000B7C
Start Time: 12:10:46.110 Call Duration: 00:00:00.000
Status: 0 (VI_SUCCESS)
13. ncWaitForState (53412784, 1, 1000, 3)
Process ID: 0x00000DDC Thread ID: 0x00000B7C
Start Time: 12:10:46.110 Call Duration: 00:00:00.100
Status: 0 (VI_SUCCESS)
14. ncRead (53412784, 16, ".b..La..../r....")
Process ID: 0x00000DDC Thread ID: 0x00000B7C
Start Time: 12:10:46.210 Call Duration: 00:00:00.000
Status: 0 (VI_SUCCESS)
15. ncWrite (53412456, 8, "!.......")
Process ID: 0x00000DDC Thread ID: 0x00000B7C
Start Time: 12:10:46.210 Call Duration: 00:00:00.000
Status: 0 (VI_SUCCESS)
> 16. ncWaitForState (53412784, 1, 1000, 0)
> Process ID: 0x00000DDC Thread ID: 0x00000B7C
> Start Time: 12:10:46.210 Call Duration: 00:00:01.002
> Status: 0xBFF62001
etc......

My visual basic code is
i=0
Do
Status = ncWrite(HandleNameTX, Len(Transmit1), Transmit1)
Status1 = ncWaitForState(HandleNameRX, (NC_ST_READ_AVAIL), 2000, State)
If Status1 = 0 Then
Status2 = ncRead(HandleNameRX, Len(Receive1), Receive1)
If Receive1.Data(0) = 48 Then
j = 0
Do
Status = ncWrite(HandleNameTX, Len(Transmit2), Transmit2)
Status3 = ncWaitForState(HandleNameRX, (NC_ST_READ_AVAIL), 1000, State)
If Status3 = 0 Then
Status = ncRead(HandleNameRX, Len(Receive2), Receive2)
End If
j = j + 1
Loop Until (Receive2.Data(0) = 16 Or j > 10) = True
'Status = ncWrite(HandleNameTX, Len(Transmit1), Transmit1)
End If
End If
i = i + 1
Loop Until (i > 10) = True
0 Kudos
Message 3 of 5
(5,292 Views)
Sorry, I meant to ask for a spy capture file - they are much easier to read then text pasted in. So, I don't know if this is the real issue, but it looks like you are both reading and writing on a single CAN port, is that correct? Are you using the Channel API or the Frames API?

Logan S.
0 Kudos
Message 4 of 5
(5,282 Views)
Hello,

Here is a piece of code (labwindows/cvi ) i'm currently working on.
It's based on kwp2000 specifications for communication via kwp on CAN with an ECU.
ID 695 is the receiving ID and ID 6B5 is the transmiting ID.
message are ascii based , and the firt byte is the length of the message.

ex:

int clearDTC(void)
{
unsigned char buffer[128];

// start diag session
KWP2000Request("0210920000000000", buffer,1);

// clear all dtc
KWP2000Request("0314ff0000000000", buffer,1);

if ( buffer[0] == 0x54 && buffer[1]==0xff )
return 1;
else
return 0;



}

hope this willl help you.

best regards.
B.W.
0 Kudos
Message 5 of 5
(5,197 Views)