Recent

Author Topic: Read and write automobile canbus frames with lazarus...  (Read 2218 times)

crisares

  • Jr. Member
  • **
  • Posts: 63
Read and write automobile canbus frames with lazarus...
« on: September 17, 2020, 09:46:27 pm »
Hi all.
I'm trying to figure out how it would be possible to do what I mention in the title of the post.
I know it is possible with some component and the correct USB / OBD2 interface.
Could someone guide me a little on the subject?
Currently I do this same thing but with arduino + shield canbus .. but it is quite limited and I do not master the C language of the Arduino IDE either.
Thanks and greetings to all

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Read and write automobile canbus frames with lazarus...
« Reply #1 on: September 17, 2020, 11:31:38 pm »
don't expect to be able to decode that directly to the PC because its not like the old days where you can sit there In real mode and loop a input to a serial port chip to build the 11 bit data field.

 You can however get Canbus to 232 converters and the 232 shows up in most systems as a serial port.


 From there you can then monitor the can traffic to start with once you figure out the protocol ID, DATA and CRC calculations
The only true wisdom is knowing you know nothing

crisares

  • Jr. Member
  • **
  • Posts: 63
Re: Read and write automobile canbus frames with lazarus...
« Reply #2 on: September 18, 2020, 01:23:31 am »
Hi Jamie! 
If I understand that and I did not expect to be able to do it directly ... If I understand ... without understanding much ... that it is possible with interfaces such as an elm327 with PIC or an obdlink with an STN chip through some Lazarus Serial component and AT commands  for example.
The identification of ID and data that I already have everything clear and I have identified all the information that I am going to read and write ... What I was looking for was someone who can guide or advise me on the appropriate component to be able to carry out that communication by  example..

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Read and write automobile canbus frames with lazarus...
« Reply #3 on: September 18, 2020, 03:56:27 am »
lazSerial should work for you if you plan on being in windows GUI..

I am no so sure about the Linux side of it, I know it is supported..

Synapses can be directly used also which lazserial uses.

It should work..
The only true wisdom is knowing you know nothing

af0815

  • Hero Member
  • *****
  • Posts: 1288
Re: Read and write automobile canbus frames with lazarus...
« Reply #4 on: September 18, 2020, 05:38:52 am »
lazSerial should work for you if you plan on being in windows GUI..

I am no so sure about the Linux side of it, I know it is supported..

Synapses can be directly used also which lazserial uses.

It should work..

LazSerial work on Win, Linux, RaspBian,...

About CAN to RS232 look at http://www.can232.com/?page_id=14 they have sample code on the download page (maybe D5)
« Last Edit: September 18, 2020, 05:42:17 am by af0815 »
regards
Andreas

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: Read and write automobile canbus frames with lazarus...
« Reply #5 on: September 18, 2020, 09:59:48 am »
You don't have to access canbus devices directly. Linux has standard interface SocketCAN and many devices (mcp251x, slcan/lawicel...) are already supported.

You should search forum for socketcan, and also take a look here:
https://www.elinux.org/CAN_Bus
https://www.elinux.org/Can-utils
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: Read and write automobile canbus frames with lazarus...
« Reply #6 on: September 18, 2020, 10:28:31 am »
Yes.
I also would like to add that it is way better to NOT use components like LazSerial, but work with classes instead.
Specialize a type, not a var.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: Read and write automobile canbus frames with lazarus...
« Reply #7 on: September 18, 2020, 10:29:43 am »
Might I just ask: to what extent does this overlap with OBD2 access, for which adapters are readily available?

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: Read and write automobile canbus frames with lazarus...
« Reply #8 on: September 18, 2020, 01:25:32 pm »
Might I just ask: to what extent does this overlap with OBD2 access, for which adapters are readily available?
OBD2 supports 5 communication protocols which also vary electrically on physical level. Only ISO 15765 uses CAN. CAN has variants based on identifier length, and latest edition even allows flexible data rate. There are also higher level protocols built on top of CAN. For example J1939 is used in trucks/buses/heavymachineryvehicles, or CANopen which is popular in automation.

OBD2 adapters usually support all car protocols. If your OBD2 adapter supports CAN and it is supported by linux (for example there is 3rd party socketcan driver for popular ELM327), and your car uses CAN interface on OBD2 connector, then you can make your own socketcan application, or use can-utils, wireshark and other tools for packet sniffing, receiving and sending.

You can do the same without OBD2 adapter if you have CAN adapter supported by socketcan, your car uses CAN interface on OBD2 connector, and you do proper wiring from your adapter to ODB2 connector.

Still actual read for people interested in car hacking: https://makezine.com/2016/04/08/car-hacking-tools-trade/

But CAN is not used only in vehicles. On electrical level it is based on very robust RS485, and because of very, very clever addressing scheme it allows multi masters on CAN network without any collisions and overhead. BOSCH really has some very clever engineers. Because of it's robustness, range, scalability and noise immunity it is used in vehicles, microcontrollers, programmable logic controllers, robots, home automation and many other places.
« Last Edit: September 18, 2020, 01:40:32 pm by avra »
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: Read and write automobile canbus frames with lazarus...
« Reply #9 on: September 18, 2020, 04:33:23 pm »
Thanks for that. I was broadly aware of CAN (and aware of RS485 etc. in rather more detail), but not how the overlap worked.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

crisares

  • Jr. Member
  • **
  • Posts: 63
Re: Leer y escribir marcos de canbus de automóviles con lázaro...
« Reply #10 on: September 18, 2020, 05:31:34 pm »
You don't have to access canbus devices directly. Linux has standard interface SocketCAN and many devices (mcp251x, slcan/lawicel...) are already supported.

You should search forum for socketcan, and also take a look here:
https://www.elinux.org/CAN_Bus
https://www.elinux.org/Can-utils


Thanks for the tips !! I do not use Linux .. but I will keep in mind in the future ...

BlueIcaro

  • Hero Member
  • *****
  • Posts: 792
    • Blog personal
Re: Read and write automobile canbus frames with lazarus...
« Reply #11 on: September 18, 2020, 10:42:58 pm »


But CAN is not used only in vehicles. On electrical level it is based on very robust RS485, and because of very, very clever addressing scheme it allows multi masters on CAN network without any collisions and overhead. BOSCH really has some very clever engineers. Because of it's robustness, range, scalability and noise immunity it is used in vehicles, microcontrollers, programmable logic controllers, robots, home automation and many other places.

CAN and Rs485 are different. Can was design by Bosch. Rs485 was design by standard ANSI/TIA/EIA-485-A-1998. CAN use a pulse signal over two lines (CH, CL), use 2,5 voltios as reference. CH move between 2,5 a 3,5 voltios, CL move betwen 2,5 and 1,5 voltios. Depending the state of CH and CL you have 0 or 1.
Rs485, use two lines (A,B). Compares voltage between A and B

A - B < -0,3V = MARK = OFF = Lógico 1    A - B > +0,3V = SPACE = ON = Lógico 0

/Blueicaro
« Last Edit: September 18, 2020, 10:44:44 pm by BlueIcaro »

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: Read and write automobile canbus frames with lazarus...
« Reply #12 on: September 21, 2020, 08:28:34 am »
But CAN is not used only in vehicles. On electrical level it is based on very robust RS485, and because of very, very clever addressing scheme it allows multi masters on CAN network without any collisions and overhead. BOSCH really has some very clever engineers. Because of it's robustness, range, scalability and noise immunity it is used in vehicles, microcontrollers, programmable logic controllers, robots, home automation and many other places.

CAN and Rs485 are different. Can was design by Bosch. Rs485 was design by standard ANSI/TIA/EIA-485-A-1998. CAN use a pulse signal over two lines (CH, CL), use 2,5 voltios as reference. CH move between 2,5 a 3,5 voltios, CL move betwen 2,5 and 1,5 voltios. Depending the state of CH and CL you have 0 or 1.
Rs485, use two lines (A,B). Compares voltage between A and B

A - B < -0,3V = MARK = OFF = Lógico 1    A - B > +0,3V = SPACE = ON = Lógico 0
Nice catch. I was doing PROFIBUS too much these days so I said that CAN is also based on RS485. That is simply not true, so thanks for the correction. Different transceivers are needed (although not impossible to make CAN work with RS485 ones), 1 and 0 are inverted, and CAN has additional OSI data link layer.
« Last Edit: September 21, 2020, 10:36:01 am by avra »
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

 

TinyPortal © 2005-2018