~46~
Appendix C Example Program
/ *
* Example C program for controlling MOXA serial/Non-TTY ports
* using MOXA DOS/UNIX API-232 library
* /
#include "mxapi232.h"
void main()
{
int port_no, count, i;
char data[81];
/* Setting the port 9600, N, 8, 1, ... */
port_no = 1;
if (sio_ioctl(port_no, B9600, BIT_8 | P_NONE | STOP_1) != 0) {
printf("Port #%d sio_ioctl() error !\n", port_no);
exit;
}
sio_lctrl(port_no, 3); /* set DTR RTS on */
sio_flowctrl(port_no, 0); /* set NO flow control */
sio_open(port_no); /* Open Port */
/* Get line status from port. If CTS and DSR are ON, continue */
while (1) {
if ( sio_lstatus(port_no) & 3 )
break;
}
/* Read input queue status from port. If any input data, read it */
i = 5; /* execute for 5 times */
while (i) {
if ((count = sio_iqueue(port_no)) > 0) {