Serialib is a cross-platform library written in C++.
The library has been tested on Windows and Linux. This project has been developed with Qt Creator and succesfully compile with:
serialib()
openDevice()
closeDevice()
writeChar()
writeString ()
writeBytes ()
readChar()
readString()
readBytes()
flushReceiver()
available()
DTR()
setDTR()
clearDTR()
RTS()
setRTS()
clearRTS()
isRI()
isDCD()
isCTS()
isDSR()
isRTS()
isDTR()
This first example send a section of the ASCII table on the serial device:
// Connection to serial port
serialib serial;
if (serial.openDevice("/dev/ttyACM0", 115200)!=1) return 1;
// Display ASCII characters (from 32 to 128)
for (int c=32;c<128;c++)
{
serial.writeChar(c);
usleep(10000);
}
// Close the serial device
serial.closeDevice();
This example has been tested with the Arduino TFT terminal:
This second example set DTR and unset RTS before displaying input pins status:
// Connection to serial port
serialib serial;
if (serial.openDevice("COM1", 115200)!=1) return 1;
// Set DTR and unset RTS
serial.DTR(true);
serial.RTS(false);
// Loop forever and display pin status
while (1)
{
// Read and display the status of each pin (DTR should be 1, RTS should be 0)
printf ("4-DTR=%d\t", serial.isDTR());
printf ("7-RTS=%d\t", serial.isRTS());
printf ("1-DCD=%d\t", serial.isDCD());
printf ("8-CTS=%d\t", serial.isCTS());
printf ("6-DSR=%d\t", serial.isDSR());
printf ("9-RING=%d\n", serial.isRI());
}
Serialib can be downloaded with one of the following links: