Download RAW-Connection User`s Guide

Transcript
Programming Example 1
The following example was developed under VC++ 4.2 for Windows 9x/NT/2000
//////////////////////////////////////////////////////////////
//
//
// NPort RAW mode Tx/Rx example program
//
//
//
// Date:
08-30-2001
//
//
//
// Version:
1.0
//
//
//
// Program description:
//
//
A dumb terminal emulation example program
//
//
via NPort RAW mode
//
//
1. hit <ESC> to stop the program
//
//
2. program sends data from the keyboard to NPort
//
//
3. program prints to the screen any data
//
//
read from NPort
//
//
4. Syntax: as_raw NPort_IP TCP_PORT
//
//
5. Program developed under VC++ 4.2
//
//
6. May be used on Windows 9X/NT/2000 OS
//
//
//
//////////////////////////////////////////////////////////////
#include
#include
#include
#include
#include
#include
<winsock2.h>
<stdlib.h>
<stdio.h>
<fcntl.h>
<string.h>
<conio.h>
#define IP_ERROR
#define INTERVAL
#define RETRY
0xFFFEFFFFL // Invalid ip address
100
// 10 msec
50
// connect retry count
SOCKET
Fd;
unsigned long
SOCKET
int
{
// Socket descriptor used on data Tx/Rx
dot2ip(char *dot);
sioopen(unsigned long ipaddr,int p);
main(int argc, char *argv[])
int
port,i;
unsigned long ip;
WSADATA
wsaData;
char
ch,len;
char
buf[80];
SOCKET
fd;
if ( argc < 3 ) {
printf("Syntax: %s NPortIP TCP_Port\n",argv[0]);
return -1;
}
ip = dot2ip(argv[1]);
if (ip == IP_ERROR) {
printf("Invalid IP address %s!\n",argv[1]);
return -2;
}
port = atoi(argv[2]);
3/8