ACE under serial programming
First look at the relevant classes, under the ACE is very simple to use, followed by an instance of the ace comes with.
/**
* @class ace_tty_io
*
* @brief class definitions for platform specific TTY features.
*
* This class represents an example interface for a specific
* device (a serial line). It extends the capability of the
* underlying Dev_io class by adding a control method that takes
* a special Struc Ture (serial_params) as argument to allow a
* Comfortable user interface (away from that annoying termios
* struc Ture, which is very specific to UNIX).
*/
what is a TTY. TTY is the general term of the terminal equipment, the word TTY originates from teletypes, or teletypewriters, originally refers to the telex typewriter, is through the serial line with the printer keyboard through reading and sending information things, later this thing was replaced by keyboard and display, So now call terminal more appropriate. This ace_tty_io class in Ace is not long, so take a look here.
Class Ace_export ace_tty_io:public Ace_dev_io {public:enum Control_mode {setparams,///< Set
Control parameters.
Getparams///< Get control parameters.
};
struct Ace_export serial_params {serial_params (void); /** Specifies the baudrate at which the Communnication Port operates.
*/int baudrate; /** Specifies the minimum number of bytes in input buffer before XON char is sent. Negative value indicates that default value should is used (WIN32).
*/int Xonlim; /** Specifies the maximum number of bytes in input buffer before XOFF char is sent. Negative value indicates that default value should is used (WIN32).
*/int Xofflim; /** Specifies the minimum number of characters for non-canonical read (POSIX).
*/unsigned int readmincharacters; /** Specifies the time to wait before returning from read. Negative value means infinite timeout. */INT Readtimeoutmsec; /** enable/disable parity checking.
*/bool Parityenb; /** Specifies the parity mode.
POSIX supports "even" and "odd" parity. Additionally Win32 supports "mark" and "space" parity modes.
*/const char *paritymode; /** Enable & Set CTS mode. Note that RTS & CTS was enabled/disabled together on some systems (Rts/cts is enabled if either <co De>ctsenb</code> or <code>rtsenb</code> is set).
*/bool Ctsenb; /** Enable & Set RTS mode. Note that RTS & CTS was enabled/disabled together on some systems (Rts/cts is enabled if either <co
De>ctsenb</code> or <code>rtsenb</code> is set).
-0 = Disable RTS.
-1 = Enable RTS.
-2 = Enable RTS flow-control handshaking (Win32). -3 = Specifies that RTS line would be is high if bytes is available for transmission. After transmission RTS would be is low (WIN32).
*/ int Rtsenb; /** enable/disable software flow control on input.
*/bool Xinenb; /** enable/disable software flow control on output.
*/bool Xoutenb; /** Specifies if device is a modem (POSIX). If not set modem status lines is ignored.
* * BOOL Modem; /** enable/disable Receiver (POSIX).
*/bool Rcvenb; /** Controls whether DSR is disabled or enabled (WIN32).
*/bool Dsrenb; /** Controls whether DTR is disabled or enabled.
*/bool dtrdisable; /** Data bits.
Valid values 5, 6, 7, and 8 data bits. Additionally WIN32 supports 4 data bits.
*/unsigned char databits; /** Stop bits. Valid values is 1 and 2.
*/unsigned char stopbits;
}; /** Interface for reading/writing serial device parameters.
*/int control (control_mode cmd, serial_params *arg) const; #if defined (ace_needs_dev_io_conversion)/** this was necessary to pass Ace_tty_io as parameter to Dev_connector.
*/Operator Ace_dev_io & (); #endif/* ace_needs_dev_io_conversion *};
Ace's read demo, where directory Ace_wrappers\examples\ipc_sap\dev_sap
#include "ace/dev_addr.h" #include "ace/dev_connector.h" #include "ace/tty_io.h" int ace_tmain (int argc, Ace_tchar *argv
[]) {if (ARGC < 2) Ace_error_return ((Lm_error, Ace_text ("Usage:%s device-filename\n"),
Argv[0]), 1);
Ace_tty_io Read_dev;
Ace_dev_connector con;
if (Con.connect (Read_dev, Ace_dev_addr (argv[1])) = =-1) ace_error_return ((Lm_error,
Ace_text ("%p\n"), Argv[1]), 1);
Ace_tty_io::serial_params Myparams;
Myparams.baudrate = 19200;
Myparams.xonlim = 0;
Myparams.xofflim = 0;
myparams.readmincharacters = 0; Myparams.readtimeoutmsec = 10*1000;
Ten seconds Myparams.paritymode = "even";
Myparams.ctsenb = false;
Myparams.rtsenb = 0;
Myparams.xinenb = false;
Myparams.xoutenb = false;
Myparams.modem = false;
Myparams.rcvenb = true;
Myparams.dsrenb = false; Myparams.dtRdisable = false;
Myparams.databits = 8;
Myparams.stopbits = 1; if (Read_dev.control (ace_tty_io::setparams, &myparams) = =-1) ace_error_return ((lm_error
, Ace_text ("%p control\n"), Argv[1]), 1);
Read till character ' Q '.
for (char readback = ' x '; Readback! = ' Q ';)
{ssize_t Bytes_read = READ_DEV.RECV ((void *) &readback, 1);
if (Bytes_read = = 1) ace_debug ((Lm_debug, Ace_text ("read:%c\n"),
Readback));
else if (Bytes_read = = 0) ace_debug ((Lm_debug, Ace_text ("timeout!\n"));
else if (Bytes_read = =-1) ace_error_return ((Lm_error, Ace_text ("%p recv\n"),
ARGV[1]), 1);
} return 0; }