ertugrul.kalkan

Hello,

I'm pretty new at OpenPLC and PLC concept. I'm trying to use OpenPLC to drive my custom slave over Modbus TCP/IP (libmodbus).

In my experiments I found out that `%QW` registers are always initialized zero (if I don't override initial value on OpenPLC Editor). I thougt in every loop of PLC program, it reads all registers (and coils, discreate inputs etc.) then modifies, and at last writes it.

Also I fount out that Holding registers are red in to `%IW100 + [register]` address but in OpenPLC editor, I can't bound any variable to another without write it it PLC program.

Is there any way to make the loop like,

- Read Inputs
- Read Coils
- Read Holdings
- [PLC program body]
- Write Coils
- Write Holdings

Thanks.

Reply 0 0
ertugrul.kalkan

By the way I figured out that I couldn't explain myself very clearly, I'm adding my PLC program and configuration as attachment. You will understand what I say when you look at the program. I think there should be a better way to make it `read before write` for `%QW` registers. I'm seeking for it.

Thanks again.

Reply 0 0
thiagoralves

By definition, a PLC scan cycle MUST be:
Read Inputs
Program body
Write outputs

If you change that cycle you’re building something else, not a PLC. Therefore, for slave devices, all outputs are write only (never read) and all inputs are read only (never written to). 


The only reason why OpenPLC offers the ability to “read” holding registers is because some Modbus devices only have holding registers, where a portion of the address space is used as inputs and another portion used as outputs. With that being said, using the same address range for both reading and writing holding registers makes absolutely no sense 

Reply 1 0
ertugrul.kalkan

Ok, I got what you mean. It's better I explain why do I need something like that so maybe you can give me an advice.

I'm programming a system that keep its state at registers. I have my own (embedded) control loop/loops as well as PLC. I'm trying to make this controller programmable externaly over OpenPLC.

example:
- I have a `SOME_OTHER_REGISTER` register that keeps INT and both Readable and Writible.
- I have a `CONTROL` register in embedded controller and has 2 different states (maybe OFF, ON) and both Readable and Writible.
- I have a `STATUS` register in embedded controller and has 3 different states (maybe OFF, ON, BUSY) and only Readable.
The user wants to program a PLC that sets CONTROL to ON if "STATUS is ON and SOME_OTHER_REGISTER is equals 100".

In this case I have to define two different SOME_OTHER_REGISTER variable at PLC, one points to SOME_OTHER_REGISTER_WRITE(%QW100) to set SOME_OTHER_REGISTER register and one points to maybe SOME_OTHER_REGISTER_READ(%IW164) to get current state of SOME_OTHER_REGISTER register but these two variables are the same for both MODBUS and EMBEDDED CONTROLLER. For writer of external program, its unnecessary complexity.

Regards

Reply 0 0
thiagoralves
I understand your need, but in that case, duplicating the IOs in read/write is the only way for you to integrate your controller with OpenPLC. When a PLC adds a slave device, it must copy the slave's internal image tables to its local image tables. That's how the PLC keeps control of the slave device, as if the slave's IO points were the PLC's local IO points. For that to work well, you must clearly define the inputs (read-only) and outputs (write-only).

There are some other PLC brands that give the user flexibility to establish the Modbus communication on the PLC programming itself. They usually have some communication blocks that you can use on your programming to read or write registers. On those PLCs you can structure the communication any way you want, but this is only program-wise, not system-wise. This means that each PLC program must implement its own communication strategy. OpenPLC is system-wise, which means that no matter what program you are running, slave handling is done by the OpenPLC operating environment (runtime). Your PLC programs access slave IOs as if they were local PLC IOs. There is no difference.
Reply 0 0
Reply