Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Has anybody experience with MODBUS to read temp sensors?
#28
@Rudy M

Your current approach (continuous loop + _LIMIT pollHz!) is perfectly fine and is the simplest, most robust way to poll MODBUS sensors on a PC. For MODBUS RTU there is no “push” unless you enable auto-report, so polling is the normal model.

I would not use ON TIMER ... GOSUB for serial MODBUS polling. Reason: TIMER events can fire while you’re still reading/writing the port, which can create re-entrancy problems (overlapping requests, partial frames, CRC fails) unless you add a lock/busy flag and very careful buffering. A single-threaded main loop is safer.

Recommended pattern:

Keep a main loop that polls at a fixed rate: e.g. 2 Hz (every 0.5 s) or 1 Hz.

After each successful read, copy results into Temp!(0..7) (and maybe store a timestamp).

The rest of your program (control logic / GUI) just reads the latest Temp!() values. If a read fails, keep the old values and set an error flag or “age” counter.

So: if you want “every 0.5 seconds”, don’t use ON TIMER. Just set:

pollHz! = 2 (because 2 polls per second = 0.5 s)

or use Timer (not ON Timer but Timer only):

pseudocode:

If timer < oldtimer then

oldtimer = timer + .5
read and print temperatures

end if

Extra practical notes:

MODBUS requests should not be too fast; 0.5–1.0 s is a good start for stability.

If you later run multiple devices (relays + sensors) on the same RS485 bus, keep polling orderly: one request at a time, wait for reply, then next request.


Reply


Messages In This Thread
RE: Has anybody experience with MODBUS to read temp sensors? - by Petr - 02-24-2026, 05:47 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question How to read Google Calendar events? Ikerkaz 10 1,882 07-10-2023, 11:06 AM
Last Post: Ultraman
  SHELL creates unicode file, can't read correctly with LINE INPUT thesolarcode 3 1,248 05-06-2023, 09:41 PM
Last Post: thesolarcode
  Read / Allocate Cores dISP 10 2,231 04-25-2023, 12:23 PM
Last Post: dISP
  Can images be read from a file into an array? PhilOfPerth 11 2,560 02-17-2023, 03:31 AM
Last Post: TerryRitchie

Forum Jump:


Users browsing this thread: 1 Guest(s)