QSerialPort signals and slots broadcasting
-
Im sharing one QSerialport between 4 place in app, im using tcpsocket to so i made connectivity class for communication select.
class Connectivity : public QObject { Q_OBJECT public: int connectionType = 1; SerialThread *serial; //I need in this app for sure. TCP *tcp; ... ctor ... connect(serial, SIGNAL(connected()), this, SLOT(onConnected()), Qt::QueuedConnection); connect(serial, SIGNAL(disconnected()), this, SLOT(onDisconnected()), Qt::QueuedConnection); connect(serial, SIGNAL(response(QString)), this, SLOT(onResponse(QString)), Qt::QueuedConnection); connect(serial, SIGNAL(error(QString)), this, SLOT(onError(QString)), Qt::QueuedConnection); connect(serial, SIGNAL(timeout(QString)), this, SLOT(onTimeout(QString)), Qt::QueuedConnection); ...
I need good way to brooadcast anserws between that 4 places. Maybe make it in Connectivity object slots?
thx
-
@qtprogrammer123
Yes, that will work fine.
Its called a token design so whoever has the token, will get the reply.So last one to use sendMsg, will get next reply or all replies until someone else
use sendMsg. -
Hi
How do you know where the reply belongs?
Is there some ID in data or how do you tell the places apart?
OR do you want all places to get all answers at the same time? -
@qtprogrammer123 said in QSerialPort signals and slots broadcasting:
Im sharing one QSerialport between 4 place in app,
just to clarify,
do you mean 1 app, 4 places
or
4 apps 1 Serialport?
-
1 app 4 places: console, one object communication, second object communication...
-
@qtprogrammer123
But do you want all places to get same reply ?
Els you need a way to know what reply goes where.
If its ok that all get the same data, then a signal will do just fine. -
I want reply only in one place - to place from i send data. ouu its sync communication
-
@qtprogrammer123
well then you can either let the Connectivity handle it
by having 4 signals for data
and only emit the right one for the sender
Or disconnect and connect the Senders when you switch betwen them.Can you tell from the data who should get it ? (i assume not)
-
Im think about make second param in sendMsg method with sender id, remeber it, and after response clean it. 3 objects replay similar data, and will be hard to select reciver by them, 4th sending big data in parts - send part, after recive OK, send next while data > 0
-
@qtprogrammer123
Yes, that will work fine.
Its called a token design so whoever has the token, will get the reply.So last one to use sendMsg, will get next reply or all replies until someone else
use sendMsg. -
ok ths for help.
-
ouuu one more, better way is using 4 separate signals for anserws, connect/disconnect them everytime, or reciving them in 4 places and check token? I think making 4 separate signal is best way - i will check token only once after recive and broadcast anserw
-
@qtprogrammer123
well 4 separate will make more simple.
and signals is not expensive so i would go for that.
and then depending on the token, simply emit different ones. -
ok ;] I think its all