Repository navigation
Plugin rs485 communication
Provides a central RS485 worker and FIFO rs485_queue for OSPy plug-ins, with Waveshare CH343G auto-detection, status monitoring and adapter testing.
| Item | Value |
|---|---|
| Version | 1.0.3 |
| Category | Automation and integrations |
| Author | Martin Pihrt |
| License | GPL-3.0 |
| OSPy |
3.0.211 or newer |
| Python |
3.8 or newer |
| Permissions | system |
| Hardware | platforms: raspberry_pi, beaglebone, linux; interfaces: serial
|
| Dependencies | None |
| Python/OS packages |
serial / pyserial (required) |
| Interfaces | Mobile API v1 |
| Source | Open the plug-in directory |
Provides a central RS485 worker and FIFO rs485_queue for OSPy plug-ins, with Waveshare CH343G auto-detection, status monitoring and adapter testing.
Central RS485 communication plug-in for OSPy.
The plug-in owns one serial RS485 interface and provides one public FIFO queue (rs485_queue) for all other OSPy plug-ins. It is intended primarily for the Waveshare industrial USB TO RS485 (B) adapter based on the WCH CH343G chip.
- Enable/disable the RS485 worker.
- Automatic Waveshare CH343G detection (USB VID:PID
1A86:55D3). - Manual Linux serial port selection (
/dev/ttyACM0,/dev/serial/by-id/..., etc.). - Configurable baud rate, data bits, parity, stop bits and timeouts.
- Background Modbus discovery using address 255 broadcast probes, addresses 1-254, functions 03 and 04, one- and two-register reads, common sensor baud rates and 8N1/8E1/8O1 framing, with live test details and validated response frames.
- Live state: Disabled / Waiting / OK / Communicating / Error.
- Shows detected and active port, device description, USB ID, last communication, last client plug-in and TX/RX counters.
- Safe adapter test (USB discovery + opening the selected serial port).
- Public
rs485_queueFIFO: all clients are processed one by one by one worker. - Queue diagnostics: waiting jobs, current client/operation, completed/error counters, peak queue depth and last queue wait time.
- Synchronous and asynchronous transaction API.
- Atomic callback API for protocols that need several write/read operations.
- OSPy
health()diagnostics hook. - CSRF-protected settings/actions and gettext-ready UI strings.
The serial format is a property of the complete physical bus, so every device connected to the same A/B pair normally has to use the configured values. The default is 4800 baud, 8 data bits, no parity, 1 stop bit (4800 8N1), matching the factory setting documented for the ZTS-3000-FSJT wind sensor. Changing this setting changes how OSPy opens the USB adapter; it does not reconfigure a slave device. A device-specific plug-in must send the documented protocol command before both sides are switched to a new speed.
Requires pyserial (serial Python module). The plug-in manifest declares this dependency.
The recommended interface is the single queue object:
from plugins.rs485_communication import rs485_queuereply = rs485_queue.transaction(
request=request_frame,
response_length=expected_bytes,
client='My OSPy plug-in',
clear_input=True,
delay=0.05,
)job = rs485_queue.submit_transaction(
request=request_frame,
response_length=expected_bytes,
client='My OSPy plug-in',
)
### The worker executes queued jobs in FIFO order.
reply = job.wait(timeout=3)def protocol_exchange(ser):
ser.reset_input_buffer()
ser.write(frame_1)
ser.flush()
first = ser.read(8)
ser.write(frame_2)
ser.flush()
second = ser.read(8)
return first, second
first, second = rs485_queue.call(
protocol_exchange,
client='My protocol plug-in',
)The callback is executed by the RS485 worker. No other queued plug-in can access the bus until it returns.
Convenience helper functions are also exported: rs485_transaction(), rs485_write(), rs485_read() and rs485_call(). They all use rs485_queue; they do not bypass it.
Do not open the same /dev/tty* interface directly from dependent plug-ins.
Frames, fixed-length reads and delimiter reads are bounded to 65,536 bytes and transaction delays are bounded to 30 seconds. These limits prevent a faulty dependent plug-in from reserving excessive memory or monopolizing the shared worker indefinitely.
Opening the USB serial port confirms OS/driver/permissions and serial configuration. It cannot prove RS485 A/B wiring or a slave response without transmitting a protocol-specific request. Protocol-specific tests belong in the dependent device plug-in.
The following notes are generated from the help page shipped with this plug-in. Field names are also explained directly in the OSPy settings page.
This plug-in provides one shared RS485 serial interface for OSPy and other plug-ins. It is designed primarily for the Waveshare industrial USB TO RS485 (B) adapter with the CH343G USB chip.
The adapter uses a WCH CH343G USB interface and an SP485EEN RS485 transceiver. It converts USB to a two-way, half-duplex RS485 connection and controls the transmit/receive direction automatically in hardware.
-
RS485 terminals: A+, B- and GND; USB-A host connection and 5 V USB power.
-
Supported communication speed: 300 baud to 3 Mbps.
-
Approximate RS485 reach: up to 1.2 km at a suitably low speed and with correct bus wiring.
-
Point-to-multipoint operation for up to 32 nodes; a repeater is recommended by the vendor for 16 or more nodes.
-
Automatic direction control, built-in 120 ohm matching resistor, resettable fuse, TVS surge protection and ESD protection.
-
PWR, TXD and RXD LEDs indicate power and communication activity.
Product information and specifications on RPishop.cz
-
Connect the USB adapter to the Raspberry Pi.
-
Connect RS485 A+ to A / D+ / 485+ of the target device.
-
Connect RS485 B- to B / D- / 485- of the target device.
-
Connect GND when required by the installation and the target device documentation.
The default value auto searches specifically for a WCH CH343G adapter. On Raspberry Pi it normally appears as /dev/ttyACM0. You can also enter a fixed path manually, including a /dev/serial/by-id path.
The selected baud rate and serial format apply to the complete physical bus. All devices connected to the same A/B pair normally have to use the same values. The default 4800 8N1 matches the documented factory setting of the ZTS-3000-FSJT wind sensor.
Important Saving a new speed changes how OSPy opens the USB adapter; it does not change a slave device. A device-specific plug-in must first send the documented configuration command and then switch the bus to the same speed.
The Test adapter button verifies that the USB serial adapter is detected and that OSPy can open the selected serial port with the configured parameters. The test intentionally sends no arbitrary bytes to the live RS485 bus.
Important A successful adapter test does not prove A/B wiring or communication with a slave device. A complete RS485 line test requires a responding device or a second RS485 adapter.
All dependent plug-ins should use the public rs485_queue object. Requests are processed in FIFO order by one worker, so two plug-ins cannot transmit on the half-duplex RS485 bus at the same time.
Synchronous transaction
Asynchronous queued transaction
Atomic multi-step protocol
Use call() when one protocol operation needs several writes and reads. The callback runs entirely inside the RS485 worker and remains atomic with respect to other queued plug-ins.
The settings page shows the current queue depth, active queue client, completed/error counters, peak queue depth and the last queue waiting time.
Check OSPy → Diagnostics first and remove passwords, tokens, private addresses and other secrets before sharing logs. Report reproducible plug-in problems in the OSPy-plugins issue tracker.
Start
Reference
Catalog sections


