LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

can't receive the data from my hardware device by LAN

Hi!

background:  For a testing task, I set up a hardware testing platform that including of a power supply device, a hardware to be tested(Device Under Test), a power Meter and a PC.   i build a program to control the hardwares, and they communicate with each other by LAN. at first, the program as a client can normally communicates with my hardware after initializing all hardwares. And then the program turns off the power of my device and turn on power again after delay 60 seconds. after initiantion, my hardware can execute the command which is received from the program, but the program can't receive the data from my hardware. Why my program cannot receive the data from my hardware, after the second time turn on the power of my hardware?  the program as client code as below:


int CVICALLBACK ClientRRH (unsigned handle, int event, int error, void *callbackData)
 {
  char temp[64]={0};
  int  ReceiveSize=0;
  char *Pos;

  switch(event)
  {
   case TCP_DATAREADY:
   
    if( (ReceiveSize=ClientTCPRead (rrhHandle, readRRHBuffer, 4096, 2000))<0)
    {
                 SetCtrlVal (panelHandle, PANEL_TEXTBOX_INFO,"Read RRH trace error!\n");  
                return 0;
    }
    else
    {
     if (ReceiveSize>4096)
      readRRHBuffer[4096]= '\0';
       else
       readRRHBuffer[ReceiveSize] = '\0';
    } 
    if (Flag)
      {
      Pos = strstr(readRRHBuffer,orderString);
      if(Pos)
      {
       //strncpy(temp,(Pos+ strlen(orderString)),maxSize);
       _mbsnbcpy(temp,(Pos+ strlen(orderString)),maxSize); 
       sprintf(receData,temp);
       *temp=0;
       Flag=0;
       maxSize=0;
       *orderString=0;
      }
      }  
         
    SetCtrlVal (panelHandle, PANEL_TEXTBOX_INFO,readRRHBuffer);
    *readRRHBuffer=0;

            break;
   
         case TCP_DISCONNECT:  
   rrhHandle =error;
            SetCtrlVal (panelHandle, PANEL_TEXTBOX_INFO,"TCP Client:Server has closed connection!\n");                 
            SetCtrlVal (panelHandle, PANEL_LED_RRH, 0);      
            break;
   
  }  
 return 0;
 }

 

int RRH_ini(char *RRH_address)

{

    ViChar Buffer[200];

    char temp[200];

    int status =0;

 

 if((ConnectToTCPServer (&rrhHandle, 7006, rrhAddr, ClientRRH, NULL, 1000)<0))
    {
     SetCtrlVal(panelHandle,PANEL_LED_RRH,0);
    SetCtrlVal(panelHandle,PANEL_TEXTBOX_INFO,"Connection to RRH fail...\n");
    }
     else
    {
     SetCtrlVal(panelHandle,PANEL_LED_RRH,1);
     SetTCPDisconnectMode (rrhHandle, TCP_DISCONNECT_AUTO);

     sprintf(RRHCommand,"%s\n","asb");
     ClientTCPWrite (rrhHandle, RRHCommand, strlen(RRHCommand), 0);
     Delay(0.2);
     sprintf(RRHCommand,"%s\n","asb#1234");
     ClientTCPWrite(rrhHandle,RRHCommand,strlen(RRHCommand),0);
     Delay(0.2);
     SetCtrlVal(panelHandle,PANEL_TEXTBOX_INFO,"Connection to RRH successful!\n");
     }   
   
   return 0;
}

 

 

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