- Posts: 210
- Thank you received: 15
(SOLVED - maybe) How to get an underscore in a pin/parameter name?
- Sparky961
- Offline
- Elite Member
-
Less
More
8 years 4 months ago - 8 years 4 months ago #112386
by Sparky961
Replied by Sparky961 on topic How to get an underscore in a pin/parameter name?
For the sake of completeness, I'll summarize the current issue.
I make a file, 'and5.comp' that's in the component generator language:
Then I run the following:
Ok, all seems well. Then I try to load it in HAL:
...ok, this also seems to be working fine.
Now when I try to do it in two steps:
Then only preprocess:
Results in hm2_7i76e.c being created as below:
Now I change only the dash in the name on line 56 to an underscore and try to compile the C file:
No nasty errors. Seems like it worked.
Now, as before, I try to load the component in HAL:
Well I'll be a ...... damn. I swear that wasn't happening last night. It would try to load and never succeed.
Seems I don't need help on this anymore for the time being. Unless I can reproduce the problem, it seems.
I make a file, 'and5.comp' that's in the component generator language:
Code:
component and5 "Five-input AND gate";
pin in bit in0;
pin in bit in1;
pin in bit in2;
pin in bit in3;
pin in bit in4;
pin out bit out;
function _ nofp;
license "GPL";
;;
FUNCTION(_) { out = in0 && in1 && in2 && in3 && in4; }
Then I run the following:
Code:
linuxcnc@debian:/usr/src/linuxcnc-dev/src/hal/components$ sudo halcompile --install and5.comp
[sudo] password for linuxcnc:
Compiling realtime and5.c
Linking and5.so
cp and5.so /usr/lib/linuxcnc/modules/
Ok, all seems well. Then I try to load it in HAL:
Code:
linuxcnc@debian:/usr/src/linuxcnc-dev/src/hal/components$ halrun
halcmd: loadrt and5
Note: Using POSIX realtime
halcmd: show
Loaded HAL Components:
ID Type Name PID State
6 RT and5 ready
4 User halcmd3948 3948 ready
Component Pins:
Owner Type Dir Value Name
6 bit IN FALSE and5.0.in0
6 bit IN FALSE and5.0.in1
6 bit IN FALSE and5.0.in2
6 bit IN FALSE and5.0.in3
6 bit IN FALSE and5.0.in4
6 bit OUT FALSE and5.0.out
6 s32 OUT 0 and5.0.time
<snip>
...ok, this also seems to be working fine.
Now when I try to do it in two steps:
Code:
component hm2_7i76e "Fake pins from 7i76e for testing without attached hardware";
param r s32 watchdog.timeout_ns = 5000000;
pin out bit out0;
pin in bit in0;
function _;
license "GPL";
;;
FUNCTION(_) {
}
Then only preprocess:
Code:
linuxcnc@debian:/usr/src/linuxcnc-dev/src/hal/components$ sudo halcompile --preprocess hm2_7i76e.comp
Results in hm2_7i76e.c being created as below:
Code:
/* Autogenerated by /usr/bin/halcompile on Thu Jun 14 20:12:52 2018 -- do not edit */
#include "rtapi.h"
#ifdef RTAPI
#include "rtapi_app.h"
#endif
#include "rtapi_string.h"
#include "rtapi_errno.h"
#include "hal.h"
#include "rtapi_math64.h"
static int comp_id;
#ifdef MODULE_INFO
MODULE_INFO(linuxcnc, "component:hm2_7i76e:Fake pins from 7i76e for testing without attached hardware");
MODULE_INFO(linuxcnc, "param:watchdog.timeout_ns:s32:0:r::5000000:None");
MODULE_INFO(linuxcnc, "pin:out0:bit:0:out::None:None");
MODULE_INFO(linuxcnc, "pin:in0:bit:0:in::None:None");
MODULE_INFO(linuxcnc, "funct:_:1:");
MODULE_INFO(linuxcnc, "license:GPL");
MODULE_LICENSE("GPL");
#endif // MODULE_INFO
struct __comp_state {
struct __comp_state *_next;
hal_bit_t *out0;
hal_bit_t *in0;
hal_s32_t watchdog_timeout_ns;
};
struct __comp_state *__comp_first_inst=0, *__comp_last_inst=0;
static void _(struct __comp_state *__comp_inst, long period);
static int __comp_get_data_size(void);
#undef TRUE
#define TRUE (1)
#undef FALSE
#define FALSE (0)
#undef true
#define true (1)
#undef false
#define false (0)
static int export(char *prefix, long extra_arg) {
char buf[HAL_NAME_LEN + 1];
int r = 0;
int sz = sizeof(struct __comp_state) + __comp_get_data_size();
struct __comp_state *inst = hal_malloc(sz);
memset(inst, 0, sz);
r = hal_pin_bit_newf(HAL_OUT, &(inst->out0), comp_id,
"%s.out0", prefix);
if(r != 0) return r;
r = hal_pin_bit_newf(HAL_IN, &(inst->in0), comp_id,
"%s.in0", prefix);
if(r != 0) return r;
r = hal_param_s32_newf(HAL_RO, &(inst->watchdog_timeout_ns), comp_id,
"%s.watchdog.timeout-ns", prefix);
inst->watchdog_timeout_ns = 5000000;
if(r != 0) return r;
rtapi_snprintf(buf, sizeof(buf), "%s", prefix);
r = hal_export_funct(buf, (void(*)(void *inst, long))_, inst, 1, 0, comp_id);
if(r != 0) return r;
if(__comp_last_inst) __comp_last_inst->_next = inst;
__comp_last_inst = inst;
if(!__comp_first_inst) __comp_first_inst = inst;
return 0;
}
static int default_count=1, count=0;
char *names[16] = {0,};
RTAPI_MP_INT(count, "number of hm2_7i76e");
RTAPI_MP_ARRAY_STRING(names, 16, "names of hm2_7i76e");
int rtapi_app_main(void) {
int r = 0;
int i;
comp_id = hal_init("hm2_7i76e");
if(comp_id < 0) return comp_id;
if(count && names[0]) {
rtapi_print_msg(RTAPI_MSG_ERR,"count= and names= are mutually exclusive\n");
return -EINVAL;
}
if(!count && !names[0]) count = default_count;
if(count) {
for(i=0; i<count; i++) {
char buf[HAL_NAME_LEN + 1];
rtapi_snprintf(buf, sizeof(buf), "hm2-7i76e.%d", i);
r = export(buf, i);
if(r != 0) break;
}
} else {
int max_names = sizeof(names)/sizeof(names[0]);
for(i=0; (i < max_names) && names[i]; i++) {
if (strlen(names[i]) < 1) {
rtapi_print_msg(RTAPI_MSG_ERR, "names[%d] is invalid (empty string)\n", i);
r = -EINVAL;
break;
}
r = export(names[i], i);
if(r != 0) break;
}
}
if(r) {
hal_exit(comp_id);
} else {
hal_ready(comp_id);
}
return r;
}
void rtapi_app_exit(void) {
hal_exit(comp_id);
}
#undef FUNCTION
#define FUNCTION(name) static void name(struct __comp_state *__comp_inst, long period)
#undef EXTRA_SETUP
#define EXTRA_SETUP() static int extra_setup(struct __comp_state *__comp_inst, char *prefix, long extra_arg)
#undef EXTRA_CLEANUP
#define EXTRA_CLEANUP() static void extra_cleanup(void)
#undef fperiod
#define fperiod (period * 1e-9)
#undef out0
#define out0 (*__comp_inst->out0)
#undef in0
#define in0 (0+*__comp_inst->in0)
#undef watchdog_timeout_ns
#define watchdog_timeout_ns (__comp_inst->watchdog_timeout_ns)
#line 8 "hm2_7i76e.comp"
FUNCTION(_) {
}
static int __comp_get_data_size(void) { return 0; }
Now I change only the dash in the name on line 56 to an underscore and try to compile the C file:
Code:
linuxcnc@debian:/usr/src/linuxcnc-dev/src/hal/components$ sudo halcompile --install hm2_7i76e.c
Compiling realtime hm2_7i76e.c
Linking hm2_7i76e.so
cp hm2_7i76e.so /usr/lib/linuxcnc/modules/
No nasty errors. Seems like it worked.
Now, as before, I try to load the component in HAL:
Well I'll be a ...... damn. I swear that wasn't happening last night. It would try to load and never succeed.
Code:
linuxcnc@debian:/usr/src/linuxcnc-dev/src/hal/components$ halrun
halcmd: loadrt hm2_7i76e
Note: Using POSIX realtime
halcmd: show
Loaded HAL Components:
ID Type Name PID State
6 RT hm2_7i76e ready
4 User halcmd4023 4023 ready
Component Pins:
Owner Type Dir Value Name
6 bit IN FALSE hm2-7i76e.0.in0
6 bit OUT FALSE hm2-7i76e.0.out0
6 s32 OUT 0 hm2-7i76e.0.time
Pin Aliases:
Alias Original Name
Signals:
Type Value Name (linked to)
Parameters:
Owner Type Dir Value Name
6 s32 RW 0 hm2-7i76e.0.tmax
6 bit RO FALSE hm2-7i76e.0.tmax-increased
6 s32 RO 5000000 hm2-7i76e.0.watchdog.timeout_ns
Seems I don't need help on this anymore for the time being. Unless I can reproduce the problem, it seems.
Last edit: 8 years 4 months ago by Sparky961. Reason: Missed word...
Please Log in or Create an account to join the conversation.
- ozzyrob
- Visitor
-
8 years 4 months ago #112387
by ozzyrob
Replied by ozzyrob on topic How to get an underscore in a pin/parameter name?
Apparently you can use any string for indicated in red:
r = hal_param_s32_newf(HAL_RO, &(inst->watchdog_timeout_ns), comp_id,
"%s.watchdog.timeout-ns", prefix);
As seen here in blue:
r = hal_param_s32_newf(HAL_RO, &(inst->watchdog_timeout_ns), comp_id,
"%s.foofoo.dog_woof", prefix);
halcmd: loadrt hm2_7i76e
Note: Using POSIX realtime
halcmd: show
Loaded HAL Components:
ID Type Name PID State
6 RT hm2_7i76e ready
4 User halcmd9484 9484 ready
Component Pins:
Owner Type Dir Value Name
6 bit IN FALSE hm2-7i76e.0.in0
6 bit OUT FALSE hm2-7i76e.0.out0
6 s32 OUT 0 hm2-7i76e.0.time
Pin Aliases:
Alias Original Name
Signals:
Type Value Name (linked to)
Parameters:
Owner Type Dir Value Name
6 s32 RO 5000000 hm2-7i76e.0.foofoo.dog_woof
6 s32 RW 0 hm2-7i76e.0.tmax
6 bit RO FALSE hm2-7i76e.0.tmax-increased
Parameter Aliases:
Alias Original Name
Exported Functions:
Owner CodeAddr Arg FP Users Name
00006 7f158155bcb0 7f1582d640d8 YES 0 hm2-7i76e.0
Realtime Threads:
Period FP Name ( Time, Max-Time )
halcmd: quit
Note: Using POSIX realtime
r = hal_param_s32_newf(HAL_RO, &(inst->watchdog_timeout_ns), comp_id,
"%s.watchdog.timeout-ns", prefix);
As seen here in blue:
r = hal_param_s32_newf(HAL_RO, &(inst->watchdog_timeout_ns), comp_id,
"%s.foofoo.dog_woof", prefix);
halcmd: loadrt hm2_7i76e
Note: Using POSIX realtime
halcmd: show
Loaded HAL Components:
ID Type Name PID State
6 RT hm2_7i76e ready
4 User halcmd9484 9484 ready
Component Pins:
Owner Type Dir Value Name
6 bit IN FALSE hm2-7i76e.0.in0
6 bit OUT FALSE hm2-7i76e.0.out0
6 s32 OUT 0 hm2-7i76e.0.time
Pin Aliases:
Alias Original Name
Signals:
Type Value Name (linked to)
Parameters:
Owner Type Dir Value Name
6 s32 RO 5000000 hm2-7i76e.0.foofoo.dog_woof
6 s32 RW 0 hm2-7i76e.0.tmax
6 bit RO FALSE hm2-7i76e.0.tmax-increased
Parameter Aliases:
Alias Original Name
Exported Functions:
Owner CodeAddr Arg FP Users Name
00006 7f158155bcb0 7f1582d640d8 YES 0 hm2-7i76e.0
Realtime Threads:
Period FP Name ( Time, Max-Time )
halcmd: quit
Note: Using POSIX realtime
Please Log in or Create an account to join the conversation.
- andypugh
- Offline
- Moderator
-
Less
More
- Posts: 19899
- Thank you received: 4655
8 years 4 months ago #112394
by andypugh
Replied by andypugh on topic How to get an underscore in a pin/parameter name?
Do you want pins "hm2_7i76" or "hm2-7i76" ?
The real HAL file with the real 7i76 will have "hm2_7i76" (maybe hm2_7i76e" I haven't seen one)
The real HAL file with the real 7i76 will have "hm2_7i76" (maybe hm2_7i76e" I haven't seen one)
Please Log in or Create an account to join the conversation.
- Sparky961
- Offline
- Elite Member
-
Less
More
- Posts: 210
- Thank you received: 15
8 years 4 months ago #112395
by Sparky961
Yes, you're right. I was so focused on the one I didn't see the other.
Replied by Sparky961 on topic How to get an underscore in a pin/parameter name?
andypugh wrote: Do you want pins "hm2_7i76" or "hm2-7i76" ?
The real HAL file with the real 7i76 will have "hm2_7i76" (maybe hm2_7i76e" I haven't seen one)
Yes, you're right. I was so focused on the one I didn't see the other.
Please Log in or Create an account to join the conversation.
Time to create page: 1.492 seconds