Lazarus

Programming => Networking and Web Programming => Topic started by: rampinia on January 28, 2018, 10:20:35 am

Title: CAN-BUS SockectCAN
Post by: rampinia on January 28, 2018, 10:20:35 am
Hello to all

does anyone did programming socket in the class PF_CAN for accessing CAN-BUS in Linux?
On the wiki side I have seen there are not current constant declaration for such network protocoll.

If the pfsocket and others call are just wrapper for standard BSD socket call I think it is enaugh to declare the constant just porting from the standard linux header.

Any info?

Thanks
Title: Re: CAN-BUS SockectCAN
Post by: marcov on January 28, 2018, 10:43:14 am
Yes, the sockets unit are just wrappers. Best is if somebody finds the constants, tests it, and then submits a patch.
Title: Re: CAN-BUS SockectCAN
Post by: rampinia on January 28, 2018, 06:30:27 pm
Yes

got PF_CAN = 29 and CAN_RAW = 1 from sys/if.h

already run some tests with PF_CAN = 29 and CAN_RAW = 1 and it works.

I'm working a minimal porting from C header.
Title: Re: CAN-BUS SockectCAN
Post by: RM on March 11, 2019, 08:50:21 am
Hello at all, i am new here...

I try to establish a CAN connection on the raspberry pi (stretch), using free pascal.
I successfully created a raw socket with PF_CAN=29 and CAN_RAW=1.
And now i have to bind the socket to the hardware address, but i don't know how?

Code: Pascal  [Select][+][-]
  1. class procedure TSysBus.OpenSocket;
  2. var
  3.   s:Tsocket;
  4.   sa:TSockAddr;
  5. begin
  6.      s:=fpsocket(29, SOCK_RAW, 1);
  7.      sa.sa_family:=29;
  8.      sa.sa_data[0]:=???;
  9.      fpbind(s,@sa,SizeOf(sa));
  10.      FpClose(s);
  11. end;
  12.  

Can somebody give me an example, how i have to go on?
Thanks
Title: Re: CAN-BUS SockectCAN
Post by: jcdammeyer on August 21, 2020, 05:00:22 am
Anyone been able to create the equivalent of a simple the socketCAN utilities  candump using Lazarus
Code: Text  [Select][+][-]
  1. debian@ebb:~$ sudo /sbin/ip link set can1 up type can bitrate 250000
  2. debian@ebb:~$ candump can1
  3.   can1  721   [1]  05
  4.   can1  1A1   [8]  20 00 FF 0F A8 FD A8 FD
  5.  

No one answered RM and rampinia didn't post any other solutions.

Code: Pascal  [Select][+][-]
  1. procedure TSocketForm.Button1Click(Sender: TObject);
  2. var
  3.     i : integer;
  4. begin
  5.   // open socket
  6.   socket_result := fpsocket(PF_CAN, SOCK_RAW, CAN_RAW);
  7.   if (socket_result < 0) then begin
  8.         // perror("socket");
  9.     Edit1.text := 'Error #' + IntToStr(socket_result) + ' creating socket';
  10.   end
  11.   else begin
  12.     SAddr.sin_family := PF_CAN;
  13.     if fpconnect(socket_result, @SAddr, 0) = -1 then begin
  14.       Edit1.text := 'Socket can''t connect: ' + strerror(socketerror);
  15.     end;
  16.   end;
  17. end;
  18.  

The error is 'Operation not supported on Endpoint'

The C language candump doesn't use fpconnect() and the 'connect()' is deprecated and doesn't work either.  So although this is the document for fpconnect it uses deprecated functions rather than fpconnect().

https://www.freepascal.org/docs-html/current/rtl/sockets/fpconnect.html (https://www.freepascal.org/docs-html/current/rtl/sockets/fpconnect.html)

Plus it's more targeted at internet protocol sockets.

Ideas?

Title: Re: CAN-BUS SockectCAN
Post by: trev on August 21, 2020, 05:17:22 am
What about this (http://www.cananalyser.co.uk/index.html). The Windows/Linux SDK for Delphi is free.
Title: Re: CAN-BUS SockectCAN
Post by: jcdammeyer on August 23, 2020, 09:55:24 am
What about this (http://www.cananalyser.co.uk/index.html). The Windows/Linux SDK for Delphi is free.
Unfortunately from what I can see it doesn't address socketcan.

What I've found out so far is that socketcan and the utilities like candump work with the USB based CANUSB from Lawicel along with the internal BeagleBone Black CAN device and on a Pi, an SPI based MCP2515.

Further research shows that as simple as including 'can' in python programs brings in support for either the BBB or Pi. 

This is what I want to see for Lazarus.  I'd like to be able to plug in any device that has socketCAN support and have the application compile on that platform, or cross compile for that platform and just plain work.

What I've discovered is that this doesn't work for Lazarus yet.   So I need to find out where the sockets source code lives for the Pi and the Beagle and figure out why the fpconnect() returns an error.  Clearly it's broken or not properly documented.
Title: Re: CAN-BUS SockectCAN
Post by: Laksen on August 23, 2020, 11:10:19 am
Why are you calling connect and not bind?
TinyPortal © 2005-2018