How to pass parameters .comp file

More
1 year 6 months ago #326225 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 to join the conversation.

More
1 year 6 months ago #326234 by rodw
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

Please Log in to join the conversation.

More
1 year 6 months ago #326310 by dinodf
I know it, thanks, my problem is upstream  I can't find where it is explained how to pass the parameters 
 

Please Log in to join the conversation.

More
1 year 6 months ago #326339 by rodw
This example in the docs is similar to what you want
linuxcnc.org/docs/stable/html/hal/comp.html#_out8

Please Log in to join the conversation.

More
1 year 6 months ago #326416 by dinodf
Thanks a lot!
If someone need it the code is: 
Code:
#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 to join the conversation.

More
1 year 6 months ago #326708 by rodw
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:
Code:
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

Please Log in to join the conversation.

Time to create page: 0.142 seconds
Powered by Kunena Forum