/*------------------------------------------------------------------------- | rxtx is a native interface to serial ports in java. | Copyright 1997 by Trent Jarvi jarvi@ezlink.com. | | This library is free software; you can redistribute it and/or | modify it under the terms of the GNU Library General Public | License as published by the Free Software Foundation; either | version 2 of the License, or (at your option) any later version. | | This library is distributed in the hope that it will be useful, | but WITHOUT ANY WARRANTY; without even the implied warranty of | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | Library General Public License for more details. | | You should have received a copy of the GNU Library General Public | License along with this library; if not, write to the Free | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --------------------------------------------------------------------------*/ #include "../../out/config.h" #include #include #include #include #include #include #ifdef HAVE_FCNTL_H # include #endif #include #include extern int errno; /*------------------------------------------------------------------------- | nothing fancy here. enter your /dev/, speed, and a string to send out. | serial port is configed, string sent and a loop monitors for return data. --------------------------------------------------------------------------*/ int main() { char *port = "/dev/cua0"; int speed = 13; /*9600*/ char out[16]= "\x10\x0A\x02\x07\x00\xED\x10\x03"; struct termios ttyset; int ttyp = -1; char in[2]; if (ttyp < 0) { ttyp = open(port, O_RDWR|O_NDELAY); if(ttyp < 0){ printf("fopen() failed: %s\n",strerror(errno)); return(errno); } } if(tcgetattr(ttyp, &ttyset)< 0){ ttyp = -1; printf("tcgetattr() failed\n"); return(errno); } cfmakeraw(&ttyset); if (tcsetattr(ttyp, TCSAFLUSH, &ttyset) <0) { printf("tcsetattr() failed\n"); return(-1); } if (cfsetospeed(&ttyset, speed)<0) printf("set output speed failed\n"); if (cfsetispeed(&ttyset, speed)<0) printf("set input speed failed\n"); printf("Serial port initialized output speed=%d, input speed= %d \n", cfgetospeed(&ttyset), cfgetispeed(&ttyset)); write(ttyp, out,16); for(;;) if(read(ttyp,in,2)>0) printf("0x%02X\n",*in); }