28 lines
517 B
C++
28 lines
517 B
C++
|
#include <iostream>
|
||
|
#include <serial.h>
|
||
|
|
||
|
using namespace cppbox;
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
char buffer[512]{};
|
||
|
|
||
|
CSerialOpr opr;
|
||
|
|
||
|
opr.set_baudrate(19200);
|
||
|
opr.set_data_bits(DataBits::D8);
|
||
|
opr.set_flow_control(FlowControl::NoFlowControl);
|
||
|
opr.set_parity(Parity::EvenParity);
|
||
|
opr.set_port("COM2");
|
||
|
opr.set_timeout(10 * 1000);
|
||
|
opr.set_stop_bits(StopBits::OneStop);
|
||
|
|
||
|
if (opr.open() != 0) {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
int read_size = opr.read(buffer, sizeof(buffer));
|
||
|
|
||
|
|
||
|
return 0;
|
||
|
}
|