Recent

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

jcdammeyer

  • Full Member
  • ***
  • Posts: 195
  • Embedded System Developer
    • Automation Artisans Inc.
Re: CAN-BUS SockectCAN
« Reply #90 on: September 24, 2021, 07:30:21 pm »
I'm glad you like the progress.  :D ;) :D
If you need CANopen now, then you will have to implement it on your own. Patches are welcome.
The problem with CANopen is it's huge and for 99% of the projects (IMHO) doesn't need to be.  For example, a big deal is made over the support of the configuration files.  Useful for the non-programmer mechanical engineer or installer but for someone who writes in Delphi or Lazarus not so much.  Building up the object dictionary (OD) to show the size of variables pointless and just takes up a lot of code/data space.  Creating a be all end all installation would be nice but also overkill and hard to understand and maintain.

So I'm proposing a CANopen Lite.  That can deal with COTS (Commercial Off The Shelf) devices but might require a bit of programming to interface with.  To start with I've started with a simple monitoring program that at the moment uses the CANUSB.  So far this software has run on WIN-PC, BeagleBone and Pi. 

To migrate to socketCAN it will need a level of abstraction built in so we can open a device like the internal processor built in CAN on a BeagleBone or a Pi3 HAT that uses the MCP2515 SPI to CAN device and of course the socketCAN version of CANUSB.  I have two HATs for the Pi, a cape for the Beagle and lots of CANUSB plus a few expensive commercial USB dongles.

I will of course make the entire program open source. 
« Last Edit: September 24, 2021, 07:32:10 pm by jcdammeyer »

avra

  • Hero Member
  • *****
  • Posts: 2249
    • Additional info
Re: CAN-BUS SockectCAN
« Reply #91 on: September 25, 2021, 01:02:20 am »
To migrate to socketCAN it will need a level of abstraction built in so we can open a device like the internal processor built in CAN on a BeagleBone or a Pi3 HAT that uses the MCP2515 SPI to CAN device and of course the socketCAN version of CANUSB.
Step-by-step guide on using Lawicel CANUSB via SocketCAN: https://pascal-walter.blogspot.com/2015/08/installing-lawicel-canusb-on-linux.html
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

jcdammeyer

  • Full Member
  • ***
  • Posts: 195
  • Embedded System Developer
    • Automation Artisans Inc.
Re: CAN-BUS SockectCAN
« Reply #92 on: September 25, 2021, 01:10:02 am »
To migrate to socketCAN it will need a level of abstraction built in so we can open a device like the internal processor built in CAN on a BeagleBone or a Pi3 HAT that uses the MCP2515 SPI to CAN device and of course the socketCAN version of CANUSB.
Step-by-step guide on using Lawicel CANUSB via SocketCAN: https://pascal-walter.blogspot.com/2015/08/installing-lawicel-canusb-on-linux.html

Yes.  Thank you.  That's not an issue.  I've dumped CAN packets from working systems using socketCAN with the CANUSB on the PI3/4.  But that's using the C language command line programs.   

A couple of years ago now I had to record Hydrogen powered vehicle CAN messages from ignition key on and the Pi wasn't capable of booting in under 14 seconds.   So instead I put together a small PIC32 with CAN module that logged/timestamped all CAN messages along with GPS information and sent them up via SPI to the PiZero once it was awake. On the Pi they were saved in files and another application would grab them and put them on the cloud for the engineers to use for diagnostics.

Really looking forward to playing with your socketCAN stuff.
John


avra

  • Hero Member
  • *****
  • Posts: 2249
    • Additional info
Re: CAN-BUS SockectCAN
« Reply #93 on: September 25, 2021, 11:02:03 am »
I've dumped CAN packets from working systems using socketCAN with the CANUSB on the PI3/4.  But that's using the C language command line programs.
As you progress through pascal SocketCAN demos, you will see that low level units will help when you want to convert C examples from the net since it will mostly be 1:1 translation as far as SocketCAN part is concerned. Once you get a feeling, you will quickly advance to more natural pascalish high level unit.

Really looking forward to playing with your socketCAN stuff.
I wish you as much fun as I have!  :D
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

jcdammeyer

  • Full Member
  • ***
  • Posts: 195
  • Embedded System Developer
    • Automation Artisans Inc.
Re: CAN-BUS SockectCAN
« Reply #94 on: September 26, 2021, 05:49:40 am »
I wish you as much fun as I have!  :D
Not quite yet.
Under Lazarus I can create a console project, add this
writeln('Hello World from my Console Application');
 in the appropriate spot and then either run it from the IDE or from the console with that output.

Opening the canreceive project from the can.zip file compiles but doesn't generate an executable on the Beaglebone as shown in the attached screen shot.

Code: Pascal  [Select][+][-]
  1.     s := fpsocket(PF_CAN, SOCK_RAW, CAN_RAW);
And the BBB sockets.pp doesn't have PF_CAN so the can.zip file by itself isn't enough to compile and test. 

ie. if I add this along with the perror function it complains about the missing PF_CAN
Code: Pascal  [Select][+][-]
  1.     s := fpsocket(PF_CAN, SOCK_RAW, CAN_RAW);
  2.     if s < 0 then
  3.     begin
  4.       perror('Socket');
  5.       Exit;
  6.     end;
  7.  

Would you be able to create a canreceive.zip with a console application who's sole purpose is to open say slcan0 and just dump out messages like your canreceive.  For example the 3 attachments show that the CANUSB on /dev/ttyUSB0 can be accessed as a serial port via the CANopenLite application but can also be configured as slcan0 as shown in the other photo working with the socketCAN candump application.

So my hardware works.  Now the software.


avra

  • Hero Member
  • *****
  • Posts: 2249
    • Additional info
Re: CAN-BUS SockectCAN
« Reply #95 on: September 26, 2021, 05:00:21 pm »
BBB sockets.pp doesn't have PF_CAN
As mentioned at https://forum.lazarus.freepascal.org/index.php/topic,39858.msg396135.html#msg396135 you need newer FPC so getting trunk would be a good idea. If that is not for you, then instead you could simply define missing constants PF_CAN and AF_CAN as 29 somewhere in your code. After that, it would be good to create vcan0 virtual adapter and go through demos since they should all work out of the box.

Would you be able to create a canreceive.zip with a console application who's sole purpose is to open say slcan0 and just dump out messages like your canreceive.
Once you have demos working with vcan0, making them work with slcan0 should be trivial. For example, in canreceive.lpr or hlcanreceive.lpr, all you need is to replace 'vcan0' with 'slcan0' at one place in code (as shown in your 3rd attachment).
« Last Edit: September 26, 2021, 05:04:39 pm by avra »
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

jcdammeyer

  • Full Member
  • ***
  • Posts: 195
  • Embedded System Developer
    • Automation Artisans Inc.
Re: CAN-BUS SockectCAN
« Reply #96 on: September 26, 2021, 07:22:11 pm »
BBB sockets.pp doesn't have PF_CAN
As mentioned at https://forum.lazarus.freepascal.org/index.php/topic,39858.msg396135.html#msg396135 you need newer FPC so getting trunk would be a good idea. If that is not for you, then instead you could simply define missing constants PF_CAN and AF_CAN as 29 somewhere in your code. After that, it would be good to create vcan0 virtual adapter and go through demos since they should all work out of the box.
Sadly this link doesn't work anymore which is why I posted the question.
Quote
CAN constants have been added to FPC 48867:
https://svn.freepascal.org/svn/fpc/trunk/packages/rtl-extra/src/linux/unxsockh.inc
In fact I can't even access https://svn.freepasccal.org


dsiders

  • Hero Member
  • *****
  • Posts: 520
Re: CAN-BUS SockectCAN
« Reply #97 on: September 26, 2021, 08:07:10 pm »
Quote
CAN constants have been added to FPC 48867:
https://svn.freepascal.org/svn/fpc/trunk/packages/rtl-extra/src/linux/unxsockh.inc
In fact I can't even access https://svn.freepasccal.org

You have two issues:

The URL was https://svn.freepascal.org and not https://svn.freepasccal.org.

They moved to GitLab a few months back and the svn server no longer exists. There is a GitHub SVN mirror at: https://github.com/fpc/FPCSource, but the vcs of record is git located at: https://gitlab.com/freepascal.org/fpc/source.
« Last Edit: September 26, 2021, 08:56:10 pm by dsiders »
Lazarus 2.0.12, 2.2.0-RC1, 2.3.0 (Git) / FPC 3.2.0, 3.2.2 / x86-win64 / Windows 8.1

jcdammeyer

  • Full Member
  • ***
  • Posts: 195
  • Embedded System Developer
    • Automation Artisans Inc.
Re: CAN-BUS SocketCAN
« Reply #98 on: September 26, 2021, 08:45:45 pm »
Incorrect spelling.  Sorry about that.  If possible then the link way back should be edited to point to the correct location.

What I did is add the PF_CAN and AF_CAN definitions into my code.  I also did put them into unxsockh.inc but it didn't have any effect.  Perhaps there's another copy being used instead.

Here's the results of the code below where I cut and pasted the canreceive.lpr section:
Code: [Select]
debian@ebb:~/lazarus/AvraCAN$ ./ConsoleApplication
Hello World from Console Application
CAN Sockets Receive Demo Rev 0.01
fpsocket call
fpioctl call
fpbind call
fpread call
Standard CAN frame received with length 1
0x718 [1] 05
debian@ebb:~/lazarus/AvraCAN$

Code: Pascal  [Select][+][-]
  1. program ConsoleApplication;
  2.  
  3. {$mode delphi}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  7.   cthreads,
  8.   {$ENDIF}{$ENDIF}
  9.   Classes, SysUtils, CustApp,
  10.   { you can add units after this }
  11.   sockets, baseunix, can;
  12.  
  13. const
  14.          PF_CAN = 29;
  15.          AF_CAN = 29;
  16.  
  17. type
  18.  
  19.   { TMyApplication }
  20.  
  21.   TMyApplication = class(TCustomApplication)
  22.   protected
  23.     procedure DoRun; override;
  24.   public
  25.     constructor Create(TheOwner: TComponent); override;
  26.     destructor Destroy; override;
  27.     procedure WriteHelp; virtual;
  28.     procedure perror(const S : string);
  29.     procedure MyApplicationMain;
  30.   end;
  31.  
  32. { TMyApplication }
  33. procedure TMyApplication.perror(const S : string);
  34. begin
  35.   WriteLn(S, ', SocketError = ', SocketError);
  36. end;
  37.  
  38.  
  39. procedure TMyApplication.MyApplicationMain;
  40. var
  41.   s, i, nbytes, err: cint;
  42.   addr:              sockaddr_can;
  43.   ifr:               ifreq;
  44.   frame:             canfd_frame;
  45. begin
  46.   Writeln('Hello World from Console Application');
  47.   WriteLn('CAN Sockets Receive Demo Rev 0.01');
  48.   writeln('fpsocket call');
  49.   s := fpsocket(PF_CAN, SOCK_RAW, CAN_RAW);
  50.   if s < 0 then
  51.   begin
  52.     perror('Socket');
  53.     Exit;
  54.   end;
  55.  
  56.   writeln('fpioctl call');
  57.   strcopy(ifr.ifr_name, 'slcan0'); // ifr.ifr_name := 'vcan0' + #0;
  58.   if fpioctl(s, SIOCGIFINDEX, @ifr) < 0 then
  59.   begin
  60.     perror('IOctl');
  61.     Exit;
  62.   end;
  63.  
  64.   writeln('fpbind call');
  65.   memset(@addr, 0, sizeof(addr));
  66.   addr.can_family  := AF_CAN;
  67.   addr.can_ifindex := ifr.ifr_ifindex;
  68.  
  69.   if fpbind(s, @addr, sizeof(addr)) < 0 then
  70.   begin
  71.     perror('Bind');
  72.     Exit;
  73.   end;
  74.  
  75.   writeln('fpread call');
  76.   nbytes := fpread(s, frame, sizeof(frame));
  77.   if nbytes < 0 then
  78.   begin
  79.     perror('Read');
  80.     Exit;
  81.   end;
  82.  
  83.   if nbytes = CANFD_MTU then    // test CAN FD with 'cansend vcan0 123##1223344556677889900'
  84.     WriteLn('CAN FD frame received with length ', IntToStr(frame.len))
  85.   else if nbytes = CAN_MTU then // test legacy CAN with 'cansend vcan0 456#DEADBEEF'
  86.     WriteLn('Standard CAN frame received with length ', IntToStr(frame.len))
  87.   else
  88.     WriteLn('Invalid CAN(FD) frame received');
  89.  
  90.   Write(Format('0x%03X [%d] ', [frame.can_id and CAN_EFF_MASK, frame.len]));
  91.   for i := 0 to frame.len - 1 do
  92.     Write(Format('%02.2X ', [frame.data[i]]));
  93.   WriteLn('');
  94.  
  95.   if fpclose(s) < 0 then
  96.   begin
  97.     perror('Close');
  98.     Exit;
  99.   end;
  100.  
  101. end;
  102.  
  103. procedure TMyApplication.DoRun;
  104. var
  105.   ErrorMsg: String;
  106. begin
  107.   // quick check parameters
  108.   ErrorMsg:=CheckOptions('h', 'help');
  109.   if ErrorMsg<>'' then begin
  110.     ShowException(Exception.Create(ErrorMsg));
  111.     Terminate;
  112.     Exit;
  113.   end;
  114.  
  115.   // parse parameters
  116.   if HasOption('h', 'help') then begin
  117.     WriteHelp;
  118.     Terminate;
  119.     Exit;
  120.   end;
  121.  
  122.   { add your program here }
  123.   MyApplicationMain;
  124.  
  125.   // stop program loop
  126.   Terminate;
  127. end;
  128.  
  129. constructor TMyApplication.Create(TheOwner: TComponent);
  130. begin
  131.   inherited Create(TheOwner);
  132.   StopOnException:=True;
  133. end;
  134.  
  135. destructor TMyApplication.Destroy;
  136. begin
  137.   inherited Destroy;
  138. end;
  139.  
  140. procedure TMyApplication.WriteHelp;
  141. begin
  142.   { add your help code here }
  143.   writeln('Usage: ', ExeName, ' -h');
  144. end;
  145.  
  146. var
  147.   Application: TMyApplication;
  148. begin
  149.   Application:=TMyApplication.Create(nil);
  150.   Application.Title:='My Application';
  151.   Application.Run;
  152.   Application.Free;
  153. end.
  154.  
  155.  

No idea why canreceive.lpr won't compile into an executable.

jcdammeyer

  • Full Member
  • ***
  • Posts: 195
  • Embedded System Developer
    • Automation Artisans Inc.
Re: CAN-BUS SocketCAN
« Reply #99 on: September 26, 2021, 10:32:19 pm »
I've updated the program and formatted it to match the socketCAN candump program.  Only does standard IDs, no Extended ID or CANFD.  CANFD likely won't happen as I have absolutely no CANFD units here and no desire to actually use it.  99.9% of everything I have in stock in drivers, devices, dongles are all non-CANFD.

Quote
debian@ebb:~/lazarus/AvraCAN$ ./ConsoleApplication
CAN Sockets Receive Demo Rev 0.1 Build 5
slcan0  298   [7]  00 00 00 00 01 00 00
slcan0  718   [1]  05
slcan0  298   [7]  00 00 00 00 01 00 00
slcan0  298   [7]  00 00 00 00 01 00 00
slcan0  718   [1]  05
slcan0  298   [7]  00 00 00 00 01 00 00
slcan0  298   [7]  00 00 00 00 01 00 00
slcan0  718   [1]  05
slcan0  298   [7]  00 00 00 00 01 00 00
slcan0  298   [7]  00 00 00 00 01 00 00
slcan0  718   [1]  05
debian@ebb:~/lazarus/AvraCAN$

And here's the updated console application.  I'll hang a module on that generates Extended 29 bit ID messages and add support for that to match candump.  I'll also add a command line parameter that allows defining which CAN device is to be used.  Since this test is on a Beagle I'll put the CAN cape on it, verify with the socketCAN candump that it works and then test it with the Lazarus program.

Code: Pascal  [Select][+][-]
  1. program ConsoleApplication;
  2.  
  3. {$mode delphi}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  7.   cthreads,
  8.   {$ENDIF}{$ENDIF}
  9.   Classes, SysUtils, CustApp,
  10.   { you can add units after this }
  11.   crt,  { for the keypressed function }
  12.   sockets, baseunix, can;  { for socketCAN support }
  13.  
  14. const
  15.          PF_CAN = 29;  // Not defined in libraries yet.
  16.          AF_CAN = 29;
  17.  
  18. type
  19.  
  20.   { TMyApplication }
  21.  
  22.   TMyApplication = class(TCustomApplication)
  23.   protected
  24.     procedure DoRun; override;
  25.   public
  26.     constructor Create(TheOwner: TComponent); override;
  27.     destructor Destroy; override;
  28.     procedure WriteHelp; virtual;
  29.     procedure perror(const S : string);
  30.     procedure MyApplicationMain;
  31.   end;
  32.  
  33. { TMyApplication }
  34. procedure TMyApplication.perror(const S : string);
  35. begin
  36.   WriteLn(S, ', SocketError = ', SocketError);
  37. end;
  38.  
  39.  
  40. procedure TMyApplication.MyApplicationMain;
  41. var
  42.   s, i, nbytes, err: cint;
  43.   addr:              sockaddr_can;
  44.   ifr:               ifreq;
  45.   frame:             canfd_frame;
  46.  
  47. begin
  48. //  Writeln('Hello World from Console Application');
  49.   WriteLn('CAN Sockets Receive Demo Rev 0.1 Build 5');
  50. //  writeln('fpsocket call');
  51.   s := fpsocket(PF_CAN, SOCK_RAW, CAN_RAW);
  52.   if s < 0 then
  53.   begin
  54.     perror('Socket');
  55.     Exit;
  56.   end;
  57.  
  58. //  writeln('fpioctl call');
  59.   strcopy(ifr.ifr_name, 'slcan0'); // ifr.ifr_name := 'vcan0' + #0;
  60.   if fpioctl(s, SIOCGIFINDEX, @ifr) < 0 then
  61.   begin
  62.     perror('IOctl');
  63.     Exit;
  64.   end;
  65.  
  66. //  writeln('fpbind call');
  67.   memset(@addr, 0, sizeof(addr));
  68.   addr.can_family  := AF_CAN;
  69.   addr.can_ifindex := ifr.ifr_ifindex;
  70.  
  71.   if fpbind(s, @addr, sizeof(addr)) < 0 then
  72.   begin
  73.     perror('Bind');
  74.     Exit;
  75.   end;
  76.  
  77.   while (not keypressed) do begin
  78.     //  writeln('fpread call');
  79.       nbytes := fpread(s, frame, sizeof(frame));
  80.       if nbytes < 0 then
  81.       begin
  82.         perror('Read');
  83.         Exit;
  84.       end;
  85.  
  86.       if nbytes = CANFD_MTU then    // test CAN FD with 'cansend vcan0 123##1223344556677889900'
  87.         WriteLn('CAN FD frame received with length ', IntToStr(frame.len))
  88.       else if nbytes = CAN_MTU then // test Standard CAN with 'cansend vcan0 456#DEADBEEF'
  89.     //    WriteLn('Standard CAN frame received with length ', IntToStr(frame.len))
  90.           write(ifr.ifr_name, '  ')
  91.       else
  92.         WriteLn('Invalid CAN(FD) frame received');
  93.  
  94.       Write(Format('%03X   [%d]  ', [frame.can_id and CAN_EFF_MASK, frame.len]));
  95.       for i := 0 to frame.len - 1 do
  96.         Write(Format('%02.2X ', [frame.data[i]]));
  97.       WriteLn('');
  98.   end;
  99.  
  100.   if fpclose(s) < 0 then
  101.   begin
  102.     perror('Close');
  103.     Exit;
  104.   end;
  105.  
  106. end;
  107.  
  108. procedure TMyApplication.DoRun;
  109. var
  110.   ErrorMsg: String;
  111. begin
  112.   // quick check parameters
  113.   ErrorMsg:=CheckOptions('h', 'help');
  114.   if ErrorMsg<>'' then begin
  115.     ShowException(Exception.Create(ErrorMsg));
  116.     Terminate;
  117.     Exit;
  118.   end;
  119.  
  120.   // parse parameters
  121.   if HasOption('h', 'help') then begin
  122.     WriteHelp;
  123.     Terminate;
  124.     Exit;
  125.   end;
  126.  
  127.   { add your program here }
  128.   MyApplicationMain;
  129.  
  130.   // stop program loop
  131.   Terminate;
  132. end;
  133.  
  134. constructor TMyApplication.Create(TheOwner: TComponent);
  135. begin
  136.   inherited Create(TheOwner);
  137.   StopOnException:=True;
  138. end;
  139.  
  140. destructor TMyApplication.Destroy;
  141. begin
  142.   inherited Destroy;
  143. end;
  144.  
  145. procedure TMyApplication.WriteHelp;
  146. begin
  147.   { add your help code here }
  148.   writeln('Usage: ', ExeName, ' -h');
  149. end;
  150.  
  151. var
  152.   Application: TMyApplication;
  153. begin
  154.   Application:=TMyApplication.Create(nil);
  155.   Application.Title:='My Application';
  156.   Application.Run;
  157.   Application.Free;
  158. end.
  159.  
  160.  

John

jcdammeyer

  • Full Member
  • ***
  • Posts: 195
  • Embedded System Developer
    • Automation Artisans Inc.
Re: CAN-BUS SocketCAN
« Reply #100 on: September 26, 2021, 10:47:28 pm »
Oh and the messages you see are generated by the module in the photo.  The buttons enable an air cylinder and butterfly impact wrench to act as a power drawbar and are displayed on the Pi4 LinuxCNC display.  The Mist Coolant has been turned on so the 0x44 represents that output command and in the high nibble the output status.   You can see the bits in the PDO message changing as I press the button and the drawbar state machine is activated with one other output also switched ON.  The Pi4 LinuxCNC talks to the CAN bus via another Lawicel CANUSB. 

Quote
CAN Sockets Receive Demo Rev 0.1 Build 5
slcan0  298   [7]  00 44 00 00 01 00 00
slcan0  718   [1]  05
slcan0  298   [7]  00 44 00 00 01 00 00
slcan0  298   [7]  00 44 00 00 01 00 00
slcan0  718   [1]  05
slcan0  298   [7]  00 44 00 00 01 00 00
slcan0  298   [7]  00 44 00 00 01 00 00
slcan0  718   [1]  05
slcan0  298   [7]  00 44 00 00 01 00 00
slcan0  298   [7]  00 44 00 00 01 00 00
slcan0  298   [7]  02 44 00 00 01 00 02
slcan0  298   [7]  00 66 00 00 06 00 00
slcan0  718   [1]  05
slcan0  298   [7]  00 66 00 00 06 00 00
slcan0  298   [7]  00 66 00 00 06 00 00
slcan0  718   [1]  05
slcan0  298   [7]  00 66 00 00 06 00 00
slcan0  298   [7]  00 66 00 00 06 00 00
slcan0  718   [1]  05
slcan0  298   [7]  00 44 00 00 01 00 00
slcan0  298   [7]  00 44 00 00 01 00 00
slcan0  718   [1]  05

It's not yet mounted on the machine.  I only just learned about postings from avra on this.  For some reason I missed the email that things were being done.  Been a busy summer.  And yes.  Now I'm having fun again. ;D

jcdammeyer

  • Full Member
  • ***
  • Posts: 195
  • Embedded System Developer
    • Automation Artisans Inc.
Re: CAN-BUS SocketCAN
« Reply #101 on: September 27, 2021, 01:04:06 am »
This link had me confused for a bit, especially since I was referencing CAN0 in my notes too. 
https://github.com/BlueAndi/beaglebone_black_socketcan
However, that same cape does say CAN1 on it so when I switched to setting it up as CAN1 candump now works.
I recompiled the ConsoleApplication again to use can1 and then slcan0 and the Beagle now has two functional CAN bus channels; Lawicel CANUSB and the internal Beagle bone CAN1

Quote
debian@ebb:~$ candump can1
  can1  298   [7]  00 44 00 00 01 00 00
  can1  718   [1]  05
  can1  298   [7]  00 44 00 00 01 00 00
  can1  298   [7]  00 44 00 00 01 00 00
  can1  718   [1]  05
  can1  298   [7]  00 44 00 00 01 00 00
^Cdebian@ebb:~$ cd lazarus/AvraCAN/
debian@ebb:~/lazarus/AvraCAN$ ./ConsoleApplication
CAN Sockets Receive Demo Rev 0.1 Build 6
can1  298   [7]  00 44 00 00 01 00 00
can1  718   [1]  05
can1  298   [7]  00 44 00 00 01 00 00
can1  298   [7]  00 44 00 00 01 00 00
can1  718   [1]  05
can1  298   [7]  00 44 00 00 01 00 00
can1  298   [7]  00 44 00 00 01 00 00
can1  718   [1]  05
debian@ebb:~/lazarus/AvraCAN$ sudo ifconfig slcan0 up
[sudo] password for debian:
debian@ebb:~/lazarus/AvraCAN$ ./ConsoleApplication
CAN Sockets Receive Demo Rev 0.1 Build 7
slcan0  298   [7]  00 44 00 00 01 00 00
slcan0  718   [1]  05
slcan0  298   [7]  00 44 00 00 01 00 00
slcan0  298   [7]  00 44 00 00 01 00 00
slcan0  718   [1]  05
debian@ebb:~/lazarus/AvraCAN$
« Last Edit: September 27, 2021, 05:54:25 am by jcdammeyer »

jcdammeyer

  • Full Member
  • ***
  • Posts: 195
  • Embedded System Developer
    • Automation Artisans Inc.
Re: CAN-BUS SocketCAN
« Reply #102 on: September 27, 2021, 08:59:05 am »
BTW, if anyone wants more of a write-up on socketCAN this link might be useful.  The link is also in the can.pas application provided by avra:
https://www.kernel.org/doc/html/v5.10/networking/can.html

Also back in 2013 when I attended the CANopen Conference in Germany the attached pdf was one of the presentations.  This presentation goes over the Volkswagon contribution by Oliver Hartkopp who is also referenced in the can.pas document.

Just a bit of history...

avra

  • Hero Member
  • *****
  • Posts: 2249
    • Additional info
Re: CAN-BUS SocketCAN
« Reply #103 on: September 28, 2021, 01:47:04 pm »
I also did put them into unxsockh.inc but it didn't have any effect.
That would have also worked after FPC rebuilding.

No idea why canreceive.lpr won't compile into an executable.
What is the compilation error message? What FPC/LAZ/OS/ARCH/Bitness combo was used? Did you manage to compile other demos?

Also back in 2013 when I attended the CANopen Conference in Germany the attached pdf was one of the presentations.
Nice and simple bridge and ISO examples.
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

jcdammeyer

  • Full Member
  • ***
  • Posts: 195
  • Embedded System Developer
    • Automation Artisans Inc.
Re: CAN-BUS SocketCAN
« Reply #104 on: September 28, 2021, 07:14:33 pm »
I also did put them into unxsockh.inc but it didn't have any effect.
That would have also worked after FPC rebuilding.
Unfortunately at this point you lose me on what to do there.  I ran fpcupdeluxe to install the same version on the PC, Pi3/4 and BBB.  I would need the simpleton step by step procedure to do the 'FPC rebuilding' along with a "why I am doing what I'm doing"

Quote
No idea why canreceive.lpr won't compile into an executable.
What is the compilation error message? What FPC/LAZ/OS/ARCH/Bitness combo was used? Did you manage to compile other demos?
I opened up the .lpi project from Lazarus and did a build.  The screen capture I posted earlier and again here shows the result.  I tried a number of options with no success in creating an executable.  That's when I used the lazarus 'new' and selected console application program to create my stock application.  Then coppied and pasted the key parts that were needed to duplicate the basic functionality of candump.

Last night I created a new folder 'lazcandump' and copied over the initial files that appeared to be needed based on the uses clause and the {$i lines.  And then a bunch more that I'm not sure where were {$i when the compiler complained.  {It was late.  Easier to copy over than figure out why}

It now accepts 'can1' or 'slcan0' on the command line and then dumps the messages in the same way as the socketCAN candump.  I plugged a mcp2515 CAN hat into a Pi4 running LinuxCNC.  I think I still have to install Lazarus on that Pi4 but the socketCAN candump shows the messages created by the CANUSB when a checkbox is clicked on the LinuxCNC AXIS display.  More on that by the end of the day if all goes well.

Quote
Also back in 2013 when I attended the CANopen Conference in Germany the attached pdf was one of the presentations.
Nice and simple bridge and ISO examples.

I do have a zip of the entire conference proceedings (47MB) including my presentation (1.4MB) all too big to post here.


 

TinyPortal © 2005-2018