PXI

cancel
Showing results for 
Search instead for 
Did you mean: 

CNVString - Sending Strings from a PXI chassis over ethernet to a labWindows application on another computer

Solved!
Go to solution

I have a PXI chassis with a PXI-8101 controller. It is set up with a realtime operating system. I am communicating to it with a PC with a Windows operating system. I am trying to send variable length string messages from my PXI system to my PC.

 

On the PC I have a LabWindows application which can send and receive data with the PXI system. I am attempting to send error messages from the PXI system to the PC on ethernet. I am able to send numerical data between them but not the string messages. The PXI software runs to the function call CNVCreateArrayDataValue() and steps into it but never returns. It only has this problem when the parameter CNVDataType is CNVString; when I change CNVDataType to CNVBool it does not have this problem. I am new to this PXI realtime so would appreciate the help. Below is the code on my PXI system which sends these text messages.

 

In the beginning of RTMain I create the Writer

      CNVCreateBufferedWriter("\\\\localhost\\system\\" REG_CAL_ERROR_STRING, 0, 0, 0, 64, 5000, 0, &gErrorPublisher);

 

Then I call a function with a string in the parameter list:

void SendRT_ErrorMessage(char* message)

{                                    

      CNVData data=0;

      int error;

      char error_str[256];

       int i;

      char out_str[ERROR_STRN_SIZE*4];

      strcpy(out_str,message);

      size_t arrayDims= ERROR_STRN_SIZE;

      arrayDims= strlen(message) +1;

     

      error = CNVCreateArrayDataValue(&data, CNVString, out_str, 1, &arrayDims);

      if(error<0)

      {

            strncpy(error_str, CNVGetErrorDescription(error),256);

      }

//    CNVPutDataInBuffer(gErrorPublisher, data, 1000);

 

     

      CNVSetArrayDataValue(data,CNVString,out_str,1,&arrayDims);

      CNVPutDataInBuffer(gErrorPublisher, data, 1000);

     

      CNVDisposeData(data);

     

}

 

0 Kudos
Message 1 of 11
(4,005 Views)

Hi,

 

When you say it doesn't return, what do you mean? Does your program just hang? What if you used something like CNVCreateScalarDataValue  (&data, CNVString, out_str) instead? Does that work?

Rohama K.
0 Kudos
Message 2 of 11
(3,992 Views)

I've changed things around and now the application on the realtime operating system on the PXI-8101 does not hang but my host computer does not see the message correctly. It sees some characters but they are not what I sent.

I don't seem to be able to get message out of CNVData data properly. Below is the new code for the PXI-8101 controller and the Host computer LabWindows application.

 

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Here is the code in the PXI-8101 controller now:

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 CNVCreateWriter("\\\\localhost\\system\\" REG_CAL_ERROR_STRING, 0, 0, 5000, 0, &gErrorPublisher);

void SendRT_ErrorMessage(char* message)
{       
 CNVData data=0;
 int error;
 char error_str[256];
  int i;
 char out_str[ERROR_STRN_SIZE*4];
 strcpy(out_str,message);
 size_t arrayDims= ERROR_STRN_SIZE;
 arrayDims= strlen(message) +1;
 
 error = CNVCreateScalarDataValue( &data,CNVString,out_str); 
 if(error<0)
 {
  strncpy(error_str, CNVGetErrorDescription(error),256);
 }

 

 CNVWrite(gErrorPublisher, data, 1000);
 
 CNVDisposeData(data);
 
}

 

 

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

And here is the code in the Host computer LabWindows application:

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 sprintf(path, "\\\\%s\\system\\%s", address, REG_CAL_ERROR_STRING);
 CNVCreateSubscriber(path, ErrorMessageCallback, 0, 0, 10000, 0, &gErrorMessageSubscriber);

 


static void CVICALLBACK ErrorMessageCallback(void * handle, CNVData data, void * callbackData)
{
 char message[ERROR_STRN_SIZE];
 
 CNVGetScalarDataValue(data,CNVString,(void *)message);
 (void)SetCtrlVal(panelHandle,PANEL_TEXTBOX_DEBUG_MSG,"got something\n");
 (void)SetCtrlVal(panelHandle,PANEL_TEXTBOX_DEBUG_MSG,message);
 (void)SetCtrlVal(panelHandle,PANEL_TEXTBOX_DEBUG_MSG,"\n");
   
 CNVDisposeData(data);
 
}

 

You can see that I output a message "got something" so that I know I got the callback but the next line is a gibberish message "HÊl "

 



 

 

0 Kudos
Message 3 of 11
(3,984 Views)

Hi,

 

 

For the following on your host computer : 

CNVGetScalarDataValue(data,CNVString,(void *)message);

 

What happens if you change it to this:

CNVGetScalarDataValue(data,CNVString,message);
Rohama K.
0 Kudos
Message 4 of 11
(3,980 Views)

I get a runtime error.

 

Found pointer to character expected pointer to pointer to character

0 Kudos
Message 5 of 11
(3,977 Views)

Do you see the correct information in the Distributed System Manager?

Rohama K.
0 Kudos
Message 6 of 11
(3,975 Views)

Yes I do see the correct information in the Distribution System Manager. Thanks for telling me about that tool. I was not aware of its existenance. Very handy. Unfortunately, I still do not understand why my UI application does not see the message correctly. I know it gets the message because it prints out a message when the callback is called but the string it gets is still wrong.

0 Kudos
Message 7 of 11
(3,960 Views)

I think I figured it out. How are you declaring the third parameter for the following: CNVGetScalarDataValue (CNVData data, CNVDataType type, void *value)? Try declaring it as "char* value" and then have something like this: CNVGetScalarDataValue (data, CNVString, &value). Let me know if this doesn't make sense. 

Rohama K.
0 Kudos
Message 8 of 11
(3,957 Views)

When I do this below it gives me a run-time error "Invalid argument type: found 'pointer to array 30 of char'. expected 'pointer to pointer to char'.

static void CVICALLBACK ErrorMessageCallback(void * handle, CNVData data, void * callbackData)
{
 char message[ERROR_STRN_SIZE];
 
 CNVGetScalarDataValue(data,CNVString,&message);
 (void)SetCtrlVal(panelHandle,PANEL_TEXTBOX_DEBUG_MSG,"got something\n");
 (void)SetCtrlVal(panelHandle,PANEL_TEXTBOX_DEBUG_MSG,message);
 (void)SetCtrlVal(panelHandle,PANEL_TEXTBOX_DEBUG_MSG,"\n");
   
 CNVDisposeData(data);
 
}

 

When I change the line to this below: It does not have a run-time error but obviously does not have the right information.

CNVGetScalarDataValue(data,CNVString,(void *)&message);

 

I also tried this with same result:

CNVGetScalarDataValue(data,CNVString,(void *)message);

 

 

I probably have sort of casting problem but not sure what it is. That is why I was looking for some example code for this. Thought this would give me a clue

 

0 Kudos
Message 9 of 11
(3,950 Views)
Solution
Accepted by topic author DPearce

Change this:


static void CVICALLBACK ErrorMessageCallback(void * handle, CNVData data, void * callbackData)
{
 char message[ERROR_STRN_SIZE];
 
 CNVGetScalarDataValue(data,CNVString,&message);
 (void)SetCtrlVal(panelHandle,PANEL_TEXTBOX_DEBUG_MSG,"got something\n");
 (void)SetCtrlVal(panelHandle,PANEL_TEXTBOX_DEBUG_MSG,message);
 (void)SetCtrlVal(panelHandle,PANEL_TEXTBOX_DEBUG_MSG,"\n");
   
 CNVDisposeData(data);
 
}

 

 

To this:

 

static void CVICALLBACK ErrorMessageCallback(void * handle, CNVData data, void * callbackData)
{
 char* message;
 
 CNVGetScalarDataValue(data,CNVString,&message);
 (void)SetCtrlVal(panelHandle,PANEL_TEXTBOX_DEBUG_MSG,"got something\n");
 (void)SetCtrlVal(panelHandle,PANEL_TEXTBOX_DEBUG_MSG,message);
 (void)SetCtrlVal(panelHandle,PANEL_TEXTBOX_DEBUG_MSG,"\n");
   
 CNVDisposeData(data);
 
}

 

You will have to also add CNVFreeMemory to free the memory allocated for the string.

Rohama K.
0 Kudos
Message 10 of 11
(3,947 Views)