BLOK MASTER SERIAL
DOWNLOAD ===> https://cinurl.com/2t8b4K
The purpose of this example is to demonstrate how to simplify your serial programming code without losing the responsiveness of the user interface. The blocking serial programming API often leads to simpler code, but it should only be used in non-GUI threads to keep the user interface responsive.
MasterThread is a QThread subclass that provides API for scheduling requests to the slave. This class provides signals for responding and reporting errors. The transaction() method can be called to start up the new master transaction with the desired request. The result is provided by the response() signal. In case of any issues, the error() or timeout() signal is emitted.
The transaction() method stores the serial port name, timeout and request data. The mutex can be locked with QMutexLocker to protect this data. The thread can be started then, unless it is already running. The wakeOne() method is discussed later.
Under no circumstance should the transaction() method be called simultaneously with a process fetching the data. Note, while the QString class is reentrant, it is not thread-safe. Thereby, it is not recommended to read the serial port name in a request thread, and timeout or request data in another thread. The MasterThread class can only handle one request at a time.
The function block ModbusRtuMaster_KL6x22B implements a Modbus master that communicates via a serial Bus Terminal KL6021 or KL6041. The block is not called in its basic form, but individual actions of that block are used within a PLC program. Each Modbus function is implemented as an action.
On a serial bus, a single signal often includes address, control, data, and clock information. This can make isolating events of interest difficult. Optional serial applications transform the oscilloscope into a robust tool for debugging serial buses with automatic decode and analysis for I2C, SPI, eSPI, CAN, CAN FD, LIN, FlexRay, 100BASE-T1, SENT, RS-232/422/485, UART, USB 2.0 (LS, FS, HS), Ethernet, I3C, SPMI, Spacewire, 8b10b, NRZ, MIL-STD-1553, ARINC 429, I2S, LJ, RJ, PSI5, CPHY, CXPI, DPHY, SMBus, 1-WIRE, EtherCAT, and TDM.
The serial applications support automatic trigger and decode for I2C, SPI, CAN, CAN FD, LIN, FlexRay, 100BASE-T1, SENT, RS-232/422/485, UART, USB 2.0 (LS, FS, HS), Ethernet, I3C, SPMI, Spacewire, 8b10b, NRZ, MIL-STD-1553, ARINC`429, I2S, LJ, RJ, PSI5, SMBus, EtherCAT, and TDM buses, making it easier to locate, analyze, and debug events of interest.
Trigger on packet content such as start of packet, specific addresses, specific data content, unique identifiers, etc. on popular serial interfaces such as I2C, SPI, CAN, CAN FD, LIN, FlexRay, SENT, RS-232/422/485, UART, USB 2.0, Ethernet, I3C, SPMI, MIL-STD-1553, ARINC 429, I2S, LJ, RJ, PSI5, and TDM.
Let the oscilloscope with a serial application do it for you! Once you've set up a bus, the oscilloscope decodes each packet on the bus, and displays the value in hex, binary, ASCII, or decimal (certain buses only) in the bus waveform.
Serial bus type 3 Series MDO Option 4 Series MSO Option 5 Series MSO Option 6 Series MSO Option Description MIL-STD-1553, ARINC 429 3-SRAERO 4-SRAERO 5-SRAERO 6-SRAERO Aerospace Serial Triggering and Analysis (MIL-STD-1553, ARINC 429). Enables triggering on packet-level information on MIL-STD-1553 and ARINC 429 buses as well as analytical tools such as digital views of the signal, bus views, packet decoding, search tools, and packet decode tables with time stamp information. I2S, LJ, RJ, TDM 3-SRAUDIO 4-SRAUDIO 5-SRAUDIO 6-SRAUDIO Audio Serial Triggering and Analysis (I2S, LJ, RJ, TDM). Enables triggering on packet-level information on serial audio buses as well as analytical tools such as digital views of the signal, bus views, packet decoding, search tools, and packet decode tables with time stamp information. 8b10b N/A N/A 5-SR8B10B 5-SR8B10B 8B10B Serial Decoding and Analysis. Enables decoding and searching the packet-level information on buses with analytical tools such as digital views of the signal, bus views, packet decoding, search tools, and packet decode tables with time stamp information. Finds and displays parity error if found in 4-bit or 6-bit for the 10-bit symbol in 8b10b. NRZ N/A 4-SRNRZ 5-SRNRZ 6-SRNRZ NRZ Serial Decoding and Analysis. Enables decoding and searching the packet-level information on buses with analytical tools such as digital views of the signal, bus views, packet decoding, search tools, and packet decode tables with time stamp information. Variants like NRZ-I, NRZ-M, NRZ-S, and NRZ-C are not supported currently. Supports only NRZ with normal and inverted polarity with Bit Order (MSB or LSB First). CAN, CAN FD, LIN, FlexRay 3-SRAUTO 4-SRAUTO 5-SRAUTO 6-SRAUTO Automotive Serial Triggering and Analysis (CAN, CAN FD, LIN, FlexRay). Enables triggering on packet-level information on CAN/CAN FD/LIN/FlexRay buses as well as analytical tools such as digital views of the signal, bus views, packet decoding, search tools, and packet decode tables with time stamp information. Automotive 100BASE-T1 N/A N/A 5-SRAUTOEN1 6-SRAUTOEN1 100BASE-T1 Automotive Ethernet serial analysis. SENT N/A 4-SRAUTOSEN 5-SRAUTOSEN 6-SRAUTOSEN Automotive Sensor Serial Triggering and Analysis (SENT). Enables triggering on packet-level information on SENT buses as well as analytical tools such as digital views of the signal, bus views, packet decoding, search tools, and packet decode tables with time stamp information. RS-232/422/485, UART 3-SRCOMP 4-SRCOMP 5-SRCOMP 6-SRCOMP Computer Serial Triggering and Analysis (RS-232, RS-422, RS-485, UART). Enables triggering on packet-level information on RS-232/422/485 and UART buses as well as analytical tools such as digital views of the signal, bus views, packet decoding, search tools, and packet decode tables with time stamp information. I 2C, SPI 3-SREMBD 4-SREMBD 5-SREMBD 6-SREMBD Embedded Serial Triggering and Analysis (I2C, SPI). Enables triggering on packet-level information on I2C and SPI buses as well as analytical tools such as digital views of the signal, bus views, packet decoding, search tools, and packet decode tables with time stamp information. Ethernet N/A 4-SRENET 5-SRENET 6-SRENET Ethernet Serial Triggering and Analysis (10BASE-T, 100BASE-T). Enables triggering on packet-level information on Ethernet buses as well as analytical tools such as digital views of the signal, bus views, packet decoding, search tools, and packet decode tables with time stamp information. I3C N/A 4-SRI3C 5-SRI3C 6-SRI3C I3C Serial Decoding and Analysis. Enables decoding and searching on packet-level information on MIPI I3C buses with analytical tools such as digital views of the signal, bus views, packet decoding, search tools, and packet decode tables with time stamp information. SPMI N/A 4-SRPM 5-SRPM 6-SRPM Power Management Serial Triggering and Analysis (SPMI). Enables triggering on packet-level information on SPMI buses as well as analytical tools such as digital views of the signal, bus views, packet decoding, search tools, and packet decode tables with time stamp information. Spacewire N/A 4-SRSPACEWIRE 5-SRSPACEWIRE 6-SRSPACEWIRE Spacewire serial analysis. Enables decoding and analysis on Spacewire buses. USB 2.0 3-SRUSB2 4-SRUSB2 5-SRUSB2 6-SRUSB2 USB 2.0 Serial Triggering and Analysis (LS, FS, HS). Enables triggering on packet-level information on USB 2.0 buses as well as analytical tools such as digital views of the signal, bus views, packet decoding, search tools, and packet decode tables with time stamp information. Serial options bundle 3-BND N/A N/A N/A Adds all serial analysis options and the power analysis option available for an instrument. PSI5 N/A 4-SRPSI5 5-SRPSI5 6-SRPSI5 PSI5 Serial Decoding (v1.3 and 2.1) and analysis. Enables decoding and Search Packet level information with analytical tools such as digital views of the signal, bus views, packet decoding, search tools, and packet decode tables with time stamp information. MDIO N/A 4-SRMDIO 5-SRMDIO 6-SRMDIO MDIO Protocol Decoder and Search, No Hardware Trigger; Node locked SVID N/A 4-SRSVID 5-SRSVID 6-SRSVID SVID Protocol Decoder and Search, No Hardware Trigger; Node locked e-USB2 N/A 4-SREUSB2 5-SREUSB2 6-SREUSB2 eUSB2 Protocol Decoder and Search; Node locked
For working programming examples on how to send or receive bytes, please see the built in Example Finder (Help menu -> Find Examples...). Click on the Search tab and search for the keyword "serial". I recommend the Basic Serial Write and Read, Basic 2 Port Serial Write And Read and Advanced Serial Write and Read examples.
the problem you mentioned (variable package size) is exactly why the correct approach will be to use a loop to receive the bytes from the serial line, a separate loop to parse the bytestream into separate packages, and another loop to process the data.
Let's see the example I suggested earlier. The upper loop is there only to simulate the equipment that is sending the data, so you won't need it if you have real equipment to receive data from. If you want to use real serial data you will have to replace the Dequeue Element function in the "get byte"case with the VISA Read function and read the serial port one byte at a time. The shift register named Buffer will collect the bytes until a full package is received. The "Check" state will decide if you have a complete package in the buffer or not. You will have to modify the logic in the "Check" case to detect the packet borders according to your specifications. If a complete package is received, the state machine will go to the "Packet received"state. The "packet received" case will send the package to the processing loop through a queue.
I noticed that possibly you would like to deal with your serial input as a series of bytes instead of a continuous string. If that is the case you can use the String To Byte Array function (String -> Conversion palette) at the beginnig of your processing pipeline. This will require some rearchitecturing of the code, but the result will be much cleaner. This way you will have access to every single byte in the stream and you won't have to deal with string scanning, whitespace characters, etc. If you wish to interpret some part of your input as a continuous string you can convert it back with the Byte Array To String function (same palette). 2b1af7f3a8