Recent

Author Topic: CAN-BUS SocketCAN  (Read 71889 times)

jcdammeyer

  • Full Member
  • ***
  • Posts: 205
  • Embedded System Developer
    • Automation Artisans Inc.
Re: CAN-BUS SocketCAN
« Reply #120 on: October 02, 2021, 02:12:30 am »
Here's the difference between the LinuxCNC Pi4 and the regular Pi4 Linux.
Version Value is different and both MainUnit Value and Modes Count don't exist in the fixlp file that doesn't work.

I wonder why. 

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: CAN-BUS SocketCAN
« Reply #121 on: October 04, 2021, 04:53:37 pm »
@jcdammeyer:

SocketCAN was never meant to be used with older FPC like 3.0.4. Even newer 3.2.x does not have needed constants. I use it with trunk since there is a plan for SocketCAN to end up in FPC 3.4 or 4.0, whichever comes first. Lazarus version should not matter at all, but it did since I used Lazarus trunk which introduced new LPI format. I fixed that in latest can.zip so use that instead.

While constants like AF_CAN, PF_CAN and PF_RDS can be added manually, whole units like termio certainly can't, so I wouldn't bother with such old FPC. Sorry, I do not provide support for that.

When I see that you still have members.pas in your LPI file, that tells me that you did not use latest can.zip where I fixed that (fixlp is also not needed with this latest archive). Btw, not having members.pas file in directory does not stop compilation at all. It just notifies you that it could not be found, and since it was not used at all - it didn't matter anyway.

I'm glad you somehow managed to compile at all, even with old FPC.
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

jcdammeyer

  • Full Member
  • ***
  • Posts: 205
  • Embedded System Developer
    • Automation Artisans Inc.
Re: CAN-BUS SocketCAN
« Reply #122 on: October 04, 2021, 06:16:30 pm »
I probably get confused at times too with which system is which.  I'm running a Pi Linux version on one MicroSD and a LinuxCNC on the other.  Add to that a Debian system on the Beagle which was no longer supported so with the help of Robert Nelson was able to upgrade the kernel and the OS to the latest version. 

I've only stayed with 2.0.10 because that worked on WIN-10, WIN-7, Linux, LinuxCNC, Pi3/4 and Beagle.  Upgrading one of those to a newer version means it has to be done on everything which is a lot of work.  I've found in the past that it's best to not be on the bleeding edge but I guess trying out socketCAN for Lazarus is really still working on the bleeding edge.

I recall from looking at older Delphi libraries that I thought I saw {$ifdef... statements that tested versions of the compiler.  Should that not then be in socketCAN libraries so if one tries to compile applications that require > 3.2.x that the compiler complains and stops.  If sample applications are dependent on that then should that not also exist in those samples?

But if it's time to upgrade then so be it.

« Last Edit: October 04, 2021, 06:19:22 pm by jcdammeyer »

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: CAN-BUS SocketCAN
« Reply #123 on: October 05, 2021, 01:15:52 am »
I recall from looking at older Delphi libraries that I thought I saw {$ifdef... statements that tested versions of the compiler.  Should that not then be in socketCAN libraries so if one tries to compile applications that require > 3.2.x that the compiler complains and stops.  If sample applications are dependent on that then should that not also exist in those samples?
It was never meant to make SocketCAN a library that works with any FPC version. It can be forced but it would be a mine field which I do not recommend. In one of the old messages in this thread you can find exact FPC revision that I added missing constants to, and which has everything else needed - but if you do not feel like hunting it down, then current trunk FPC will do. This is just a playground and SocketCAN will be part of FPC, so there will be no need for ifdefs in code. As for Lazarus, my last can.zip does not depend on Lazarus 2.1+ any more and should work with any Lazarus 2.0.x and maybe even older.
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

jcdammeyer

  • Full Member
  • ***
  • Posts: 205
  • Embedded System Developer
    • Automation Artisans Inc.
Re: CAN-BUS SocketCAN
« Reply #124 on: October 05, 2021, 01:34:41 am »
Thanks,
The two windows systems (WIN-7 and WIN-10) have been upgraded to trunk and trunk.  The reason for maintaining windows compatibility isn't just for socketCAN but also for that graphical issue a few months back.  Now I have to find out where I put all the packages.  Sloppy on my part.

And therein lies the problem with constantly updating.  All the lpk packages have to be rebuilt and installed into the IDE.  It was always the worst part of upgrading Delphi too.

Then I'll upgrade my Linux systems.

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: CAN-BUS SocketCAN
« Reply #125 on: October 06, 2021, 11:09:17 am »
The two windows systems (WIN-7 and WIN-10) have been upgraded to trunk and trunk.
Since projects can now be opened in older Lazarus, there was no real need to use Lazarus trunk, but it will not hurt. In case you want to be able to open your own projects saved with Lazarus 2.1+ in Lazarus 2.0.x and older, you can go to Project Options / Misellaneous and check Maximize compatibility of project files (LPI and LPS). That's all I did in latest can.zip, so fixlp is not needed any more.

If you use fpcupdeluxe, then it would be wise to write down exact revision of FPC and LAZ combo you used at one place, and then tell fpcupdeluxe to download that exact combo on each system you use for SocketCAN. That would eliminate a lot of ifs in case of problems.

And therein lies the problem with constantly updating.  All the lpk packages have to be rebuilt and installed into the IDE.  It was always the worst part of upgrading Delphi too.
If you use fpcupdeluxe, then once you install it in one OS/CPU combo, you can simply copy whole dir and desktop shortcut to another machine with the same (or compatible) OS/CPU combo. That's all. No need for reinstallation all over again. And sometimes cross compilation can also save the day...
« Last Edit: October 06, 2021, 11:16:05 am by avra »
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

jcdammeyer

  • Full Member
  • ***
  • Posts: 205
  • Embedded System Developer
    • Automation Artisans Inc.
Re: CAN-BUS SocketCAN
« Reply #126 on: October 06, 2021, 07:02:35 pm »
Since projects can now be opened in older Lazarus, there was no real need to use Lazarus trunk, but it will not hurt. In case you want to be able to open your own projects saved with Lazarus 2.1+ in Lazarus 2.0.x and older, you can go to Project Options / Misellaneous and check Maximize compatibility of project files (LPI and LPS). That's all I did in latest can.zip, so fixlp is not needed any more.

For some reason, even after 3 tries I couldn't get the trunk/trunk version to install on the Pi4 LinuxCNC version.  What finally worked was the trunk fpc which then built your examples correctly.   The 2.0.10 Lazarus did install and that's what I was running on the others.  And that created the same problem from 6 months ago.
Code: Pascal  [Select][+][-]
  1.     if (DevCtx.IsNullPen and (DevCtx.IsNullBrush or Winding)) then
Had to go back through all my postings to find that solution and now the sample 7 segment programs work on all three systems.  The Pi is using FPC 3.3.1 and Laz 10.0.2.  The Beagle is using Laz 10.0.2 and I think 3.3.1 but for some reason the compiler version isn't showing up on the messages.  The same boxes appear to be checked in the Project Options verbosity.  I only updated the FPC on the Beagle.  PCs are both running 3.3.1 and Laz 2.3.0 but then Windows never had the issue with the "Winding".

Quote
If you use fpcupdeluxe, then it would be wise to write down exact revision of FPC and LAZ combo you used at one place, and then tell fpcupdeluxe to download that exact combo on each system you use for SocketCAN. That would eliminate a lot of ifs in case of problems.

And therein lies the problem with constantly updating.  All the lpk packages have to be rebuilt and installed into the IDE.  It was always the worst part of upgrading Delphi too.
If you use fpcupdeluxe, then once you install it in one OS/CPU combo, you can simply copy whole dir and desktop shortcut to another machine with the same (or compatible) OS/CPU combo. That's all. No need for reinstallation all over again. And sometimes cross compilation can also save the day...

In either case, updating to 3.3.1 allows all your examples to compile.  Thanks for all your help. 

Now I have to chase the usual BBB kernal and OS update issues.  Seems now the paths to the SPI devices have changed so once again Derek Molloy's book has sections now that are wrong.    And where I used to be able to read a 1-Wire device on the BBB it no longer shows up.  Probably something in the cape EEROM.  Constant upgrades that break old programs are such a pain. 


avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: CAN-BUS SocketCAN
« Reply #127 on: October 06, 2021, 08:56:43 pm »
...that created the same problem from 6 months ago... Had to go back through all my postings to find that solution and now the sample 7 segment programs work on all three systems.
Well, LCL evolves so from time to time you need to check your projects for compatibility. SocketCAN should work with your old Lazarus, but your project which uses some GUI features that changed in newer Lazarus was the reason for incompatibility. Glad you fixed that after all.

In either case, updating to 3.3.1 allows all your examples to compile.  Thanks for all your help.
You're most welcome. I'm glad that you can finally compile all SocketCAN demos.
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

jcdammeyer

  • Full Member
  • ***
  • Posts: 205
  • Embedded System Developer
    • Automation Artisans Inc.
Re: CAN-BUS SocketCAN
« Reply #128 on: October 06, 2021, 10:21:38 pm »
I had already started my own CANopen unit which included a CAN message data structure.  I'll see if I can't convert that over to use the socketCAN data structures and add {$ifdef for WIN or LINUX so I can still run with the CANUSB on the windows systems but switch over to socketCAN on the Linux ones.  That will allow me to use the MCP2515 devices on the Pi and the internal CAN device on the Beagle.

When that's all done and working I'll post the Lazarus source code for the project.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: CAN-BUS SocketCAN
« Reply #129 on: October 19, 2021, 12:02:03 pm »
Noting that this is the dominant Canbus thread: what interface hardware are people using for general development on a PC? I might need to prod at a vehicle subsystem with Canbus as one (fortunately not the only one) of the interfaces.

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

jcdammeyer

  • Full Member
  • ***
  • Posts: 205
  • Embedded System Developer
    • Automation Artisans Inc.
Re: CAN-BUS SocketCAN
« Reply #130 on: October 19, 2021, 07:29:42 pm »
Noting that this is the dominant Canbus thread: what interface hardware are people using for general development on a PC? I might need to prod at a vehicle subsystem with Canbus as one (fortunately not the only one) of the interfaces.

MarkMLl

It's because I have four of the CANUSB from Lawicel in Sweden that it is one of the first tools I grab but the software support for monitoring isn't the best.  I think there are clones from China for even less.

For some monitoring on my car before a friend loaned me a Code Monitor I built up an Arduino with the add on SPI based CAN board.  It would be easy enough to clone the basic serial side of the CANUSB protocol on it.

I also have a dongle from RM Michaelides with their software that is very good but over $500.  It's that user software that I'm sort of cloning onto Lazarus.   The Lazarus software works with the serial port (COMx: on windows, /dev/ttyUSBx on Linux).

I also have a KVaser Lief USB dongle.  Rarely use it.  They are even more money.

For the Beagle I have a cape with the CAN and RS485 driver.  For the Pi I have a single and dual CAN cape both using SPI.

The Lazarus software has a long way to go.  I've been side tracked by other projects but I can zip up what I have if you want it.
John

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: CAN-BUS SocketCAN
« Reply #131 on: October 19, 2021, 08:27:10 pm »
It's because I have four of the CANUSB from Lawicel in Sweden that it is one of the first tools I grab but the software support for monitoring isn't the best.  I think there are clones from China for even less.

Thanks for that. I see http://www.can232.com/?page_id=16 and note that that's described as having an FTDI interface, so I've got a fair degree of confidence that Linux will see it (as remarked elsewhere, I've bought lots of stuff over the last year or so that has an embedded serial chip).

Is the clone you're thinking about something like https://www.ebay.co.uk/itm/143099880796 ?

I can see the various SPI interfaces, but at least initially I want to be able to exercise some kit from my desk.

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: CAN-BUS SocketCAN
« Reply #132 on: October 19, 2021, 08:32:51 pm »
Noting that this is the dominant Canbus thread: what interface hardware are people using for general development on a PC? I might need to prod at a vehicle subsystem with Canbus as one (fortunately not the only one) of the interfaces.

Linux has best tools and allows greatest hacking capability, so you could use these (Pi based on MCP2515):
For the Beagle I have a cape with the CAN and RS485 driver.  For the Pi I have a single and dual CAN cape both using SPI.

Lawicel based ones work with both Windows and Linux (and can occasionally drop frames on very congested 1Mbit networks), but above ones are my favorites (especially if you have proper DBC files for automatic data decoding). For software/hardware specifics read my older messages.
« Last Edit: October 19, 2021, 08:35:31 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: CAN-BUS SocketCAN
« Reply #133 on: October 19, 2021, 08:44:26 pm »
Noting that this is the dominant Canbus thread: what interface hardware are people using for general development on a PC? I might need to prod at a vehicle subsystem with Canbus as one (fortunately not the only one) of the interfaces.

Linux has best tools and allows greatest hacking capability, so you could use these (Pi based on MCP2515):
For the Beagle I have a cape with the CAN and RS485 driver.  For the Pi I have a single and dual CAN cape both using SPI.

Lawicel based ones work with both Windows and Linux (and can occasionally drop frames on very congested 1Mbit networks), but above ones are my favorites (especially if you have proper DBC files for automatic data decoding). For software/hardware specifics read my older messages.

Thanks Avra, noted. It's all extremely tentative at the moment, I anticipate it would be entirely point-to-point and low-speed.

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

jcdammeyer

  • Full Member
  • ***
  • Posts: 205
  • Embedded System Developer
    • Automation Artisans Inc.
Re: CAN-BUS SocketCAN
« Reply #134 on: October 19, 2021, 08:44:54 pm »

Thanks for that. I see http://www.can232.com/?page_id=16 and note that that's described as having an FTDI interface, so I've got a fair degree of confidence that Linux will see it (as remarked elsewhere, I've bought lots of stuff over the last year or so that has an embedded serial chip).

Is the clone you're thinking about something like https://www.ebay.co.uk/itm/143099880796 ?

I can see the various SPI interfaces, but at least initially I want to be able to exercise some kit from my desk.

MarkMLl

The biggest problem with that one and most of the crap coming from China is that the CAN bus is designed for 3 wires, not two.  Ground is a fundamental part of the circuit and it's find if you have an arduino or Pi which is also powered from the vehicle 12V power system as at some point the arduino power ground matches up with the vehicle CAN bus ground .

The late Steve Corrigan at TI (he designed TI's CAN driver chips) and I had a long discussion about that.  I even set up two 82C250 CAN transceivers both run from 9V batteries into 78L05 regulators.  I coupled only the two CAN signals so no physical ground connection.  There was no problem sending with only two wires so you'd think it would be fine.  Which is why you see the crap out there not supplying a ground assuming the vehicle ground is on both.  But here's the reason you need the ground.

Ultimately it's possible for the ground from one device to be connected to the ground from the other through some peculiar way.  Now the two CAN signals which are referenced to ground (2.5V is recessive relative to their own ground) could have more than 7V between the two grounds.  This results in a common mode voltage that is higher than the transceiver and it pops.  Or worse you don't exceed it but you get a lot of bus faults that are sporadic and non-deterministic.   The error counters go up and down and you can't pinpoint the reason.  As soon as you put the scope on it the errors  go away.

So watch out for dongles that don't provide the standard DB-9 CANopen pin format.  Notice on this link they don't make the ground pin optional.

https://www.kvaser.com/about-can/the-can-protocol/can-connectors/



 

TinyPortal © 2005-2018