Recent

Author Topic: CAN-BUS SockectCAN  (Read 3282 times)

MarkMLl

  • Hero Member
  • *****
  • Posts: 1451
Re: CAN-BUS SockectCAN
« Reply #15 on: October 22, 2020, 01:29:16 pm »
Code: Pascal  [Select][+][-]
  1.     if fpconnect(socket_result, @SAddr, 0) = -1 then begin
  2.  

Why the third parameter of fpconnect is zero?

Well spotted ;-)

For that matter, I have a lot of trouble tying https://www.freepascal.org/docs-html/rtl/sockets/fpconnect.html to anything remotely relevant.

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

jcdammeyer

  • Jr. Member
  • **
  • Posts: 85
  • Embedded System Developer
    • Automation Artisans Inc.
Re: CAN-BUS SockectCAN
« Reply #16 on: October 22, 2020, 07:06:19 pm »
So in general I get the feeling that to add socketCAN support to FPC will require a fairly extensive modification of the base sockets library.
PF_CAN is just a number. In linux sources you can find it defined as AF_CAN, which is defined as 29. So why don't you try that first?

EDIT: I see now that you are looking at sources of candump. It will be much easier if you use simpler example from here:
https://www.beyondlogic.org/example-c-socketcan-code/

True.  And in my example I assigned 29 to PF_CAN.  The beyondlogic example in C translated to pascal still suffers from the same issue that it's not handled in the socket library.  Thank you for that link.  It does simplify the code.  The candump.c has become more complicated with CAN_FD support which I'm not interested in looking at right now.  Especially since it's not supported by the MCP2515 and the BeagleBone internal CAN device nor many of the other existing CANopen modules out there.

I don't really want to add what appears to be an extra layer with TCP if I don't have to.  I'll download and compile socketcand to see if it fits in with what I want to do.

BTW, under winsock2.pp 29 is allocated to
Code: Pascal  [Select][+][-]
  1.   AF_TCNPROCESS   = 29;
  2.   AF_TCNMESSAGE   = 30;
  3.   AF_ICLFXBM      = 31;
  4.  
  5.   AF_MAX          = 32;
  6.  

My goal is to make something that runs on Windows, Pi and BeagleBones and other small modules running Linux.  Even LinuxCNC.  Not that concerned about Linux Desktop PCs.  The PC doesn't have the SPI or embedded CAN device so the CANUSB from Lawicel (or equivalent module with identical protocol) is what I'm currently targeting.


jcdammeyer

  • Jr. Member
  • **
  • Posts: 85
  • Embedded System Developer
    • Automation Artisans Inc.
Re: CAN-BUS SockectCAN
« Reply #17 on: October 22, 2020, 07:08:55 pm »
Code: Pascal  [Select][+][-]
  1.     if fpconnect(socket_result, @SAddr, 0) = -1 then begin
  2.  

Why the third parameter of fpconnect is zero?

Well spotted ;-)

For that matter, I have a lot of trouble tying https://www.freepascal.org/docs-html/rtl/sockets/fpconnect.html to anything remotely relevant.

MarkMLl
Because I never got past the socket call and had not used bind which is what should be used.  Wasn't even worried about fpconnect or the Saddr once I dove down into the socket library and saw that AF_CAN  or PF_CAN equal to 29 was not supported which essentially means the socketCAN library working in C or Python also won't work.

jcdammeyer

  • Jr. Member
  • **
  • Posts: 85
  • Embedded System Developer
    • Automation Artisans Inc.
Re: CAN-BUS SockectCAN
« Reply #18 on: October 22, 2020, 07:25:05 pm »
Code: Pascal  [Select][+][-]
  1.     if fpconnect(socket_result, @SAddr, 0) = -1 then begin
  2.  

Why the third parameter of fpconnect is zero?
Awe Crap!  That's what I get for leaving a project for 2 months and then jumping back in not remembering where I stopped.  In fact both you and Mark are correct that I'm using fpconnect incorrectly.
My mistake is that I though I didn't make it past the socket call which I do and returns 11 and not a value < 0. 

OK.  Some steps backwards and then I'll report what I've discovered.  Sheesh. Newbie type mistake...

 

TinyPortal © 2005-2018