#ifndef SERIAL_CHANNEL_HH #define SERIAL_CHANNEL_HH #include #include #include #include #include #include #include #include #include #include "Constants.hh" #include "Channel.hh" #include "Semaphore.hh" void fd_zero_function( fd_set* fds ) { FD_ZERO( fds ); }; void fd_set_function( int id, fd_set* fds ) { FD_SET( id, fds ); }; /** * Each of the Set commands is mapped to a terminal command, changing the * attributes of the device. Each of the terminal commands is mapped to an * ioctl() command but configuration is easier to deal with at the higher * level. */ template class SerialChannel : public Channel { public: SerialChannel (int port, int baud, const char* serialName = "SerialChannel"); ~SerialChannel (); STATUS Open (); STATUS Close (); STATUS Read (Dtype message, long length, int timeout); STATUS Read (Dtype message, long length); STATUS Write (Dtype message, long length); bool IsOpen (); int getComPort (); int FlushIn (); int FlushOut (); protected: int id; int comPort; int baudRate; int bytesSent, bytesReceived; int isOpen; // has the serial port been opened? struct termios oldConfig, newConfig; // for configuration restoration }; #include "SerialChannel.icc" #endif /* SERIAL_CHANNEL_HH */