- LinuxCNC
- General LinuxCNC Questions
- (solve} int do_gets_cmd(QString) get bool receive .... HAL_TYPE_UNINITIALIZED
(solve} int do_gets_cmd(QString) get bool receive .... HAL_TYPE_UNINITIALIZED
- bkt
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 1199
- Thank you received: 103
01 Nov 2023 14:18 - 02 Nov 2023 22:47 #284261
by bkt
for no waste time .... if you try to reach these goal (run your gui app c++ on rt-preempt) need to copy ACTUAL installation file hal_priv.h in your project code .... in these way you can align shmem data with request/command from your app c++.
When you update Lcnc version, need to change that file on your project folder .... (and add to your heather file)
THESE IS THE RIGHT SOLUTION FOR ALL THESE POST OPEN BY ME IN LAST 5 DAYS:
forum.linuxcnc.org/41-guis/50520-int-set...ot-writable-or-not-e
forum.linuxcnc.org/10-advanced-configura...le-for-kins?start=20 (only last part of problem encountered pg.3)
SO: in linux mint 19.3 kernel 4.19 rt3 can run Lcnc2.10 pre0, linuxcnc 2.9.1 whitout problem ( for version 2.10 you need some tricks to cheat the dependencies... for example not installing the docs, and installing and reinstalling the yapps2 package during the installation process of the 2 necessary .deb packages.... in addition you need to install libmodbus 3.1. 6 with make, in order to have a documentation package required by 2.10.... in fact in libmodbus5.so the specific documentation package does not exist.)
############################################################################
why my signal return as HAL_TYPE_UNINITIALIZED? .... from these call .... thse after upgrate to 2.9.1 trought .deb package.
When you update Lcnc version, need to change that file on your project folder .... (and add to your heather file)
THESE IS THE RIGHT SOLUTION FOR ALL THESE POST OPEN BY ME IN LAST 5 DAYS:
forum.linuxcnc.org/41-guis/50520-int-set...ot-writable-or-not-e
forum.linuxcnc.org/10-advanced-configura...le-for-kins?start=20 (only last part of problem encountered pg.3)
SO: in linux mint 19.3 kernel 4.19 rt3 can run Lcnc2.10 pre0, linuxcnc 2.9.1 whitout problem ( for version 2.10 you need some tricks to cheat the dependencies... for example not installing the docs, and installing and reinstalling the yapps2 package during the installation process of the 2 necessary .deb packages.... in addition you need to install libmodbus 3.1. 6 with make, in order to have a documentation package required by 2.10.... in fact in libmodbus5.so the specific documentation package does not exist.)
############################################################################
why my signal return as HAL_TYPE_UNINITIALIZED? .... from these call .... thse after upgrate to 2.9.1 trought .deb package.
int do_gets_cmd(QString nameSig)
{
hal_sig_t *sig;
hal_type_t type;
void *d_ptr;
char *value_str = {};
static char buf[18];
std::string str_false = "FALSE";
std::string str_true = "TRUE";
std::string str_unknow = "unknown_type";
int valBIT = 0;
char name[strlen(nameSig.toStdString().c_str()) + 1]; // Make sure there's enough space
strcpy(name, nameSig.toStdString().c_str());
qDebug() << Q_FUNC_INFO << "get signal receive ...." << name;
/* get mutex before accessing shared data */
rtapi_mutex_get(&;(hal_data->mutex));
/* search signal list for name */
sig = halpr_find_sig_by_name(name);
if (sig == 0) {
rtapi_mutex_give(&;(hal_data->mutex));
//qDebug() << Q_FUNC_INFO << "get signal not find ...." << name;
valBIT = 10;
}
else{
//rtapi_mutex_get(&;(hal_data->mutex));
////qDebug() << Q_FUNC_INFO << "get signal FIND ...." << name;
type = sig->type;
//qDebug() << Q_FUNC_INFO << "get signal FIND .... VALID HAL_TYPE for sig :" << name << " , value....:" << type;
if(sig->writers > 0){
//qDebug() << Q_FUNC_INFO << "get bool receive .... case HAS WRITER" ;
d_ptr = SHMPTR(sig->data_ptr);
if(type == HAL_BIT){
if (*((hal_bit_t *) d_ptr) == 0){
// strcpy(value_str, str_false.c_str());
rtapi_mutex_give(&;(hal_data->mutex));
valBIT = 0;
//value_str = "FALSE";
////qDebug() << Q_FUNC_INFO << "get bool receive .... case HAL_BIT: " << valBIT;
}
else{
// strcpy(value_str, str_true.c_str());
rtapi_mutex_give(&;(hal_data->mutex));
valBIT = 1;
//value_str = "TRUE";
////qDebug() << Q_FUNC_INFO << "get bool receive .... case HAL_BIT: " << valBIT;
}
}
else if(type == HAL_FLOAT){
snprintf(buf, 16, "%.7g", (double)*((hal_float_t *) d_ptr));
rtapi_mutex_give(&;(hal_data->mutex));
value_str = buf;
qDebug() << Q_FUNC_INFO << "get bool receive .... case HAL_FLOAT" ;
}
else if(type == HAL_S32){
snprintf(buf, 16, "%ld", (long)*((hal_s32_t *) d_ptr));
rtapi_mutex_give(&;(hal_data->mutex));
value_str = buf;
qDebug() << Q_FUNC_INFO << "get bool receive .... case HAL_S32" ;
}
else if(type == HAL_U32){
snprintf(buf, 16, "%ld", (unsigned long)*((hal_u32_t *) d_ptr));
rtapi_mutex_give(&;(hal_data->mutex));
value_str = buf;
////qDebug() << Q_FUNC_INFO << "get bool receive .... case HAL_U32" ;
}
else if(type == HAL_PORT){
//snprintf(buf, 16, "%ld", (unsigned long)*((hal_u32_t *) d_ptr));
rtapi_mutex_give(&;(hal_data->mutex));
// value_str = buf;
qDebug() << Q_FUNC_INFO << "get bool receive .... case HAL_PORT" ;
}
else if(type == HAL_TYPE_UNINITIALIZED){
//snprintf(buf, 16, "%ld", (unsigned long)*((hal_u32_t *) d_ptr));
rtapi_mutex_give(&;(hal_data->mutex));
// value_str = buf;
qDebug() << Q_FUNC_INFO << "get bool receive .... HAL_TYPE_UNINITIALIZED" ;
}
else if(type == HAL_TYPE_UNSPECIFIED){
//snprintf(buf, 16, "%ld", (unsigned long)*((hal_u32_t *) d_ptr));
rtapi_mutex_give(&;(hal_data->mutex));
// value_str = buf;
qDebug() << Q_FUNC_INFO << "get bool receive .... case HAL_TYPE_UNSPECIFIED" ;
}
// case HAL_PORT:
// //snprintf(buf, 14, "%u", hal_port_buffer_size(*((hal_port_t*) valptr)));
// value_str = buf;
// break;
else{
/* Shouldn't get here, but just in case... */
qDebug() << Q_FUNC_INFO << "get signal FIND ....NO VALID HAL_TYPE for sig :" << name << " , value....:" << type;
strcpy(value_str, str_unknow.c_str());
valBIT = 10;
//value_str = "unknown_type";
// //qDebug() << Q_FUNC_INFO << "get bool receive .... case DEFAULT break" ;
}
//d_ptr = SHMOFF(sig->data_ptr);
rtapi_mutex_give(&;(hal_data->mutex));
}
else{
rtapi_mutex_give(&;(hal_data->mutex));
valBIT = 10;
////qDebug() << Q_FUNC_INFO << "get bool receive .... case HAS NOT WRITER" ;
}
qDebug() << Q_FUNC_INFO << "get signal SET TO ... but not return: " << valBIT;
//return valBIT;
// if(valBIT !=0){ return 0; //qDebug() << Q_FUNC_INFO << "get signal FIND ....SET TO 1 " << name;}
// else if(valBIT==0) {return 1; //qDebug() << Q_FUNC_INFO << "get signal FIND ....SET TO 0 " << name;}
// else {return 10; //qDebug() << Q_FUNC_INFO << "get signal FIND ....SET TO 10 NOT HAL BIT" << name;}
// if(strcmp(data,"TRUE")!=0){ return 0; //qDebug() << Q_FUNC_INFO << "get signal FIND ....SET TO 1 " << name;}
//else if(strcmp(data,"TRUE")==0) {return 1; //qDebug() << Q_FUNC_INFO << "get signal FIND ....SET TO 0 " << name;}
// else {return 10; //qDebug() << Q_FUNC_INFO << "get signal FIND ....SET TO 10 " << name;}
}
/* if(valBIT !=0){ return 0; //qDebug() << Q_FUNC_INFO << "get signal FIND ....SET TO 1 " << name;}
else if(valBIT==0) {return 1; //qDebug() << Q_FUNC_INFO << "get signal FIND ....SET TO 0 " << name;}
else {return 10; //qDebug() << Q_FUNC_INFO << "get signal FIND ....SET TO 10 NOT HAL BIT" << name;}*/
//qDebug() << Q_FUNC_INFO << "get signal SET TO ...: " << valBIT;
return valBIT;
qDebug() << Q_FUNC_INFO << "get signal SET TO ...: " << valBIT;
}
Last edit: 02 Nov 2023 22:47 by bkt.
Please Log in or Create an account to join the conversation.
- TheRoslyak
- Offline
- Elite Member
Less
More
- Posts: 238
- Thank you received: 37
01 Nov 2023 16:58 #284267
by TheRoslyak
Replied by TheRoslyak on topic int do_gets_cmd(QString) get bool receive .... HAL_TYPE_UNINITIALIZED
What is halpr_find_sig_by_name?
Please Log in or Create an account to join the conversation.
- bkt
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 1199
- Thank you received: 103
01 Nov 2023 20:26 - 01 Nov 2023 20:40 #284281
by bkt
Replied by bkt on topic int do_gets_cmd(QString) get bool receive .... HAL_TYPE_UNINITIALIZED
strct on hal_priv.h or hal.h ... not remeber exactly, for find signal struct data value by name ..... but same app, whitout modification, work on same pc (or same clone pc) from 4 years, now I need to use last kinematics features ... so upgrade my Lcnc .deb package istall ... and somethings is breack .... not understand where and why .... axis gui work on sim, and with lcec.so whithout problem .... my c++ app gui stop at these point because find signal "UNINIZIALIZED" (my app is a sort of halview or halshow new features on axis gui ... perhaps connect to opcua server or slave build on qt .... nothing to do with your project opcua .... real better and clean).
My app read and write, bit, s32, u32 and float into hal pin or signal, so you can easily have a all you need for make every gui type .... these is enought .... actuallly drive more or less 200 pin or signal with 50ms refresh rate .... qtimer new feature helps a lot beacause qt convert every void call from timer in a sort of qthread .... so no freezing or blocking and less use of memory and less coding.
not in my github .... but can post willingly a sample complete code project .
My app read and write, bit, s32, u32 and float into hal pin or signal, so you can easily have a all you need for make every gui type .... these is enought .... actuallly drive more or less 200 pin or signal with 50ms refresh rate .... qtimer new feature helps a lot beacause qt convert every void call from timer in a sort of qthread .... so no freezing or blocking and less use of memory and less coding.
not in my github .... but can post willingly a sample complete code project .
Last edit: 01 Nov 2023 20:40 by bkt.
Please Log in or Create an account to join the conversation.
- TheRoslyak
- Offline
- Elite Member
Less
More
- Posts: 238
- Thank you received: 37
01 Nov 2023 21:48 #284286
by TheRoslyak
Replied by TheRoslyak on topic int do_gets_cmd(QString) get bool receive .... HAL_TYPE_UNINITIALIZED
try this
int do_gets_cmd(QString nameSig) {
hal_sig_t *sig;
hal_type_t type;
void *d_ptr;
static char buf[18];
int valBIT = 10; // Default error value if signal not found or uninitialized
std::string value_str;
// Convert QString to C-style string
QByteArray nameByteArray = nameSig.toLocal8Bit();
const char *name = nameByteArray.data();
qDebug() << Q_FUNC_INFO << "get signal receive ...." << name;
// Get mutex before accessing shared data
rtapi_mutex_get(&(hal_data->mutex));
// Search signal list for name
sig = halpr_find_sig_by_name(name);
if (sig == NULL) {
rtapi_mutex_give(&(hal_data->mutex));
qDebug() << Q_FUNC_INFO << "get signal not find ...." << name;
return valBIT; // Signal not found
}
type = sig->type;
d_ptr = SHMPTR(sig->data_ptr);
// Process signal based on type
switch (type) {
case HAL_BIT:
valBIT = (*((hal_bit_t *)d_ptr) != 0);
break;
case HAL_FLOAT:
snprintf(buf, sizeof(buf), "%.7g", *((hal_float_t *)d_ptr));
value_str = buf;
qDebug() << Q_FUNC_INFO << "get float value ...." << value_str.c_str();
break;
case HAL_S32:
snprintf(buf, sizeof(buf), "%ld", (long)*((hal_s32_t *)d_ptr));
value_str = buf;
qDebug() << Q_FUNC_INFO << "get s32 value ...." << value_str.c_str();
break;
case HAL_U32:
snprintf(buf, sizeof(buf), "%lu", (unsigned long)*((hal_u32_t *)d_ptr));
value_str = buf;
qDebug() << Q_FUNC_INFO << "get u32 value ...." << value_str.c_str();
break;
case HAL_PORT:
// Handle port type if necessary
qDebug() << Q_FUNC_INFO << "get port value ....";
break;
case HAL_TYPE_UNINITIALIZED:
qDebug() << Q_FUNC_INFO << "signal type uninitialized";
break;
case HAL_TYPE_UNSPECIFIED:
// Handle unspecified type if necessary
qDebug() << Q_FUNC_INFO << "signal type unspecified";
break;
default:
// Unexpected type
qDebug() << Q_FUNC_INFO << "no valid HAL_TYPE for signal:" << name;
value_str = "unknown_type";
break;
}
// Release mutex
rtapi_mutex_give(&(hal_data->mutex));
qDebug() << Q_FUNC_INFO << "signal value set to:" << valBIT;
return valBIT; // Return the value of valBIT, default is 10 if uninitialized
}
int do_gets_cmd(QString nameSig) {
hal_sig_t *sig;
hal_type_t type;
void *d_ptr;
static char buf[18];
int valBIT = 10; // Default error value if signal not found or uninitialized
std::string value_str;
// Convert QString to C-style string
QByteArray nameByteArray = nameSig.toLocal8Bit();
const char *name = nameByteArray.data();
qDebug() << Q_FUNC_INFO << "get signal receive ...." << name;
// Get mutex before accessing shared data
rtapi_mutex_get(&(hal_data->mutex));
// Search signal list for name
sig = halpr_find_sig_by_name(name);
if (sig == NULL) {
rtapi_mutex_give(&(hal_data->mutex));
qDebug() << Q_FUNC_INFO << "get signal not find ...." << name;
return valBIT; // Signal not found
}
type = sig->type;
d_ptr = SHMPTR(sig->data_ptr);
// Process signal based on type
switch (type) {
case HAL_BIT:
valBIT = (*((hal_bit_t *)d_ptr) != 0);
break;
case HAL_FLOAT:
snprintf(buf, sizeof(buf), "%.7g", *((hal_float_t *)d_ptr));
value_str = buf;
qDebug() << Q_FUNC_INFO << "get float value ...." << value_str.c_str();
break;
case HAL_S32:
snprintf(buf, sizeof(buf), "%ld", (long)*((hal_s32_t *)d_ptr));
value_str = buf;
qDebug() << Q_FUNC_INFO << "get s32 value ...." << value_str.c_str();
break;
case HAL_U32:
snprintf(buf, sizeof(buf), "%lu", (unsigned long)*((hal_u32_t *)d_ptr));
value_str = buf;
qDebug() << Q_FUNC_INFO << "get u32 value ...." << value_str.c_str();
break;
case HAL_PORT:
// Handle port type if necessary
qDebug() << Q_FUNC_INFO << "get port value ....";
break;
case HAL_TYPE_UNINITIALIZED:
qDebug() << Q_FUNC_INFO << "signal type uninitialized";
break;
case HAL_TYPE_UNSPECIFIED:
// Handle unspecified type if necessary
qDebug() << Q_FUNC_INFO << "signal type unspecified";
break;
default:
// Unexpected type
qDebug() << Q_FUNC_INFO << "no valid HAL_TYPE for signal:" << name;
value_str = "unknown_type";
break;
}
// Release mutex
rtapi_mutex_give(&(hal_data->mutex));
qDebug() << Q_FUNC_INFO << "signal value set to:" << valBIT;
return valBIT; // Return the value of valBIT, default is 10 if uninitialized
}
Please Log in or Create an account to join the conversation.
- bkt
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 1199
- Thank you received: 103
01 Nov 2023 22:18 - 01 Nov 2023 22:19 #284291
by bkt
Replied by bkt on topic int do_gets_cmd(QString) get bool receive .... HAL_TYPE_UNINITIALIZED
problem is all 200 signal result uninizialized .... before now code work perfect for 4 years ..... yea is not a good code .... but was working.
Last edit: 01 Nov 2023 22:19 by bkt.
Please Log in or Create an account to join the conversation.
- TheRoslyak
- Offline
- Elite Member
Less
More
- Posts: 238
- Thank you received: 37
01 Nov 2023 22:45 - 01 Nov 2023 22:50 #284293
by TheRoslyak
Replied by TheRoslyak on topic int do_gets_cmd(QString) get bool receive .... HAL_TYPE_UNINITIALIZED
Try this. It might not be entirely correct here, but the approach is workable.
int do_gets_cmd(QString nameSig) {
hal_sig_t *sig;
void *data_ptr;
int result = -1; // Default error value if signal not found or uninitialized type
// Lock the mutex before accessing the shared data
rtapi_mutex_get(&(hal_data->mutex));
// Scan all signals
for (sig = SHMPTR(hal_data->sig_list_ptr); sig; sig = SHMPTR(sig->next_ptr)) {
// Compare current signal name with the desired one using QString
if (nameSig == QString::fromUtf8(sig->name)) {
// Found the signal with the desired name
data_ptr = SHMPTR(sig->data_ptr); // Get the data pointer of the signal
// Process signal based on its type
switch (sig->type) {
case HAL_FLOAT: {
double value = *(hal_float_t *)data_ptr;
// Use the value as needed
qDebug() << "HAL_FLOAT value: " << value;
result = 0; // Assuming 0 indicates success
break;
}
case HAL_BIT: {
bool value = *(hal_bit_t *)data_ptr;
// Use the value as needed
qDebug() << "HAL_BIT value: " << value;
result = 0; // Assuming 0 indicates success
break;
}
case HAL_U32: {
unsigned int value = *(hal_u32_t *)data_ptr;
// Use the value as needed
qDebug() << "HAL_U32 value: " << value;
result = 0; // Assuming 0 indicates success
break;
}
case HAL_S32: {
int value = *(hal_s32_t *)data_ptr;
// Use the value as needed
qDebug() << "HAL_S32 value: " << value;
result = 0; // Assuming 0 indicates success
break;
}
// Add other cases for different HAL types as needed
default:
qDebug() << Q_FUNC_INFO << "Unknown or uninitialized HAL type for signal:" << nameSig;
result = -1; // Signal type is unknown or uninitialized
break;
}
break; // Break the loop since we found the signal
}
}
// Release the mutex
rtapi_mutex_give(&(hal_data->mutex));
return result; // Return the result, which is 0 on success or -1 on failure
}
Last edit: 01 Nov 2023 22:50 by TheRoslyak.
The following user(s) said Thank You: bkt
Please Log in or Create an account to join the conversation.
- bkt
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 1199
- Thank you received: 103
02 Nov 2023 08:13 #284305
by bkt
Replied by bkt on topic int do_gets_cmd(QString) get bool receive .... HAL_TYPE_UNINITIALIZED
for (sig = SHMPTR(hal_data->sig_list_ptr); sig; sig = SHMPTR(sig->next_ptr)) { ----> produce these two error:
/home/TestPc/.fix/r_cnc/get_command.h:353: error: assigning to 'hal_sig_t *' from incompatible type 'void *'
/home/TestPc/.fix/r_cnc/hal_priv.h:100: expanded from macro 'SHMPTR'
/home/TestPc/.fix/r_cnc/get_command.h:353: error: assigning to 'hal_sig_t *' from incompatible type 'void *'
/home/TestPc/.fix/r_cnc/hal_priv.h:100: expanded from macro 'SHMPTR'
plus .... for check 200 or more IN-OUT in one only call need Qthread or some spec ... not sure is possible do these with Qtimer call .... so from mainwindows, after a qtimer call, I check every IN OUT and call everytime do_gets_cmd .... so no qthread needed .... probabily above error become from c/c++ mixing usage.... but not sure at all...
/home/TestPc/.fix/r_cnc/get_command.h:353: error: assigning to 'hal_sig_t *' from incompatible type 'void *'
/home/TestPc/.fix/r_cnc/hal_priv.h:100: expanded from macro 'SHMPTR'
/home/TestPc/.fix/r_cnc/get_command.h:353: error: assigning to 'hal_sig_t *' from incompatible type 'void *'
/home/TestPc/.fix/r_cnc/hal_priv.h:100: expanded from macro 'SHMPTR'
plus .... for check 200 or more IN-OUT in one only call need Qthread or some spec ... not sure is possible do these with Qtimer call .... so from mainwindows, after a qtimer call, I check every IN OUT and call everytime do_gets_cmd .... so no qthread needed .... probabily above error become from c/c++ mixing usage.... but not sure at all...
Please Log in or Create an account to join the conversation.
- TheRoslyak
- Offline
- Elite Member
Less
More
- Posts: 238
- Thank you received: 37
02 Nov 2023 08:18 #284306
by TheRoslyak
Replied by TheRoslyak on topic int do_gets_cmd(QString) get bool receive .... HAL_TYPE_UNINITIALIZED
Correct the line
for (sig = (hal_sig_t *)SHMPTR(hal_data->sig_list_ptr); sig; sig = (hal_sig_t *)SHMPTR(sig->next_ptr)) {
It doesn't matter how many signals it reads. Your code is poorly written in general. It could update even a billion signals. The point is not to return the value but to determine the address where the variable's value is located.
for (sig = (hal_sig_t *)SHMPTR(hal_data->sig_list_ptr); sig; sig = (hal_sig_t *)SHMPTR(sig->next_ptr)) {
It doesn't matter how many signals it reads. Your code is poorly written in general. It could update even a billion signals. The point is not to return the value but to determine the address where the variable's value is located.
The following user(s) said Thank You: bkt
Please Log in or Create an account to join the conversation.
- TheRoslyak
- Offline
- Elite Member
Less
More
- Posts: 238
- Thank you received: 37
02 Nov 2023 09:33 #284307
by TheRoslyak
Replied by TheRoslyak on topic int do_gets_cmd(QString) get bool receive .... HAL_TYPE_UNINITIALIZED
did it work?
Please Log in or Create an account to join the conversation.
- bkt
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 1199
- Thank you received: 103
02 Nov 2023 09:49 #284309
by bkt
Replied by bkt on topic int do_gets_cmd(QString) get bool receive .... HAL_TYPE_UNINITIALIZED
yes I'm not a software eng. .... so is difficult for me write a good clean code .... plus have few time for my learning about classes of lcnc .... for now addhal_sig_t *sig = nullptr;to your, because warning .... any how your code freeze my gui .... mine show only UNINITIALIZED ...Actually I add mode "debug" row for understand better origin of problem, and I reduce number of request to 16 .... only 8 ethercat IN and 8 ethercat OUT ..... so can see these output (all value = 0 when someone are flashing actually in EL2008 and some In on EL1008 are at ON ) .... see my axis signal working:
see my gui ethercat on QProcess request working (you see only actual value .... but are QProcess that call "ethercat upload ......"):
and see do_gets_cmd debug messages result:So think some library are bad linked .... more than pure code error ....
see my gui ethercat on QProcess request working (you see only actual value .... but are QProcess that call "ethercat upload ......"):
and see do_gets_cmd debug messages result:So think some library are bad linked .... more than pure code error ....
Attachments:
Please Log in or Create an account to join the conversation.
- LinuxCNC
- General LinuxCNC Questions
- (solve} int do_gets_cmd(QString) get bool receive .... HAL_TYPE_UNINITIALIZED
Time to create page: 0.100 seconds