FHEM > English Corner

Devio run SimpleRead before SimpleWrite

(1/2) > >>

I'm trying to write my first module that connects and receives data hexadecimally through Devio.pm.
How to make the listener run for 1 second.
Because at this point if I run SimpleRead and after that run SimpleRead then I get exception/"DISCONNECTED" because I don't get any response back.
I would need to do a scenario like this:
- I set up a connection (it works)
- listener 1sec DevIo_SimpleRead
- immediately after the listener starts DevIo_SimpleWrite

Is this a good idea? How to do it?

Not sure I understand the task correctly, I assume you want to wait for receiving data after establishing the connection for at most 1 second.

There is a DevIo_TimeoutRead and DevIo_Expect function, but both are deprecated, as they block FHEM.

A non-deprecated way to read with a timeout is:
- specify a ReadFn function in the module hash (in the Initialize function). If this function is called, it is guaranteed, that one(!) DevIo_SimpleRead call wont block. If the data received by one DevIo_SimpleRead is not complete, remember it, return from the function, and wait for the next call.
- call DevIo_OpenDev (e.g. in the DefineFn or SetFn), specify the 3rd parameter (initFn), and set up there an InternalTimer for 1 second.
- the function called by the timer can close the connection, or do whatever is appropriate.

@rudolfkoenig Thanks for reply. You almost got it right :)
One main thing is diffrent. I can have the connection established all the time, but before sending the message via DevIo I would like run the listener for a second to catch the response. I would say it is something like a modbus connection. I send a message and after that immediately I get a response.

So I'd like to do sth like that:
> Define device (establilishing connection)
> Initialize device (run InternalTimer, every 60sec get data)
   > Run listener for one second for responose (asynchronous)
   > in the same time send hex message DevIo_SimpleWrite
   > Receive and convert data to state

Eigentlich habe ich es geschafft, die Daten zu lesen, ich habe noch eine kleine Frage, wie man es schafft, dass zwischen einer Anfrage und einer anderen zum Beispiel 2 Sekunden Pause sind?



[0] Themen-Index

[#] Nächste Seite

Zur normalen Ansicht wechseln