how to write characters to serial port

I have an ancient serial spectrometer which only runs on win9x. I want to convert to a Linux system, but the existing software is proprietary and wont work. I was able to access a console internally on the spectrometer. The console takes keyboard character commands, and sends the output to the serial port.

in vb6 I can write to the com port with char values using ComPort.Write(Chr(34))

I am interested in using Qt for the interface, how can I send something to the same effect as ComPort.Write(Chr(34)) using qt?

1 Answer

  • Here an example from Qt official site (C++)

  • If Visual Basic is your background you may prefer Gambas3

    Gambas have similar syntax of Visual Basic(VB), and support Qt as GUI tool kit.

    See

  • In Linux/BSD, Serial port is more accessible then windows. So you can even write to it from shell/terminal, or use system call from most programming languages.

    Example in shell with an Android phone as modem, it may help for debugging:

    1. Reading serial port (need to be root):

      sudo su
      cat /dev/ttyACM0

      As you can read just few lines as needed:

      head -n2 /dev/ttyACM0
    2. Writing serial, Open other terminal tab or window:

      sudo su
      echo -e "AT" > /dev/ttyACM0

      It shows OK on reading port window, Also you can sent hexadecimal data (use -n option to avoid sending new line at the end)

      echo -e -n "\x41\x54\x0a" > /dev/ttyACM0

      same as:

      echo -e "\x41\x54" > /dev/ttyACM0

      Shell will show undisplayed hex as small square with its value written inside it. Try this.

      echo -e "\x13"

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like