Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

send several flames,and ncread for respond

i am new to in-can. i need to send 22 of data flames to ECU,and get the ECU respond. As attached are complete  VB6.0 code.
i use this method to send all 22 data flames., and use ncwaitforstate,ncread to read the ECU respond. But, i couldn`t get it directly,
i need to place about 30seconds delay after the ncwrite, so that i can get the desire respond. i knew that this is not the right way to get the
respond,as the respond are expected return immediatly. i would expect respond from ECU without such a long delay. Anyway one, please advice. Thanks
 
 
 For y = 0 To 21 Step 1
       
        data = List2.List(x)
        Data_1 = Mid(data, 1, 2)
        Data_2 = Mid(data, 3, 2)
        Data_3 = Mid(data, 5, 2)
        Data_4 = Mid(data, 7, 2)
        Data_5 = Mid(data, 9, 2)
        Data_6 = Mid(data, 11, 2)
        Data_7 = Mid(data, 13, 2)
        Data_8 = Mid(data, 15, 2)
       
        x = x + 1
        Transmit.data(0) = "&H" & Data_1
        Transmit.data(1) = "&H" & Data_2
        Transmit.data(2) = "&H" & Data_3
        Transmit.data(3) = "&H" & Data_4
        Transmit.data(4) = "&H" & Data_5
        Transmit.data(5) = "&H" & Data_6
        Transmit.data(6) = "&H" & Data_7
        Transmit.data(7) = "&H" & Data_8
  
        Status = ncWrite(TxHandle, Len(Transmit), Transmit)
        wait 30s
   

 Next y
  
   Status = ncWaitForState(RxHandle, (NC_ST_READ_AVAIL), 2000, State)
   If (CheckStatus(Status, "ncWaitForState") = True) Then GoTo Error
  
   
   Status = ncRead(RxHandle, Len(Receive), Receive)
   If (CheckStatus(Status, "ncRead") = True) Then GoTo Error
  
0 Kudos
Message 1 of 18
(7,267 Views)
The way to go is using the wait for state as you did in your code. Right now it has a timeout of 2000 ms configured. Try to remove the 30 seconds wait and adjust your timeout to 30000 ms. Now you should get the frame as well. Try to lower the timeout until you reach the minimum time  your ECU needs to respond.
 
DirkW
0 Kudos
Message 2 of 18
(7,261 Views)
Thanks for replying.
 
i could get the respond by adding more delay. But, one problem occur. i need to read for 3 times,in order to get the desire respond.
As show in attached file. i try to read the respond for 6 times,after 22 flames was sent by using ncwrite. i couldn`t get the desire respond for the first time read, However, the desire respond can only get it after second times of read.  
 
As show are the respond i get after sending 22 flames
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
0x91741780FFFF88BE   --->previous respond for initialize download
0x91741780FFFF88BE  ---->previous respond for initialize download
0x9176FFFFFFFFFFF  ------>desire respond (showing the 22 flames has been written successfully)
 
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
After that,i need to send a flames to inform ECU that all the data has finished written. Then, the ECU will calculate the checksum of all data i sent , lastly, will send respond a flame to indicate that the checksum(88BE) has correctly match the flames that i sent during initialize download section.
 
i am wondering whether i am using the correct method to send severals flames, but it works for sending one flame ,and then get a respond immediately.  Please advice.
0 Kudos
Message 3 of 18
(7,255 Views)
Thanks for replying.
 
i could get the respond by adding more delay. But, one problem occur. i need to read for 3 times,in order to get the desire respond.
As show in attached file. i try to read the respond for 6 times,after 22 flames was sent by using ncwrite. i couldn`t get the desire respond for the first time read, However, the desire respond can only get it after second times of read.  
 
As show are the respond i get after sending 22 flames
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
0x91741780FFFF88BE   --->previous respond for initialize download
0x91741780FFFF88BE  ---->previous respond for initialize download
0x9176FFFFFFFFFFF  ------>desire respond (showing the 22 flames has been written successfully)
 
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
After that,i need to send a flames to inform ECU that all the data has finished written. Then, the ECU will calculate the checksum of all data i sent , lastly, will send respond a flame to indicate that the checksum(88BE) has Not correctly match the flames that i sent during initialize download section.
 
The return checksum from ECU is zero. i am thinking why would the ECU has calculated zero checksum, Is it possible that the 22flames of data was not correctly send ??
 
i am wondering whether i am using the correct method to send severals flames, but it works for sending one flame ,and then get a respond immediately.  Please advice.
0 Kudos
Message 4 of 18
(7,250 Views)
Yeoh,

I was looking at your code and could not figure out where all of your 22 frames were being written. Then the responses that you are getting in return, are the first two responses possiblly just partial returns. What are you expecting, and why are you expecting that from your ECU.

How you send your frames depends on how your ECU is configured. It is possible that you are writting too much data to your ECU before it is ready to recive more data.

The more information you can send me on what you are expecting the better.

Cheers,
-Marshall R
0 Kudos
Message 5 of 18
(7,233 Views)
Marshall R,
 
Thanks for replying. Well, i am trying to flash an ECU.
The step to being flashing are as follows:
 
1) initialize download
  
0 Kudos
Message 6 of 18
(7,229 Views)
Marshall R,
 
Thanks for replying. Well, i am trying to flash an ECU.
The step to being flashing are as follows:
 
1) initialize download
   
0 Kudos
Message 7 of 18
(7,229 Views)
Marshall R,
 
Thanks for replying. Well, i am trying to flash an ECU.
The step to being flashing are as follows:
 
1) initialize download
    In
0 Kudos
Message 8 of 18
(7,228 Views)
Marshall R,
 
Thanks for replying. Well, i am trying to flash an ECU.
The step to being flashing are as follows:
 
1) initialize download
    In this
0 Kudos
Message 9 of 18
(7,228 Views)
Marshall R,
 
Thanks for replying. Well, i am trying to flash an ECU.
The step to being flashing are as follows:
 
1) initialize download
    In this step,i
0 Kudos
Message 10 of 18
(7,227 Views)