drbitboya
Say I wanted to add a driver via PSM for a DHT11 device (Humidity and Temperature sensor that uses a straightforward 1-wire protocol, similar to the way the DS18B20 works).

That 1-wire protocol would presumably use one of the GPIO pins that are already normally assigned to an input, the value for which I assume would normally be transferred into OpenPLC's discrete (digital) input IX0.?*.

Is there any conflict between my DHT11 driver reading and writing to that pin in a separate thread, and any another process or thread that might be reading that pin?  Does using PSM eliminate that other process/thread?

If my PSM driver were to skip reading that pin and writing to that IX0.0,? entry, would that leave the pin free for the DHT11 driver to do what it wants with no conflict?

* "?" means I don't know offhand which pin or which OpenPLC IX input, but for the purposes of this thread neither do I care; I can deal with the specifics later.
Reply 0 0
thiagoralves
First of all, PSM replaces any other driver that was used previously. So you don’t have to worry about conflicts there. Your PSM driver will be in full control of all GPIO pins and any other hardware interfaces. This also means that the mapping between IX, QX, etc and GPIO pins that were defined previously by any other driver disappears. You’re blank to define your own mappings.
 
Second, you cannot store temperature (or any other measurement) in a IX location. Those are for boolean (true/false) values. Measurement inputs must be stored in IW locations. 

Third, you obviously cannot use the same GPIO pin for more than one thing. So if you define a pin to be reading DHT sensors, that’s what it is going to do. Where you place that measurement (in terms of OpenPLC locations) is totally up to you, as long as you obey the size of the data with the size of the location (no integers at boolean locations as I explained previously)
Reply 0 0
drbitboya
Thank you.  I realize these are noob queries; I am still building my OpenPLC ecosystem model (editor; runtime there; etc.) in my head.

First:  good, that is what I thought from the PSM overview, but I wanted to make sure I understood correctly.  So in order to use 1 pin differently in PSM, or for that matter anything that uses PSM, we need to rebuild an entire driver framework from scratch in the PSM; that's not a big deal as I only need DIs and DOs, and Python makes it trivial to loop over each of those similar item types.
 
First.1: That said, if it's only 1 pin, is it possible to configure the default driver, without changing the driver code itself, to ignore 1 GPIO pin that would otherwise be configured by default as an output or an input, so another process/thread on the RPi can use that pin to read the analog temperature value from the DHT, and then use some other method (e.g. Modbus) to get that value into the running runtime?  For example, I have stumbled over the hals.json file that lists the pin configurations and has default_* and user_* keys; is that read at runtime or at compile time?  And if at runtime, does that mean I can change the distribution of e.g. DIs and DOs, at least for any pins that can do both?
 
Second:  I know the temperature value would be stored in an IW location; When I referred to IX0.?, it was intended as a proxy for the default pin from which the temperature bits are read over time.

Third: yes, that was my concern.
 
Third.1:  are IX/IW/QX/QW locations the only options for writing data from the PSM to OpenPLC locations?  Or are any locations in the runtime valid as targets for the .get_var/.set_var methods?
 
Thanks again.
Reply 0 0
thiagoralves
1. Ok
1.1 Yes, you can do that. Just keep in mind that the hals.json is meant for microcontrollers and are read at compile time. On the Raspberry Pi and other Linux systems you will have to edit the hal .cpp file inside /webserver/core/hardware_layers to disable your pin. PSM won’t run on microcontrollers.
2. Ok
3. Ok
3.1 Only IX/IW/QX/QW
Reply 0 0
drbitboya
Thank you!
 
Great project.
Reply 0 0
Reply