azat385
I tried to run openPLC on orange pi zero with external tcp device and works great! Thank you!

i cant figure out how to add orange pi zero pins to config file?
Quote 0 0
thiagoralves
You will have to write specific orange pi hardware driver to be able to control orange pi's pins. Since I don't have an orange pi, I can't write one myself. However, I don't think it would be too complicated. Just take a look at the files inside the /core/hardware_layers folder. Take the blank one as an example. All you have to do is to write code for the initialization function (in case the hardware has to be initialized somehow) and then write code for the update buffers function (to update inputs and outputs).
Quote 0 0
azat385
Could you explain me how to add two different types of inputs on raspberry pi?
i mean how to use build in inputs and external modbus rtu|tcp devices?

by the way: if i try to use build input pins and uart (/dev/ttyAMA0) for modbus rtu slave? will it work properly?
Quote 0 0
azat385
i have found working library https://github.com/xpertsavenue/WiringOP-Zero
but it uses same names and functions as wiringPI library
is it possible to implement it?
Quote 0 0
thiagoralves
You should be able to use the Raspberry Pi driver with this library then. I don't know about the pinout, perhaps it might need some adjustments...

For your previous question, you can't use more than one driver simultaneously (like modbus for remote I/O and local GPIO pins on the board). See https://openplc.discussion.community/post/use-the-io-of-both-raspberry-pi-and-esp8266nodemcu-8407390?trail=15#3 for more details
Quote 0 0
azat385

[377419.777288] [ pid ] uid tgid total_vm rss cpu oom_adj oom_score_adj name
[377419.777656] [ 1133] 0 1133 107886 107466 0 0 0 openplc
[377419.777847] Out of memory: Kill process 1133 (openplc) score 645 or sacrifice child
[377419.794193] Killed process 1133 (openplc) total-vm:431544kB, anon-rss:427380kB, file-rss:2484kB


how to investigate what went wrong?
Quote 0 0
thiagoralves
That's a hard question. The log doesn't provide much information, and I'm not familiar with the Orange Pi hardware library. One thing you can do is to insert a lot of printf in the code and see where it stops. For example, insert printf("1\r\n") before a function call and printf("2\r\n") after a function call. If you don't see "2" printed on the console it means that your code is crashing on that function call.
Quote 0 0
azat385
in fact i dont think that the problem is in Orange Pi hardware library.
have a look on st code:

PROGRAM My_Program
  VAR
    button AT %IX0.0 : BOOL;
    lamp AT %QX0.0 : BOOL;
  END_VAR
  VAR
    T0 : TOF;
  END_VAR
  T0(IN := button, PT := T#2000ms);
  lamp := T0.Q;
END_PROGRAM
PROGRAM program0
  VAR
    in1 AT %IW0.0 : UINT;
    in2 AT %IW1.0 : UINT;
    in3 AT %IW2.0 : UINT;
    out1 AT %QW0.0 : UINT;
    out2 AT %QW1.0 : UINT;
    out3 AT %QW2.0 : UINT;
  END_VAR
  out1 := in1;
  out2 := in1+in2+100;
  out3 := out2+in3+100;
END_PROGRAM

CONFIGURATION Config0
  RESOURCE Res0 ON PLC
    TASK TaskMain(INTERVAL := T#20ms,PRIORITY := 0);
    PROGRAM Inst0 WITH TaskMain : My_Program;
    PROGRAM INst1 WITH TaskMain : program0;
  END_RESOURCE
END_CONFIGURATION



modbusdevice.cfg

Num_Devices = "1" 
# ------------
#   DEVICE 0
# ------------
device0.name = "MTCP_1"
device0.protocol = "TCP"
device0.slave_id = "1"
device0.address = "192.168.1.7"
device0.IP_Port = "502"
device0.RTU_Baud_Rate = ""
device0.RTU_Parity = ""
device0.RTU_Data_Bits = ""
device0.RTU_Stop_Bits = ""
device0.Discrete_Inputs_Start = "0"
device0.Discrete_Inputs_Size = "10"
device0.Coils_Start = "0"
device0.Coils_Size = "10"
device0.Input_Registers_Start = "0"
device0.Input_Registers_Size = "10"
device0.Holding_Registers_Start = "0"
device0.Holding_Registers_Size = "10" 


It is just hello world via MTCP.

and smth goes wrong i mean:
openplc process consumes too much memory, it can be a memory leakeage?

sorry for my english.

Quote 0 0
thiagoralves
OpenPLC currently doesn't support multiple programs neither multiple tasks in the same code as you did. It can only run one cyclic task with 50ms interval. However, I don't think that's the problem for it to crash. It should just run the first task and ignore the second. I ran your code on my setup and it didn't crash. If you're using external modbus devices, it might have to do with the libmodbus library. How long does it take to crash? As I said, the best way to investigate is to add printf's in the code and see where it is crashing.
Quote 0 0
azat385
thiagoralves wrote:
How long does it take to crash?

about 2-3 days
Quote:
As I said, the best way to investigate is to add printf's in the code and see where it is crashing.

where to put them?
in ST code or somewhere else?
Quote 0 0
azat385
Could you be so kind, to explain me how ST code is compiled to executable file?
Quote 0 0
thiagoralves
You need to put the printf's in the openplc code. More specifically, a good place to start is in the main.cpp file. It would be interesting to add printf's in the hardware_layer.cpp file as well. Just add them between function calls. I have the impression that libmodbus might be causing this problem. Libmodbus is only used by the Modbus hardware driver. Have you tried other hardware driver, like blank or Arduino for example? Does it crash with it?

The ST code is compiled using MatIEC (included in the OpenPLC package). The MatIEC compiler generates a bunch of .c and .h files for your ST code. They are then moved to the /core folder and stay with the other OpenPLC .cpp and .h files. Then GCC is called to compile everything together into a final binary application.
Quote 0 0
PeggyLeon
Hi...i am a new user here. As per my knowledge it should not be too complicated. Just take a look at the files inside the /core/hardware layers folder. Take the blank one as an example. All you have to do is to write code for the initialization function and then write code for the update buffers function.

pcb assembly process
Quote 0 0