- Posts: 210
- Thank you received: 15
(SOLVED - maybe) How to get an underscore in a pin/parameter name?
- ozzyrob
- Visitor
-
8 years 4 months ago #112341
by ozzyrob
Replied by ozzyrob on topic How to get an underscore in a pin/parameter name?
Using the section [MYBOARD]
and commenting & uncommenting the lines below would give you a two line change.
But I honestly think the whole underscore to dash thing is something internal, maybe the underscore has a special meaning within some data structures that Linuxcnc keeps.
Even when you use the command halcompile --preprocess hm2_7i76e.comp and have a look at the c source
You will find a line such as:
comp_id = hal_init("hm2_7i76e");
But somewhere internally that string is being changed for referencing pins.
and commenting & uncommenting the lines below would give you a two line change.
But I honestly think the whole underscore to dash thing is something internal, maybe the underscore has a special meaning within some data structures that Linuxcnc keeps.
Even when you use the command halcompile --preprocess hm2_7i76e.comp and have a look at the c source
You will find a line such as:
comp_id = hal_init("hm2_7i76e");
But somewhere internally that string is being changed for referencing pins.
Please Log in or Create an account to join the conversation.
- ozzyrob
- Visitor
-
8 years 4 months ago #112342
by ozzyrob
Replied by ozzyrob on topic How to get an underscore in a pin/parameter name?
If you want to do it your way, this is an example I tried with the supply.c code copying it to supply_2.c and changing all references to supply to supply_2.
rmurphy@stretch-cnc:~/linuxcnc-dev/src/hal/components$ halrun
halcmd: loadrt supply_2
Note: Using POSIX realtime
halcmd: show pin
Component Pins:
Owner Type Dir Value Name
6 bit OUT TRUE supply_2.0._q
6 float OUT 0 supply_2.0._variable
6 bit I/O FALSE supply_2.0.d
6 bit OUT FALSE supply_2.0.q
6 s32 OUT 0 supply_2.0.update.time
6 float I/O 0 supply_2.0.value
6 float OUT 0 supply_2.0.variable
halcmd:
I can't say for certain what affect it would have if used in a machine hal.
I would appear to unload by way of unloadrt supply_2
Code:
/********************************************************************
* Description: supply_2.c
* This file, 'supply_2.c', is a HAL component supply_2ing
* HAL pins preset to useful values like TRUE and 1.0.
*
* Author: Matt Shaver
* License: GPL Version 2
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
********************************************************************/
/** This file, 'supply_2.c', is a HAL component supply_2ing HAL pins preset
to useful values like TRUE and 1.0. I expect that it will mostly
be used for testing. It is a realtime component.
*/
/** Copyright (C) 2004 Matt Shaver
<mshaver AT users DOT sourceforge DOT net>
*/
/** This program is free software; you can redistribute it and/or
modify it under the terms of version 2 of the GNU General
Public License as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
THE AUTHORS OF THIS LIBRARY ACCEPT ABSOLUTELY NO LIABILITY FOR
ANY HARM OR LOSS RESULTING FROM ITS USE. IT IS _EXTREMELY_ UNWISE
TO RELY ON SOFTWARE ALONE FOR SAFETY. Any machinery capable of
harming persons must have provisions for completely removing power
from all motors, etc, before persons enter any danger area. All
machinery must be designed to comply with local and national safety
codes, and the authors of this software can not, and do not, take
any responsibility for such compliance.
This code was written as part of the EMC HAL project. For more
information, go to www.linuxcnc.org.
*/
#include "rtapi.h" /* RTAPI realtime OS API */
#include "rtapi_app.h" /* RTAPI realtime module decls */
#include "hal.h" /* HAL public API decls */
/* module information */
MODULE_AUTHOR("Matt Shaver");
MODULE_DESCRIPTION("supply_2 Component for EMC HAL");
MODULE_LICENSE("GPL");
static int num_chan = 1; /* number of channels - default = 1 */
RTAPI_MP_INT(num_chan, "number of channels");
/***********************************************************************
* STRUCTURES AND GLOBAL VARIABLES *
************************************************************************/
/** This structure contains the runtime data.
*/
typedef struct {
hal_bit_t *q; /* pin: q output of simulated flip-flop */
hal_bit_t *_q; /* pin: /q output of simulated flip-flop */
hal_float_t *variable; /* pin: output set by param "value" */
hal_float_t *_variable; /* pin: output set by param "value" * -1.0 */
hal_bit_t *d; /* pin: d input to simulated flip-flop */
hal_float_t *value; /* pin: value of float pin "variable" */
} hal_supply_2_t;
/* pointer to supply_2_t struct */
static hal_supply_2_t *supply_2_array;
/* other globals */
static int comp_id; /* component ID */
/***********************************************************************
* LOCAL FUNCTION DECLARATIONS *
************************************************************************/
static int export_supply_2(int num, hal_supply_2_t * addr);
static void update_supply_2(void *arg, long l);
/***********************************************************************
* INIT AND EXIT CODE *
************************************************************************/
#define MAX_CHAN 16
int rtapi_app_main(void)
{
int n, retval;
/* test for number of channels */
if ((num_chan <= 0) || (num_chan > MAX_CHAN)) {
rtapi_print_msg(RTAPI_MSG_ERR,
"supply_2: ERROR: invalid num_chan: %d\n", num_chan);
return -1;
}
/* have good config info, connect to the HAL */
comp_id = hal_init("supply_2");
if (comp_id < 0) {
rtapi_print_msg(RTAPI_MSG_ERR, "supply_2: ERROR: hal_init() failed\n");
return -1;
}
/* allocate shared memory for supply_2 data */
supply_2_array = hal_malloc(num_chan * sizeof(hal_supply_2_t));
if (supply_2_array == 0) {
rtapi_print_msg(RTAPI_MSG_ERR,
"supply_2: ERROR: hal_malloc() failed\n");
hal_exit(comp_id);
return -1;
}
/* export variables and functions for each supply_2 */
for (n = 0; n < num_chan; n++) {
retval = export_supply_2(n, &(supply_2_array[n]));
if (retval != 0) {
rtapi_print_msg(RTAPI_MSG_ERR,
"supply_2: ERROR: var export failed\n");
hal_exit(comp_id);
return -1;
}
}
rtapi_print_msg(RTAPI_MSG_INFO, "supply_2:installed %d supplies\n",
num_chan);
hal_ready(comp_id);
return 0;
}
void rtapi_app_exit(void)
{
hal_exit(comp_id);
}
/***********************************************************************
* REALTIME FUNCTIONS *
************************************************************************/
static void update_supply_2(void *arg, long l)
{
hal_supply_2_t *supply_2;
/* point to the data */
supply_2 = arg;
/* set pin = param */
*(supply_2->q) = *(supply_2->d);
*(supply_2->_q) = !(*(supply_2->d));
*(supply_2->variable) = *(supply_2->value);
*(supply_2->_variable) = *(supply_2->value) * -1.0;
/* done */
}
/***********************************************************************
* LOCAL FUNCTION DEFINITIONS *
************************************************************************/
static int export_supply_2(int num, hal_supply_2_t * addr)
{
int retval;
char buf[HAL_NAME_LEN + 1];
/* export pins */
retval = hal_pin_bit_newf(HAL_OUT, &(addr->q), comp_id, "supply_2.%d.q", num);
if (retval != 0) {
return retval;
}
retval = hal_pin_bit_newf(HAL_OUT, &(addr->_q), comp_id, "supply_2.%d._q", num);
if (retval != 0) {
return retval;
}
retval = hal_pin_float_newf(HAL_OUT, &(addr->variable), comp_id,"supply_2.%d.variable", num);
if (retval != 0) {
return retval;
}
retval = hal_pin_float_newf(HAL_OUT, &(addr->_variable), comp_id, "supply_2.%d._variable", num);
if (retval != 0) {
return retval;
}
/* export parameters */
retval = hal_pin_bit_newf(HAL_IO, &(addr->d), comp_id, "supply_2.%d.d", num);
if (retval != 0) {
return retval;
}
retval = hal_pin_float_newf(HAL_IO, &(addr->value), comp_id, "supply_2.%d.value", num);
if (retval != 0) {
return retval;
}
/* init all structure members */
*(addr->q) = 0;
*(addr->_q) = 1;
*(addr->variable) = 0.0;
*(addr->_variable) = 0.0;
*(addr->d) = 0;
*(addr->value) = 0.0;
/* export function for this loop */
rtapi_snprintf(buf, sizeof(buf), "supply_2.%d.update", num);
retval =
hal_export_funct(buf, update_supply_2, &(supply_2_array[num]), 1, 0,
comp_id);
if (retval != 0) {
rtapi_print_msg(RTAPI_MSG_ERR,
"supply_2: ERROR: update funct export failed\n");
hal_exit(comp_id);
return -1;
}
return 0;
}
rmurphy@stretch-cnc:~/linuxcnc-dev/src/hal/components$ halrun
halcmd: loadrt supply_2
Note: Using POSIX realtime
halcmd: show pin
Component Pins:
Owner Type Dir Value Name
6 bit OUT TRUE supply_2.0._q
6 float OUT 0 supply_2.0._variable
6 bit I/O FALSE supply_2.0.d
6 bit OUT FALSE supply_2.0.q
6 s32 OUT 0 supply_2.0.update.time
6 float I/O 0 supply_2.0.value
6 float OUT 0 supply_2.0.variable
halcmd:
I can't say for certain what affect it would have if used in a machine hal.
I would appear to unload by way of unloadrt supply_2
Please Log in or Create an account to join the conversation.
- Sparky961
- Offline
- Elite Member
-
Less
More
8 years 4 months ago - 8 years 4 months ago #112343
by Sparky961
Replied by Sparky961 on topic How to get an underscore in a pin/parameter name?
Your comment about using the --preprocess option got me thinking that if I do that, then I should be able to modify the C source to change the dash back to an underscore. Then it should compile and install as it's supposed to using the --install option on the .C file.
From the generated hm2_7i76e.c :
I changed the quoted string "watchdog.timeout-ns" to "watchdog.timeout_ns".
Using the code from my first post in this thread, all went well. Except I'm getting similar behaviour as when I tried building another component. I suspect something else is wrong with the way it's builiding but have no idea what to start with.
From the generated hm2_7i76e.c :
Code:
r = hal_param_s32_newf(HAL_RO, &(inst->watchdog_timeout_ns), comp_id,
"%s.watchdog.timeout_ns", prefix);
I changed the quoted string "watchdog.timeout-ns" to "watchdog.timeout_ns".
Using the code from my first post in this thread, all went well. Except I'm getting similar behaviour as when I tried building another component. I suspect something else is wrong with the way it's builiding but have no idea what to start with.
Code:
linuxcnc@debian:~$ halrun
halcmd: loadrt hm2_7i76e
Waiting for component 'hm2_7i76e' to become ready...Waited 3 seconds for master. giving up.
.Note: Using POSIX realtime
Last edit: 8 years 4 months ago by Sparky961.
Please Log in or Create an account to join the conversation.
- ozzyrob
- Visitor
-
8 years 4 months ago - 8 years 4 months ago #112344
by ozzyrob
Replied by ozzyrob on topic How to get an underscore in a pin/parameter name?
I'd be putting my wager on the coder doing something wrong rather than the compiler doing something wrong.
Make sure that all the component names in the file match the source file name...I got the same behavior when I copied the supply.c src to supply_2.c and didn't change any reference to supply to supply_2.
But when is all said and done there is obviously a reason that an underscore is change to a dash, I'd keep to the way halcompile does things.
It honestly looks as if you are trying to make things over complicated by what can be fixed by a simple search and replace or using a section & variable in the ini & hal files.
This question would probably be better addressed via the developers list as there would be more knowledge regarding the how's and whys.
Could be a coding convention ?
Just cos a underscore can be used does not necessarily mean it should.
Make sure that all the component names in the file match the source file name...I got the same behavior when I copied the supply.c src to supply_2.c and didn't change any reference to supply to supply_2.
But when is all said and done there is obviously a reason that an underscore is change to a dash, I'd keep to the way halcompile does things.
It honestly looks as if you are trying to make things over complicated by what can be fixed by a simple search and replace or using a section & variable in the ini & hal files.
This question would probably be better addressed via the developers list as there would be more knowledge regarding the how's and whys.
Could be a coding convention ?
Just cos a underscore can be used does not necessarily mean it should.
Last edit: 8 years 4 months ago by ozzyrob.
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 #112360
by andypugh
Replied by andypugh on topic How to get an underscore in a pin/parameter name?
Create your component and then pre-process
Then edit the generated C file to have your pin names.
Then compile and install
Code:
halcompile --preprocess hm2_7i76e.comp
Then edit the generated C file to have your pin names.
Then compile and install
Code:
sudo halcompile --install hm2_7i76e.c
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 #112361
by andypugh
Replied by andypugh on topic How to get an underscore in a pin/parameter name?
But, on a typical LinuxCNC intallation you can simply change the [HOSTMOT2[BOARD string to be your hm2-7i76 module and edit the loadrt lines.
Please Log in or Create an account to join the conversation.
Time to create page: 1.721 seconds