Recent

Author Topic: Frame reception problem in Fiat CAN ID 11 bits, 50 kbaud with STN1100 chip  (Read 535 times)

crisares

  • Jr. Member
  • **
  • Posts: 63
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  [Select][+][-]
  1.   lazserial1.WriteData('85 02 10 81 00 00 00 00' + #13#10);
  2.   SLEEP(100);
  3.   listbox1.items.add(lazserial1.ReadData);
  4.   listbox1.Refresh;
  5.   lazserial1.WriteData('85 02 1A 95 00 00 00 00' + #13#10);
  6.   SLEEP(100);
  7.   listbox1.items.add(lazserial1.ReadData);
  8.   listbox1.Refresh;
  9.   lazserial1.WriteData('85 02 1A 94 00 00 00 00' + #13#10);
  10.   SLEEP(100);
  11.   listbox1.items.add(lazserial1.ReadData);
  12.   listbox1.Refresh;
  13.   lazserial1.WriteData('85 30 FF 00 00 00 00 00 ' + #13#10);
  14.   SLEEP(100);
  15.   listbox1.items.add(lazserial1.ReadData);
  16.   listbox1.Refresh;
  17.  
   
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

  • Hero Member
  • *****
  • Posts: 2344
    • Additional info
I don't get any response via lazserial1.ReadData
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.

If there is someone who understands the subject and can give me a hand, I would appreciate it.
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.
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

crisares

  • Jr. Member
  • **
  • Posts: 63
Quote
I thought that LazSerial is event based, and that you should check for data in OnRxData?
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.
I'll give this a review...

Quote
I do understand the topic (implemented SocketCAN with freepascal) but you do not give much info.
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.
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.
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

  • Hero Member
  • *****
  • Posts: 574
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.
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

  • Hero Member
  • *****
  • Posts: 2344
    • Additional info
Quote
I thought that LazSerial is event based, and that you should check for data in OnRxData?
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...
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.

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.
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
First is to use simple terminal and see if you get expected response when you send manual commands.
For that I use Stnterm and everything is perfect.
Good, then you know that everything works and that just FPC/LAZ side is bugging you.

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.
Can you verify that Lazserial is working at 50 kbaud? This is not a standard baud, and afaics Lazserial only supports standard baud rates.
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.
« Last Edit: May 24, 2022, 08:44:03 am by avra »
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

 

TinyPortal © 2005-2018