- Hi @Corpse0327, and welcome to the Qt Dev Net! QSerialPort was designed for RS-232. Unfortunately, RS-232 and RS-485 are not compatible. You need to find a different way to talk to your fuel pump, as Qt does not provide the features you need.
- Serial Interfaces (RS232 and RS485) PCI Serial Interfaces 4-Port, RS-485. Qt 778981-01 NI PCI-8431/4 (RS485) 2 - 5 $ 495.00 Step 2: Select Optional Accessories.
- ., read sensors via TTL R4AVA07 7 Channel RS485 analog voltage sampler - Read 7 voltages vis RS485 PZEM-016 power sensor - Read mains voltage and current consumption vis RS485 Pelco-d PTZ control - Control pan tilt zoom via RS485 Huawei E3372 modem - Send sms via USB virtual serial port STM32 series WT Servo 16 - 16 channels servo motor.
- Analytics cookies. We use analytics cookies to understand how you use our websites so we can make them better, e.g. They're used to gather information about the pages you visit and how many clicks you need to accomplish a task.
The IFTOOLS MSB-RS485 module and the AWESOME multi-function software (!) are by far the best tool I’ve ever found for RS485 bus analysis in our serial networks. It is like going from dark night to sunshine; your RS485 analysis suite paid for itself many times over in the very first test session.
I've successfully read data from EKM metering by using Python as in http://forum.ekmmetering.com/viewtopic.php?f=4&t=3472 link.But before that I've tried to use C++ for a long time but it is unsuccessful. I follow this document http://www.chemie.fu-berlin.de/chemnet/ ... tml#SEC237, the below is my codeThe result is
pi@raspberrypi:~/solarD/src $ ./solar.out
Send result [17]
Read result [0]
pi@raspberrypi:~/solarD/src $ ./solar.out
Send result [17]
Read result [2] 30 30
But when I change code for canonical mode of POSIX There are not thing display because program is waiting data from serial portSend result [17]
Read result [0]
pi@raspberrypi:~/solarD/src $ ./solar.out
Send result [17]
Read result [2] 30 30
And when I dump serial port, it show me that there are something has received as below
pi@raspberrypi:~ $ tail -f /dev/ttyUSB0
00000001766100000000000000000000000000000000000000000000000000000000000000000000000000000002320000000000000000000000000000000000000000000000000000C000C000C0000000000011512080313555702000000000000000000000000000000000000000000000000000000000000!
=00000001766100000000000000000000000000000000000000000000000000000000000000000000000000000002324000000000000000000000000000000000000000000000000000C000C000C0000000000011512080313560302000000000000000000000000000000000000000000000000000000000000!
00000001766100000000000000000000000000000000000000000000000000000000000000000000000000000002320000000000000000000000000000000000000000000000000000C000C000C0000000000011512080313555702000000000000000000000000000000000000000000000000000000000000!
=00000001766100000000000000000000000000000000000000000000000000000000000000000000000000000002324000000000000000000000000000000000000000000000000000C000C000C0000000000011512080313560302000000000000000000000000000000000000000000000000000000000000!
![Rs485 serial connection Rs485 serial connection](/uploads/1/1/9/5/119585290/191033021.png)
Anyone can suggest me how can I fix it.
Shows how to use the synchronous API of QSerialPort in a non-GUI thread.
Blocking Slave shows how to create an application for a serial interface using QSerialPort's synchronous API in a non-GUI thread.
QSerialPort supports two general programming approaches:
- The asynchronous (non-blocking) approach. Operations are scheduled and performed when the control returns to Qt's event loop. QSerialPort emits a signal when the operation is finished. For example, QSerialPort::write() returns immediately. When the data is sent to the serial port, QSerialPort emits bytesWritten().
- The synchronous (blocking) approach. In non-GUI and multithreaded applications, the
waitFor...()
functions can be called (i.e. QSerialPort::waitForReadyRead()) to suspend the calling thread until the operation has completed.
In this example, the synchronous approach is demonstrated. The Terminal example illustrates the asynchronous approach.
The purpose of this example is to demonstrate a pattern that you can use to simplify your serial programming code, without losing responsiveness in your user interface. Use of Qt's blocking serial programming API often leads to simpler code, but because of its blocking behavior, it should only be used in non-GUI threads to prevent the user interface from freezing. But contrary to what many think, using threads with QThread does not necessarily add unmanageable complexity to your application.
This application is a Slave, that demonstrate the work paired with Master application Blocking Master Example.
The Slave application is receives the request via serial port from the Master application and send a response to it.
Rs232 Vs Rs485
We will start with the SlaveThread class, which handles the serial programming code.
SlaveThread is a QThread subclass that provides an API for receive requests from Master, and it has signals for delivering responses and reporting errors.
You should be call startSlave() to startup Slave application. This method transfers to the SlaveThread desired parameters for configure and startup the serial interface. When SlaveThread received from Master any request then emitted the request() signal. If any error occurs, the error() or timeout() signals is emitted.
It's important to notice that startSlave() is called from the main, GUI thread, but the response data and other parameters will be accessed from SlaveThread's thread. SlaveThread's data members are read and written from different threads concurrently, so it is advisable to use QMutex to synchronize access.
The startSlave() function stores the serial port name, timeout and response data, and QMutexLocker locks the mutex to protect these data. We then start the thread, unless it is already running. QWaitCondition::wakeOne() will be discussed later.
In the run() function, start by acquiring the mutex lock, fetch the serial port name, timeout and response data from the member data, and then release the lock again. Under no circumstance should the method
startSlave()
be called simultaneously with a process fetching these data. QString is reentrant but not thread-safe, and it is not recommended to read the serial port name from one startup, call and timeout or response data of another. SlaveThread can only handle one startup at a time.The QSerialPort object we construct on stack into run() function before loop enter:
This allows us once to create an object, while running loop, and also means that all the methods of the object will be executed in the context of the run() thread.
In the loop, check whether the name of the serial port for the current startup has changed or not. If it has, re-open and reconfigure the serial port.
The loop will continue waiting for request data:
Warning: The method waitForReadyRead() should be used before each read() call for the blocking approach, because it processes all the I/O routines instead of Qt event-loop.
The timeout() signal is emitted if error occurs when reading data.
After a successful read, try to send a response and wait for completion of the transfer:
Warning: The method waitForBytesWritten() should be used after each write() call for the blocking approach, because it processes all the I/O routines instead of Qt event-loop.
The timeout() signal is emitted if an error occurs when writing data.
Rs485 Connector
After a successful writing is emitted, request() signal containing the data received from the Master application:
Rs485 Serial Cable
Next, the thread switches to reading the current parameters for the serial interface, because they can already have been updated, and run the loop from the beginning.
Running the Example
To run the example from Qt Creator, open the Welcome mode and select the example from Examples. For more information, visit Building and Running an Example.
See also Terminal Example and Blocking Master Example.
Rs485 Cable
© 2020 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.