beautypg.com

Sample – Solvline PB2xxxUG User Manual

Page 85

background image

3. Sample

1). User Active Program
All this program does is connect to the host you specify on the command line, and port you specify on
the command line. After connecting, sent data from TCP socket reads in serial port, and sent data from
serial file descriptor reads in connection-based (stream) socket.

/*---------------------------------------------------------------*/

struct SYS_INFO

/*---------------------------------------------------------------*/

{

unsigned char port_no;

// 1 ~ 16

int

speed;

// 0=150 ~ 11=230400 BPS

char

lcr;

// data bits + parity bits + stop bits

char

flow;

// 0=None, 1=Xon/Xoff, 2=RTS/CTS

short

sock_no;

// My socket No.

unsigned char dest_ip [20]; // destination IP

unsigned short dest_port;

// destination socket No.

short

mtu;

// 1 ~ 1100

char

signal;

// 0=Dataonly, 1=Modem

short

alive_time;

// 0 ~ 32767

};

/*---------------------------------------------------------------*/

/* System's configuration is to determine these arguments. */

/*---------------------------------------------------------------*/

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

/*---------------------------------------------------------------*/

{

struct SYS_INFO

SYS;

int SFD;

// Serial Device FD

int LFD;

// socket FD

char WORK [1024];

int ret;

printf ("\nStart User Application\n");

SYS.port_no

=

atoi

(argv[1]);

SYS.speed

=

atoi

(argv[2]);

SYS.lcr

=

atoi

(argv[3]);

SYS.flow =

atoi

(argv[4]);

SYS.sock_no

=

atoi

(argv[5]);

strcpy

(SYS.dest_ip, argv[6]);

SYS.dest_port = atoi (argv[7]);

SYS.mtu

=

atoi

(argv[8]);

SYS.alive_time = atoi (argv[9]);

SYS.signal

=

atoi

(argv[10]);

printf ("No=%d,BPS=%d,lcr=%d,flow=%d,My socket=%d,

Dest IP=%s(%d),MTU=%d,Alive=%dSignal=%d\n",

SYS.port_no, SYS.speed, SYS.lcr, SYS.flow, SYS.sock_no,

SYS.dest_ip, SYS.dest_port, SYS.mtu, SYS.alive_time, SYS.signal);

SFD = U_open_port (SYS.port_no);

// Open serial port

U_init_port (SFD, SYS.speed, SYS.lcr, SYS.flow);

// Setting serial port

85