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

ConnectToTCPServer callback in different .c file not working.

$
0
0

Hello,

I have problem with ConnectToTCPServer in my program. Basically i have files scanner.c and scanner.h where ConnectToTCPServer is covered as below:

 

int EstablishScannerConnection(int scannerHandle, char *ip, int port)  {

int status=0;

strcpy (scannerObj[scannerHandle].ip, ip);     // kopiuj ip

scannerObj[scannerHandle].port = port;        // kopiuj port

scannerObj[scannerHandle].connect = 0;

status = ConnectToTCPServer(&scannerObj[scannerHandle].handle, scannerObj[scannerHandle].port, scannerObj[scannerHandle].ip, TCPCallback, 0, 2000);

 

if(status < 0) {

scannerObj[scannerHandle].errorMsg = GetTCPErrorString(status); scannerObj[scannerHandle].error = status;

if(scannerObj[scannerHandle].errorCallback) scannerObj[scannerHandle].errorCallback();

else

ErrorMSG( scannerHandle ); } else scannerObj[scannerHandle].connect = 1;

return scannerObj[scannerHandle].connect;

}

 

also in this file i have got TCPcallback:

 

 

int CVICALLBACK TCPCallback (unsigned handle, int event, int error,  void *callbackData) {
int status, i;

// szukaj numeru uchwytu
for (i=0; i< MAX_SCANNERS; i++) {
if(handle == scannerObj[i].handle) break;
}

switch (event) {
case TCP_DATAREADY:

scannerObj[i].dataLen = 0;
scannerObj[i].errorMsg = 0;

status = ClientTCPRead (handle, scannerObj[i].data , sizeof(scannerObj[i].data), 1000);

if ( status < 0) scannerObj[i].errorMsg = GetTCPErrorString(status);
else scannerObj[i].dataLen = strlen(scannerObj[i].data);

//scannerGetDataCB(i);
if(scannerObj[i].getDataCallback) scannerObj[i].getDataCallback(handle);
break;


case TCP_DISCONNECT:

CloseScannerConnection(i);
char outputMsg[1024]="0";
Fmt (outputMsg, "Scanner#%d\n\nIP: %d:%d:%d:%d\n\n%s\n\nDisconnected ", i, scannerObj[i].ip[0], scannerObj[i].ip[1], scannerObj[i].ip[2], scannerObj[i].ip[3]);
MessagePopup("Scanner", outputMsg);
if(scannerObj[i].closeConnCallback) scannerObj[i].closeConnCallback();
break;
}

return 0;
}

 

In main file I have:

 

#include "scanner.h"  

 

int main (int argc, char *argv[]) {

...

if(EstablishScannerConnection(SCANNER_OP130, SCANNER_OP130_IP, SCANNER_OP130_PORT))  {
   SetCtrlVal (panelHandle, PANEL_LED_SCANNER, 1);
} else {
   SetCtrlVal (panelHandle, PANEL_LED_SCANNER, 0);
}

}

 

My problem is that I have got connection with TCPServer by my TCPCallback is not working - i do not have callback TCP_DATAREADY or any different when data is ready. When I put ConnectToTCPServer as below into main it is working (I have callback for TCP_DATAREADY, but  TCP_DISCONNECT is not working):

 

int main (int argc, char *argv[]) {

...

if(ConnectToTCPServer(&scanerHandle, scannerObj[scanerHandle].port, scannerObj[scanerHandle].ip, TCPCallback, 0, 2000)==0) {
   SetCtrlVal (panelHandle, PANEL_LED_SCANNER, 1);
} else {
   SetCtrlVal (panelHandle, PANEL_LED_SCANNER, 0);
}

}

 

I am using one thread, and ProcessSystemEvents(); in that thread:

CmtScheduleThreadPoolFunction (DEFAULT_THREAD_POOL_HANDLE, ThreadMain, NULL, &threadMainHandle);

 

I will be appreciable to give me direction how to fix it.

 

 

 

 


Viewing all articles
Browse latest Browse all 5339

Trending Articles



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