NeoCortex97
Hi, I would like to use the Raspilc board instead of pixtend and unipi.

But I did not find a driver for the raspilc bord. So I wanted to ask if someone already built a driver for that board.

If nobody did that, I would like to get more input about creating my own driver. 

Thx in advance Neo
thiagoralves
You can write your own driver using the blank driver as a guide. You can find the blank driver at OpenPLC_v3/webserver/core/hardware_layers/blank.cpp. The concept is really simple, you just need to provide code for hardware initialization, reading inputs and writing to outputs. If you write directly on the blank.cpp file, once you reapply the driver on the hardware tab, your code will be loaded into OpenPLC runtime 
Reply 0 0
NeoCortex97
Thanks. I will try writing my own when I receive my board. What would be required to make it available for everyone if it works?

By the way, how would I include a library to drive spi or i2c devices. Or should I just use the ones from the other drivers?

The RasPiLC bord has multiple optional things that could be present or not. Is there any guide on how to do that in detail? 
Reply 0 0
NeoCortex97
I need libraries for mcp23017 and mcp2515 and ds1307. 
Reply 0 0
thiagoralves
The driver is pretty low level, so you’re free to do whatever you feel is better. I would try to avoid libraries that need to be linked against as those will require OpenPLC installer to be modified as well to install these dependencies. Static libraries that you can just include in your code (like #include “foo.h”) are better, making the code more portable.

As for the optionals, this is a great question. What I’ve done in the past is to use some sort of .cfg file that the driver loads and parses. DNP3 driver works exactly like that. Other features like Modbus, slave devices and persistent storage still have cfgs, but the web UI generates them automatically for the user, so their usage is kinda transparent. That’s why I like .cfgs because they are easy for humans to write, but also easy to automate on a UI later on...
Reply 0 0
thiagoralves
One thing I forgot to mention, most Raspberry Pi drivers are based on WiringPi. If I’m not mistaken, wiring pi offers support for some of your devices, if not all of them. Just in case you want to reuse some code...
Reply 0 0
richw
I created a driver for my orange pi 3 in the hardware_layers directory. How do I get in the drop down menu on the hardware page?
Reply 0 0
thiagoralves
That, unfortunately, is not straightforward. You will have to edit the source code of the webserver to include your own driver in the html of the page
Reply 0 0
richw
Can you tell me which file name I have to change?
Reply 0 0
thiagoralves
Start here https://github.com/thiagoralves/OpenPLC_v3/blob/master/webserver/webserver.py at line 1672. Once you've added your own entry to the table, you'll also have to edit scripts/ change_hardware_layer.sh script to include the new option you've added, obviously with instructions on how to compile it properly.
Reply 0 0
richw
I tried but no success, but was able to modify the RPI hardware driver by changing the pin numbers and got it to work but this is way over complicated so I searched the forum and found a post where you said it's better and easier to use PSM. I downloaded a fresh copy of OpenPLC and tried to compile and run the default PSM script and received the error below. I'm not sure but I think it says python is not installed or can't be found. I started a Linux terminal and typed "python3" and it started the interpreter. Don't know what to try next, need some direction.
OpenPLC Runtime starting...
Interactive Server: Listening on port 43628
PSM: Starting PSM...
Traceback (most recent call last):
  File "/root/OpenPLC_v3/webserver/./core/psm/main.py", line 27, in <module>
    import psm
  File "/root/OpenPLC_v3/webserver/core/psm/psm.py", line 3, in <module>
    from pymodbus.server.sync import ModbusTcpServer
ModuleNotFoundError: No module named 'pymodbus'
PSM: Error while starting Python interpreter
Issued start_modbus() command to start on port: 502
Server: Listening on port 502
Server: waiting for new client...
Issued start_dnp3() command to start on port: 20000
DNP3 ID manager: Starting thread (0)
DNP3 ID DNP3_Server: Listening on: 0.0.0.0:20000
Issued start_enip() command to start on port: 44818
Server: Listening on port 44818
Server: waiting for new client...
Issued stop_pstorage() command
PSM: Connection to psm failed
PSM: Error connecting to psm!
PSM: PSM is disabled
Skipping configuration of Slave Devices (mbconfig.cfg file not found)
Warning: Persistent Storage file not found
 
Reply 0 0
thiagoralves
PSM is much slower than a C driver. If you managed to write a C driver that works, it is better to use that instead. If you just want a quick and dirty solution, replace the raspberry pi driver with yours. Then every time you select the raspberry driver it will be your driver that will get activated.
Reply 0 0
richw
Ok, but speed is not an issue. I didn't write a new driver I just used the original RPI driver and changed the pin numbers. it seems the orange PI wiringPI is compatible with the RPI. Can you tell my why I might be getting the errors in PSM
Reply 0 0
thiagoralves
PSM is complaining that your python 3 does not have pymodbus installed.
Reply 0 0
thiagoralves
A simple 
python3 -m pip install pymodbus==2.5.3
sudo python3 -m pip install pymodbus==2.5.3
should fix this
Reply 0 0
Reply