LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Timer for Datasocket

 

return 0;

}

Hi guys, please I need some help. In this timer function I am running a test continously from StartTestWithSocket().
But at the same time, I am using "DS_GetDataType" to get data through the datasocket just a string such as "runTest2"
Once I received that string, if it is a valid string the system will stop and start that particular test.
I am trying to use a time, my StartTestWithSocket() function is running (it must be running continously), but other piece of codes not running. SO I cannot waht my incoming string.
Any help please.

 

 

 

int CVICALLBACK timer (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 
 char commandSent[11];
 
          GetCtrlVal (panelHandle, PANEL_COMM_RECEIVED , commandSent); //command needed to start StartTestWithSocket()
   StartTestWithSocket(); // running tests continously
 
   
   //reading the from datasocket
 while (true)
 {
   errorCode = DS_GetDataType (DSReadHandle, NULL, &StringLen, NULL);
   
   if (StringLen ==0)  //No data received
   {
    MessagePopup ("DATASOCKET ERROR",
         "No data received. Connect Write DataSocket first");
    return 0;
   }
   else
    ReadString= malloc(StringLen +1);
    
   //Get the string from DataSocket Writer
   errorCode = DS_GetDataValue (DSReadHandle, CAVT_CSTRING,
             ReadString, StringLen+1, 0, 0);
   Checkerror(errorCode);          
   //Get the index value from DataSocket Writer
   //errorCode = DS_GetAttrValue (DSReadHandle, "Index", CAVT_SHORT,
   //        &WriteData.index, sizeof(short), 0, 0);
   
      Checkerror(errorCode);
  
   //No errors, write data
   if (errorCode>=0)
   {
    InsertTextBoxLine(panelHandle,PANEL_COMM_RECEIVED, -1, ReadString);
   // SetCtrlVal(PanelHandle, DS_READ_INDEX,WriteData.index);
   }
   
  .... if ReadString==valid command and ReadString!=commandSent, stop test and start new test
 }
 
 
 
return 0;

}

0 Kudos
Message 1 of 2
(2,727 Views)

Hi Agyna,

 

It looks like you will need to do some multi-threading programming to achieve what you want to do. The test needs to run in a separate thread while you monitor the data socket. This way the data socket reads while the test is running concurrently. I've listed a link below on this topic for your reference.

 

http://digital.ni.com/public.nsf/allkb/6ECCBAA87476EB22862568950071CCD6?OpenDocument

 

I hope this helps.

 

Josh L.

Applications Engineer
National Instruments
0 Kudos
Message 2 of 2
(2,711 Views)