I
I
Ilia Zhitenev2016-03-26 13:52:27
Qt
Ilia Zhitenev, 2016-03-26 13:52:27

How to implement writing and reading COM port?

Hello. There is a device that needs to be controlled from a PC. The control is carried out using commands sent via the COM port via RS232. The device allows you to adjust the values ​​of several parameters. It can also return the current value on command. GUI I implement on Qt. How to process sliders and write a new value to the device - there are no problems with this. I process the valueChanged slot and write this value via RS.
In addition, I want to implement that the program sequentially asks all device parameters cyclically, thereby showing the most current values ​​​​on the monitor, and at the same time checking the connection with the device. Each window in the program is described by a class with the functions setParameter and getParameter - respectively, set a new value and read.
How to implement a cyclic polling of parameters, as well as writing new values ​​when the value of the slider changes? I correctly understand that it is necessary to use streams (thread)? What is the best way to use them? This is the first time I've encountered such a task, I have no experience. Advise how best to implement.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
Jacob E, 2016-03-26
@Zifix

Well, the easiest way is to make a timer that will start polling parameters at a certain interval.

A
Alexey Sergey, 2016-03-26
@dev_random

once did the following for something like this:
there is a data structure that represents device parameters;
there is a class that stores two instances of structures with parameters: in the first instance, the data read from the device. in the second - the data that the user has set.
Next, on a timer or via QThread, the class iterates, consisting of:
1. polling the device
2. sending the desired configuration to the device.
in my case, there were not very many parameters (about 7) and reading / writing all parameters was performed in one line. Worked quite fast, delays are not noticeable.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question