LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

no connection established

Hi,
I am trying to communicate with a speed drive (proxidrive 5,5T leroy somer) connected with an SM-ethernet card, at this point I am able to ping the card from my computer wich will be the host, the card adress is 192.168.1.100, and the host computer has the following address 192.168.1.1, the code bellow is what I have started to do to program this speed drive.
unfortunatetly when I run it i get an error non connection established on the TCPErrorString  = GetTCPErrorString (GetTCPPeerAddr(ConnectionHandle, PeerAddr, 256)); line, I thought that whenever I have started the registertcpserver function without any error the connection must be established but apparently not.
I am not sure I am doing it the right way, could somebody explain me how to handle this?
Does anybody know if someone had already wrote some similar code , or maybe used leroy somer previously mentionned products?

Thanks all

Olivier

#include <utility.h>
#include <formatio.h>
#include <ansi_c.h>
#include "toolbox.h"
#include <analysis.h>
#include <tcpsupp.h>
#include <cvirte.h>       
#include <userint.h>
#include "Ethernet.h"

int TCPCallBackFunction (unsigned handle, int xType, int errCode, void *callbackData);



static int panelHandle;

char ** addresses;
int numAddresses;
int index;
unsigned int TCPConversationHandle;
void *DataPtr;
int DataSize;
char *TCPErrorString;
char HostAddr[256];
char PeerAddr[256];
unsigned int ConnectionHandle;
#define NB_MAX_DATA                100
#define REQUEST_BUFF_SIZE 50

int main (int argc, char *argv[])
{
    if (InitCVIRTE (0, argv, 0) == 0)
        return -1;   
    if ((panelHandle = LoadPanel (0, "Ethernet.uir", PANEL)) < 0)
        return -1;
    DisplayPanel (panelHandle);
   
   
  
    TCPErrorString  = GetTCPErrorString( RegisterTCPServer (502, TCPCallBackFunction, 0000));
   
    GetTCPHostAddr(HostAddr, 256);
   
    TCPErrorString  = GetTCPErrorString (GetTCPPeerAddr(ConnectionHandle, PeerAddr, 256));
       
    //ServerTCPWrite(TCPConversationHandle, DataPtr, DataSize , 1 );  
    //int (*TCPCallBackFunction) (unsigned handle, int xType, int errCode, void *callbackData);  
   
   
    RunUserInterface ();
    DiscardPanel (panelHandle);
    return 0;
}

int TCPCallBackFunction (unsigned handle, int xType, int errCode, void *callbackData)
{
        switch(xType)
        {
       
        case TCP_CONNECT :
            printf("Connect\n");
        break;
        }
       
    return 0;
}



int CVICALLBACK Send_CB (int panel, int control, int event,
        void *callbackData, int eventData1, int eventData2)
{
    switch (event)
    {
        case EVENT_COMMIT:
           
            ServerTCPWrite(TCPConversationHandle, DataPtr, DataSize , 1 );

            break;
    }
    return 0;
}


int CVICALLBACK QuitCallback (int panel, int control, int event,
        void *callbackData, int eventData1, int eventData2)
{
    switch (event)
    {
        case EVENT_COMMIT:
            QuitUserInterface(panelHandle);
            break;
    }
    return 0;
}

0 Kudos
Message 1 of 2
(4,001 Views)
In a TCP conversation it's not enough that you register your PC as a server: the client(s) need to connect to the server before any conversation can be established. Apparently you need to operate on your motor driver to let it search for a server on the network (your PC) and connect to it. In your program you will need to have a wait state until the expected clients to connect to the server before you can operate on the remote system.
 
Unless you can revert the situation and set the driver as the server and your computer as a client: in this condition the driver is waiting for a connection and your program must use ConnectToTCPServer () to establish a connection to it. The RegisterTCPServer function is no longer needed in this environment and you will need to use ClientXXX functions instead of ServerXXX ones.
 
In any case, your conversation handle must not be empty before you can use GetTCPPeerAddr: as you can see in the documentation for this field:
TCP Support Library conversation handle that you obtain from ConnectToTCPServer or ConnectToTCPServerEx or receive in a server callback as the handle parameter of a TCP_CONNECT message.


Message Edited by Roberto Bozzolo on 03-20-2008 05:42 PM


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 2
(3,996 Views)