How to pass parameters .comp file

More
13 Apr 2025 17:05 #326225 by dinodf
How to pass parameters .comp file was created by dinodf
Hello,
I am developing a driver to connect a device to linuxcnc via ethernet, I would like to pass the IP address as a parameter but I can't find the correct way to read the parameters in the EXTRA_SETUP() function of the .comp file, the driver is a realtime object

Can help me?
Thanks
 

Please Log in or Create an account to join the conversation.

More
13 Apr 2025 22:03 #326234 by rodw
Replied by rodw on topic How to pass parameters .comp file
The IP address is a 32 bit number internally, so you should be able to pass it as an unsigned long parameter. you would need to convert 192.168.1.1 to 4 bytes in hex, then use setp
The following user(s) said Thank You: dinodf

Please Log in or Create an account to join the conversation.

More
14 Apr 2025 19:26 #326310 by dinodf
Replied by dinodf on topic How to pass parameters .comp file
I know it, thanks, my problem is upstream  I can't find where it is explained how to pass the parameters 
 

Please Log in or Create an account to join the conversation.

More
15 Apr 2025 05:14 #326339 by rodw
Replied by rodw on topic How to pass parameters .comp file
This example in the docs is similar to what you want
linuxcnc.org/docs/stable/html/hal/comp.html#_out8
The following user(s) said Thank You: dinodf

Please Log in or Create an account to join the conversation.

More
16 Apr 2025 00:11 #326416 by dinodf
Replied by dinodf on topic How to pass parameters .comp file
Thanks a lot!
If someone need it the code is: 
#define DEFAULT_REMOTE_IP "10.0.0.40"

// read parameter
static char *IPv4[20];
RTAPI_MP_ARRAY_STRING(IPv4, 16, "IPv4 to send infos")

EXTRA_SETUP() {
  struct sockaddr_in addr;
  
  // check parameters
  if (IPv4[extra_arg] == NULL) {
    rtapi_print_msg(RTAPI_MSG_ERR, "You have not set the IPv4 where send the data, will be send to %s", DEFAULT_REMOTE_IP);
    strcpy(ipDest, DEFAULT_REMOTE_IP);
  } else {
    strcpy(ipDest, IPv4[extra_arg]);
  }
  ...
}

rtapi_module_param

D

Please Log in or Create an account to join the conversation.

More
19 Apr 2025 13:26 - 19 Apr 2025 13:27 #326708 by rodw
Replied by rodw on topic How to pass parameters .comp file
I was thinking if you converted your ip address to hex using an online calculator like www.lambdatest.com/free-online-tools/ip-to-hex
10.0.0.40 = 0a.00.00.28 (0x0a000028) then you could have a parameter in your component add:
param r unsigned ipaddr;
server_addr = htonl(ipaddr);
Then in your hal file you could

setp mycomp.0.ipaddr 0x0a000028

and parse the value in the component to make your string (if that Is required)

There is more to the code  but you can fill it oit
Last edit: 19 Apr 2025 13:27 by rodw.
The following user(s) said Thank You: dinodf

Please Log in or Create an account to join the conversation.

Time to create page: 0.087 seconds
Powered by Kunena Forum