Forum > General

Frame reception problem in Fiat CAN ID 11 bits, 50 kbaud with STN1100 chip

(1/1)

crisares:
Hello everyone...
I am having problems receiving response frames with an Obdlink SX interface (STN1100 chip)
It's my own code in Delphi and I'm using a serial component (Lazserial from Lazarus IDE) to send and receive frames with AT commands. Same as how ELM327 is used.

If I do monitoring with arduino and canbus shield, the frames of both query and response are seen perfectly.

I have the Obdlink configured with the "ATSPC" protocol, which is the one that corresponds to the protocol that I am using USER2 CAN ID 11 bits, 50 kbaud.

I send:
 

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  lazserial1.WriteData('85 02 10 81 00 00 00 00' + #13#10);  SLEEP(100);  listbox1.items.add(lazserial1.ReadData);  listbox1.Refresh;  lazserial1.WriteData('85 02 1A 95 00 00 00 00' + #13#10);  SLEEP(100);  listbox1.items.add(lazserial1.ReadData);  listbox1.Refresh;  lazserial1.WriteData('85 02 1A 94 00 00 00 00' + #13#10);  SLEEP(100);  listbox1.items.add(lazserial1.ReadData);  listbox1.Refresh;  lazserial1.WriteData('85 30 FF 00 00 00 00 00 ' + #13#10);  SLEEP(100);  listbox1.items.add(lazserial1.ReadData);  listbox1.Refresh;    
and I don't get any response via lazserial1.ReadData
in frontend console i only get "NO DATA>"
I already tried with different response times and several more configurations...

while at all times in the monitoring with arduino I get the complete frames:

1 - 7B0 85 02 10 81 00 00 00 00
2 - 7C3 F1 02 50 81 00 00 00 00
3 - 7B0 85 02 1A 95 00 00 00 00
4 - 7C3 F1 04 5A 95 01 08 00 00
5 - 7B0 85 02 1A 94 00 00 00 00
6 - 7C3 F1 10 0D 5A 94 30 34 30
7 - 7B0 85 30FF 00 00 00 00 00
8 - 7C3 F1 20 30 30 30 31 32 35
9 - 7C3 F1 21 31 31 00 00 00 00

It is as if the STN1100 or the serial component had some configuration that I am missing in order to receive the frames through the Lazserial serial component.

If there is someone who understands the subject and can give me a hand, I would appreciate it.

Thank you

avra:

--- Quote from: crisares on May 22, 2022, 10:26:04 pm ---I don't get any response via lazserial1.ReadData
--- End quote ---
I thought that LazSerial is event based, and that you should check for data in OnRxData? I do not use LazSerial so take this with a grain of salt. If you want direct synchronous control (nice for use in communication threads), then you should check out https://wiki.freepascal.org/Synapse.


--- Quote from: crisares on May 22, 2022, 10:26:04 pm ---If there is someone who understands the subject and can give me a hand, I would appreciate it.
--- End quote ---
I do understand the topic (implemented SocketCAN with freepascal) but you do not give much info. Anyway, you should check for 2 things. First is to use simple terminal and see if you get expected response when you send manual commands. Second is to check if you use both Arduino IDE monitoring and your Lazarus app at the same time on the same port. If that is the case, kill Arduino IDE and try again.

For serial port troubleshooting and monitoring, you could also try to use some serial port sniffer software to compare actual data flow between OBDwiz/OBDII and YourApp/OBDII.

crisares:

--- Quote ---I thought that LazSerial is event based, and that you should check for data in OnRxData?
--- End quote ---
Although I take the data from the RxData event the error and the problem remains the same.I understand that just one line in the event avoids many of the lines seen in the code I shared... but if I want to take the value of a response frame... I find it easier to handle the .ReadData this way...


--- Quote ---then you should check out https://wiki.freepascal.org/Synapse.
--- End quote ---
I'll give this a review...


--- Quote ---I do understand the topic (implemented SocketCAN with freepascal) but you do not give much info.
--- End quote ---
When I say someone who understands the subject, I mean the subject I am working on and with the tools I am working on... I am aware that there are many other ways of working on this... as there are also those who like to work with sockets and those without.
The truth is that what I am doing is not a complicated application and it does quite simple things, I already have the same thing working perfectly in other protocols. It is this protocol that is giving me work and makes me think that I may be missing some additional configuration and it is being overlooked.


--- Quote ---First is to use simple terminal and see if you get expected response when you send manual commands.
--- End quote ---
For that I use Stnterm and everything is perfect.


--- Quote ---Second is to check if you use both Arduino IDE monitoring and your Lazarus app at the same time on the same port. If that is the case, kill Arduino IDE and try again.
--- End quote ---
The monitoring of the communication with an external tool between my software that uses the obdlink and the fiat cluster is correct as shown above... I just can't get the response frame to read Lazserial.ReadData

I'm not an expert in communication protocols or lazarus... but little by little I managed to do some things successfully... but unfortunately this is preventing me from finishing this project and continue with the next one.

ccrause:

--- Quote from: crisares on May 22, 2022, 10:26:04 pm ---I have the Obdlink configured with the "ATSPC" protocol, which is the one that corresponds to the protocol that I am using USER2 CAN ID 11 bits, 50 kbaud.
8<-----
It is as if the STN1100 or the serial component had some configuration that I am missing in order to receive the frames through the Lazserial serial component.

--- End quote ---
Can you verify that Lazserial is working at 50 kbaud? This is not a standard baud, and afaics Lazserial only supports standard baud rates.

avra:

--- Quote from: crisares on May 23, 2022, 03:14:57 am ---
--- Quote ---I thought that LazSerial is event based, and that you should check for data in OnRxData?
--- End quote ---
Although I take the data from the RxData event the error and the problem remains the same.I understand that just one line in the event avoids many of the lines seen in the code I shared... but if I want to take the value of a response frame... I find it easier to handle the .ReadData this way...
--- End quote ---
If I understood you well and you're trying to use asynchrnous component as simple synchronous lib, then it might be the reason for the unexpected behaviour. That's why I suggested Synaser from Synapse lib, which is much more suitable for such use (very simple example can be found at https://wiki.freepascal.org/Arduino#Minimal_Lazarus_Synaser_serial_example).

It was a very long time since I used LazSerial, but after dropping component on the form and setting it's properties, you need to attach some procedure to it's OnRxData event (in design time via Object Inspector, or in runtime via code), wait in runtime until that event is fired (serial data detected) and THEN use ReadData. That is the correct event based asynchronous non blocking way for LazSerial. Otherwise think about using some synchonous blocking lib as already mentioned.


--- Quote from: crisares on May 23, 2022, 03:14:57 am ---The truth is that what I am doing is not a complicated application and it does quite simple things, I already have the same thing working perfectly in other protocols. It is this protocol that is giving me work and makes me think that I may be missing some additional configuration and it is being overlooked.
--- End quote ---
It seams that you are just starting with serial communication in FPC/LAZ, and you don't know yet where the problem is and what is it that you're doing wrong. If I was in your place, besides following forum suggestions, I would first decide if I need async or sync lib (I prefer separate communication threads so my choice is always sync lib like SynaSer), write the simplest 2-way communication test app using virtual serial ports (or 2 computers) where 2 instances of my app are both senders and receivers, and then play until all the basics are conquered.


--- Quote from: crisares on May 23, 2022, 03:14:57 am ---
--- Quote ---First is to use simple terminal and see if you get expected response when you send manual commands.
--- End quote ---
For that I use Stnterm and everything is perfect.
--- End quote ---
Good, then you know that everything works and that just FPC/LAZ side is bugging you.


--- Quote from: ccrause on May 23, 2022, 07:49:34 am ---
--- Quote from: crisares on May 22, 2022, 10:26:04 pm ---I have the Obdlink configured with the "ATSPC" protocol, which is the one that corresponds to the protocol that I am using USER2 CAN ID 11 bits, 50 kbaud.
8<-----
It is as if the STN1100 or the serial component had some configuration that I am missing in order to receive the frames through the Lazserial serial component.

--- End quote ---
Can you verify that Lazserial is working at 50 kbaud? This is not a standard baud, and afaics Lazserial only supports standard baud rates.
--- End quote ---
50 kbaud is the speed on CAN side of the adapter, which is quite different from the serial side of the adapter and is not related since commands from serial terminal already work without problems. OP probably has some serial commands or gui settings which select the desired CAN speed of the adapter.

Navigation

[0] Message Index

Go to full version