Serial port expanding enumerator example
I am trying to expand the enumerator example and create a Serial Port object. I try then to invoke some QSerialPort member-functions using that object but I get some errors. Eventually I would like to send some data via COM4. See image: http://s29.postimg.org/yq4mgwe2f/Build_Errors_1_1_16.jpg
You need to include
You have only QSerialPortInfo so It dont know serial port
in your code and that it was it means with incomplete type. :)
I have added some lines to the code and got some errors. See image
Is the following sequence correct? 1)set port name 2)open the port 3) write data 4) close the port
- COM4 is not a string, put it between quotes
- use write and with a QByteArray
Also, add a check that open is successful. That way you are sure the port is open and the rest of the code should work.
I added the following lines of code and now runs successfully. see lines 34-55
The check I have to verify that port COM4 is open gives false so the program stacks at while loop.
Do I need to use the setPort() as well?
What does the setPortName() does?
That's not a check, it's just a blocking while loop. If it can't be opened the first time, the chances are unlikely that it will become later.
Just use an if and print the error string so you will know what is happening.
I use a usb to serial TTL FTDI cable (TTL-232RG-VIP-WE) connected to COM4.
It seems that the port doesn't open.
How to print the error string?
qDebug() << serialPort.errorString();
It doesn't open COM4.
You're opening it twice
I commented line 49 and now it opens the port and transmits the data.(data need to be captured in scope)
I will mark this as an answer.
I will be creating another question in order to design a minimum gui that selects baud rate, stop bits and data bits and then transmits data that have been placed to a text box. Probably I will be needing your help. I have been reading for the last year C++ and recently I have ordered book by Jasmin Blanchette.
The Terminal example that comes with Qt has dialog for selecting
Its minimal sample and sounds a lot like what u need.
hi will check