Read and Write on serial port in Ubuntu with C/C++ and LibSerial

后端 未结 2 1313
我寻月下人不归
我寻月下人不归 2020-12-05 21:48

I\'m using LibSerial on Ubuntu to read and write data on serial port.

At the moment, I\'m able to write and receive strings over the serial port, but my code does no

2条回答
  •  天涯浪人
    2020-12-05 22:27

    Using try and catch would be helpful. :)

    Try this: A global pointer SerialPort *pu was already declared and the port was opened.

    int rxstring(char *cstr, unsigned int len, bool print_str)
    
    {
    
    char temp=0;
    int i=0;
    while(temp!='\n')
    {
        try
        {
            temp=pu->ReadByte(100);
        }
        catch(SerialPort::ReadTimeout &e)
        {
            //cout<<"Read Timeout"<

    Reference: http://libserial.sourceforge.net/doxygen/class_serial_port.html#a15

提交回复
热议问题