Quantcast
Channel: LabWindows/CVI topics
Viewing all articles
Browse latest Browse all 5365

TCP Connection: send data from CVI Client to LabView Server

$
0
0

Hi!

 

I have big issues establishing communication over TCP between client app written in CVI and server written in LabView.

First, I created client app in LabView and communication worked fine. In attached picture ‘from_labview_client.jpg’ I pictured server behavior when app was sending two portions of information: first -  number of bytes to read in next TCPRead, second – actual information containing measure parameters (three doubles: 2.00, 2.00, 2.00 in cluster). I also attached LabView client block diagram (client_labview.jpg) so you could see how it works.

 

Then I wanted to achieve the same results using client app written in CVI. As you can see (from_cvi_client.jpg), in the second ClientTCPWrite I struggle to send data in the correct form - I tried sending cluster, but probably I'm doing it somehow wrong.

Could you please help me and point where I make mistake and how to correct it? How to get rid of null values in the beginning of second data out? How to properly cast doubles/cluster to ASCII?

 

Here is my callback function to send data from client to server:

static unsigned int g_hconversation;  
static double n_steps;
static double max;
static double min;

int CVICALLBACK start (int panel, int control, int event,
		void *callbackData, int eventData1, int eventData2)
{   
	char paramy[4];

	switch (event)
	{
		case EVENT_COMMIT:
			
			 GetCtrlVal (panelHandle, PANEL_NUMERIC, &n_steps);  //getting values from numeric to variables
			 GetCtrlVal (panelHandle, PANEL_NUMERIC_2, &min);
			 GetCtrlVal (panelHandle, PANEL_NUMERIC_3, &max);
			 typedef struct params params;		  //struct definiton
			 struct params{
				 double min;
				 double max;
				 double n_steps;
			 };
			 struct params struktura;                       // struct initialization
			 struktura.n_steps = n_steps;
			 struktura.max = max;
			 struktura.min = min;
			 SetWaitCursor (1);
    int err = ConnectToTCPServer (&g_hconversation, 6341, "", ClientTCPCB, 0, 5000); // establish connection

	if(err<0)
		{
		MessagePopup("TCP Client", "Connection to server failed !");	
		break;
		}
    else
        {
		printf("CONNECTED\n");

		paramy[0] = 0;
		paramy[1] = 0;
		paramy[2] = 0;
		paramy[3] = sizeof(struktura);
		
		err = ClientTCPWrite (g_hconversation,&paramy ,sizeof(paramy), -1);  
		err = ClientTCPWrite (g_hconversation, &struktura,sizeof(struktura), -1);
		}

			break;
	}
	return 0;
}

 

Thanks in advance!


Viewing all articles
Browse latest Browse all 5365

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>