workaround about MB2HAL H+L register value

More
15 Sep 2022 19:16 #252026 by bkt
float get_float_pin_val(QString nV){
    char nHv[strlen(nV.toStdString().c_str()) + 1];
    strcpy(nHv, nV.toStdString().c_str());
    hal_data_u *value;
    hal_type_t type;
    bool *con = nullptr;
    float checkVal = 0;
    int r=hal_get_pin_value_by_name(nHv,&type,&value,con);
        if(r!=0){
            checkVal = -1;
        }
        else {
            checkVal = value->f;
        }
        return checkVal;
}

These func for load pin value that is MB2HAL register .... because need to load 32bit register, can convert these func for read 16bit value 2 time on 2 consecutive register than combine it to obtain 32bit register??

sometings like these:
float get_float_pin_val(QString nV, QString nVplus1){
    char nHv[strlen(nV.toStdString().c_str()) + 1];
    strcpy(nHv, nVplus1.toStdString().c_str());
    char nHvplus1[strlen(nV.toStdString().c_str()) + 1];
    strcpy(nHvplus1, nVplus1.toStdString().c_str());
    hal_data_u *value;
    hal_type_t type;
    bool *con = nullptr;
    char checkVal[16];
    char checkVal1[16];
    int r=hal_get_pin_value_by_name(nHv,&type,&value,con);
        if(r!=0){
            checkVal = {};
        }
        else {
            checkVal = value->b;
        }

int r1=hal_get_pin_value_by_name(nHvplus1,&type,&value,con);
        if(r1!=0){
            checkVal1 = {};
        }
        else {
            checkVal1 = value->b;
        }
        /* usual combining code for checkVal1 & checkVal or L+H 16bit register*/
}

these can work or there are other way to obtain char value from bit? ... because value->f was unable to show in some way H part of my 16bit+16bit register .... but L part can see perfectly with value->f ... but only positive value.

 

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

More
26 Sep 2022 12:39 #252758 by andypugh
combining 2 x 16 bit registers into 1 x 32-bit isn't especially easy.

One way to do it in C code is to create a Union data structure, containing a float and a U32 in the same memory location. Load in the 16-bit patterns, and then read the value back as a float.

But I a not really understanding the nature of the question, so this might not be a useful answer.
The following user(s) said Thank You: bkt

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

Time to create page: 0.055 seconds
Powered by Kunena Forum