LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Array association

Hello All!

Take a look at this code.  When I associate ptr[0]... to viWriteBuffer[12]... the values do not copy correctly.  The values for iOutputPtr in the ASCIItoHex function are correct, but when I create my variable ptr, I have problems.

int index = 0;
int ptr[8];
char idArray[NUMBER_OF_LCMS];
...
GetPanelHandleFromTabPage (panelHandle, PANEL_TAB, TAB_TWO, &tabHandle);
    GetCtrlIndex (tabHandle, TABPANEL_2_ALL_LIGHTS, &index);
    GetLabelFromIndex (tabHandle, TABPANEL_2_ALL_LIGHTS, index, idArray);
    
    ASCIItoHex( idArray, ptr );
    
    viWriteBuffer[12] = ptr[0];        
    viWriteBuffer[13] = ptr[1];
    viWriteBuffer[14] = ptr[2];        
    viWriteBuffer[15] = ptr[3];
    viWriteBuffer[16] = ptr[4];        
    viWriteBuffer[17] = ptr[5];
    viWriteBuffer[18] = ptr[6];        
    viWriteBuffer[19] = ptr[7];
    
        status = viWrite( gateway, viWriteBuffer, viWriteBufferSize, viWriteDataSize );

                                                                                                                                                                     //The contents of viWriteBuffer[12-19] are not what they are supposed to be (they should be the same as the values in
                                                                                                                                                                     //iOuputPtr in my ASCIItoHex function.
void ASCIItoHex( char cInputStr[], int iOutputPtr[] )
{
    int iInputStr[33] = {0};
    int length = 0;
    int i = 0;
    int k = 0;
    int errorCheck = 0;

    int outputByteStr[8] = { 0x00 };
   
    length = strlen(cInputStr);
   
    //convert input string to integers 0 through 16
    //Requires that input not have spaces letters must be in capitals
    for( i = 0; i < length; i++ )
    {
        iInputStr[i] = (int) cInputStr[i] ;
        if(iInputStr[i] <= '9' && iInputStr[i] >= '0')        //iInputStr between 0 and 9
        {
            iInputStr[i] -= 48;
        }
        else if( iInputStr[i] <= 'F' && iInputStr[i] >= 'A')
        {
            iInputStr[i] -= 55;
        }
        else if( iInputStr[i] <= 'f' && iInputStr[i] >= 'a')
        {
            iInputStr[i] -= 87;
        }
        else if( errorCheck != 1 )
        {
            MessagePopup( "Input Error", "Non-hex value entered, check value and re-enter." );
            errorCheck = 1;
        }
    }
    for( i = 0; i < (length); i += 2 )
    {
        outputByteStr[k] = (( 16 * iInputStr[i] ) + iInputStr[i+1]);
        k++;
    }
   
    iOutputPtr = outputByteStr;
}


0 Kudos
Message 1 of 2
(3,044 Views)

What are you expecting the last line of code to do? (iOutputPtr = outputByteStr;)  If you think it will copy one array to another, you will be sadly disappointed. If this was your intention, then you must either copy each element one word at a time in a loop, or possibly use the library function memcpy() or similar. (strcpy() will not work here, as this is designed to copy strings and will stop copying when it sees a 0 in the data being copied.)

JR

0 Kudos
Message 2 of 2
(3,025 Views)