LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

windows socket calls and CVI tcp/ip library

I need to write a CVI application to talk to our device. The device uses
tcp/ip. I have source code of a VC++ app which talks to this device but it
uses windows socket calls like WSAStartup, socket, send/recv etc. I am
hoping I can accomplish the same by using LabWindows CVI tcp/ip library
functions.

Any input is appreciated.


vishi
0 Kudos
Message 1 of 4
(4,312 Views)
Good Mornig Vishi.

First thing is my English is very bad, but I try help you.

You can use WSAStatup in CVI , because this function is defined in the SDK of Cvi .The functions you need ar defined in the WSock32.lib of SDK . In this SDK you have all functions that you need for implement your communications with your device.

For Example , this is the code to open a UDP Comunications:


//----------------------------------------------------------------------------------
// OPEN A UDP COMUNICATIONS
int OpenUDP(int iNumberPort, int *HandleSocket)
{
SOCKADDR_IN sin;
WORD wVersionRequested;
WSADATA wsaData;
int errorUDP, t = 1;
unsigned long u = 0;

wVersionRequested = MAKEWORD(1, 1);
if((errorUDP = WSAStartup(wVersionRequested,
&wsaData)) != 0) {
WSACleanup();
return errorUDP;
}

//OPEN A SOCKET
*HandleSocket = socket(AF_INET, SOCK_DGRAM,0);
if(*HandleSocket == INVALID_SOCKET)
{
errorUDP = WSAGetLastError(); fclosesocket(*HandleSocket);
WSACleanup();
}

sin.sin_family = AF_INET;
sin.sin_addr.s_addr = htonl(INADDR_ANY); // sin.sin_port = htons(iNumPort);
if((errorUDP = bind(*HandleSocket, (LPSOCKADDR)&sin, sizeof(sin))) != 0) /
{
errorUDP = WSAGetLastError();
closesocket(*HandleSocket);
WSACleanup();
return errorUDP;
}

ioctlsocket(*HandleSocket, FIONBIO, &u);

setsockopt(*HandleSocket, SOL_SOCKET, SO_BROADCAST, (char*)&t, sizeof(int));
return 0;
}

If you need a Help to implement the rest of functions tell me to:

f.bermejo.garapen@adegi.es

Tximis
0 Kudos
Message 2 of 4
(4,312 Views)
Hello,
Let me also add that you need to have Windows SDK support installed on your machine by performing a custom installation of LabWindows/CVI. If you have performed a typical installation, you do not have the support installed on your computer and you need to modify the installation from Add/Remove programs. There, you can add the Windows SDK support. Once you have the support installed, you do not have to specify the include path for the SDK functions, CVI will find the files in ...\CVI\sdk\include directory automatically.

Mika Fukuchi
Application Engineer
National Instruments
0 Kudos
Message 3 of 4
(4,312 Views)
Thanks,

vishi

"Siabevef" wrote in message
news:50650000000500000085C80000-1042324653000@exchange.ni.com...
> Good Mornig Vishi.
>
> First thing is my English is very bad, but I try help you.
>
> You can use WSAStatup in CVI , because this function is defined in the
> SDK of Cvi .The functions you need ar defined in the WSock32.lib of
> SDK . In this SDK you have all functions that you need for implement
> your communications with your device.
>
> For Example , this is the code to open a UDP Comunications:
>
>
>
//--------------------------------------------------------------------------
--------
> // OPEN A UDP COMUNICATIONS
> int OpenUDP(int iNumberPort, int *HandleSocket)
> {
> SOCKADDR_IN sin;
> WORD wVersionRequested;
> WSADATA wsaData;

> int errorUDP, t = 1;
> unsigned long u = 0;
>
> wVersionRequested = MAKEWORD(1, 1);
> if((errorUDP = WSAStartup(wVersionRequested, &wsaData)) !=
> 0) {
> WSACleanup();
> return errorUDP;
> }
>
> //OPEN A SOCKET
> *HandleSocket = socket(AF_INET, SOCK_DGRAM,0);
> if(*HandleSocket == INVALID_SOCKET)
> {
> errorUDP = WSAGetLastError();
> fclosesocket(*HandleSocket);
> WSACleanup();
> }
>
> sin.sin_family = AF_INET;
> sin.sin_addr.s_addr = htonl(INADDR_ANY); // sin.sin_port =
> htons(iNumPort);
> if((errorUDP = bind(*HandleSocket, (LPSOCKADDR)&sin,
> sizeof(sin))) != 0) /
> {
> errorUDP = WSAGetLastError();
> closesocket(*HandleSocket);
> WSACleanup();
> return errorUDP;
> }
>
> ioctlsocket(*HandleSocket, FIONBIO, &u);
>
> setsockopt(*HandleSocket, SOL_SOCKET, SO_BROADCAST, (char*)&t,
> sizeof(int));
> return 0;
> }
>
> If you need a Help to implement the rest of functions tell me to:
>
> f.bermejo.garapen@adegi.es
>
> Tximis
0 Kudos
Message 4 of 4
(4,311 Views)