cpeppler
I'm trying to use OpenPLC to interact with a host through the use of registers, but I'm having compile problems anytime I use the MOVE instruction.

I started with the working "HelloWorld.xml", tested it and it worked fine.  Then I added a single rung that (I hoped) would trigger a move of 1 into a register.  It generates the STL file fine, but when I go to add it to OpenPLC, it throws compile errors, and I can not figure out how those errors relate to the original program.

Here is an image of the original program from OpenPLC:
LadderImage.JPG  Here is the STL file it generates:

StlFile.JPG 
And Here is the compilation error it creates:
CompileError.JPG  (Line 25 in ST file starts with MOVE14_OUT)

I'm pulling my hair out, wondering what this compilation problem is.  Can anyone help?
Reply 0 0
rPi_Tester
Hi cpeppler,

Does your host need to have the content of the register to read I:1 or would a simple 1 suffice ?

It's just a hunch but I suspect it's the I: that is making the compiler go haywire.
Reply 1 0
cpeppler
Thanks so much for your reply.

It worked!  I am just trying to get used to the syntax, and had seen the I: in an example
somewhere.  No fault of the developer (so pleased and thankful they make this software available)
the lack of documentation makes for some poking around to see what works.

Thanks for the support.
Reply 0 0
cpeppler

OK, Next problem.  I'm using a package called pymodbus3 to read and write register values to OpenPLC.

I've matched up the %MW01 and %MW02 holding registers with the python read/write values, and it appears
to be working.

The problem seems to be that OpenPLC overwrites the values of the holding registers with 0.  I write into them,
and they disappear.  If I drive a value into one of the registers with ladder logic, I can see it with python, but
if I stop driving it from ladder, it reverts to zero.

Here is my ladder:

Ladder.JPG 
I can write to %MW01, %MW02 and read values back immediately correctly, but when I read them
again, they go to 0.  If I press button_2, I can see 10 in %MW0.  When I release button_2, it goes back to zero.

RegisterResults.JPG 

Why are the holding registers being overwritten?


Reply 0 0
rPi_Tester
Do you have anything in your ladder diagram that manipulates the registers other than the external pymodbus ?
If not it seems odd that they would revert to zero.

The Register_1 on the other hand is always going to revert to zero because you manipulate it within the ladder.
This is where I had the toughest time to wrap by brain around ladder logic. I thought that as soon as a rung evaluates
to false anything after the first false condition (or contact in this case) would stay "safe". This is not how ladder logic works, though.

In your case when you press the button, contact button_2 will evaluate to true which will enable the move block to shift 10 to it's
output and ultimately to the Register_1. All is good so far.
But, when you release the button, contact button_2 will evaluate to false which disables the move block. And here's the catch:
the output of the move block will now evaluate to false (i.e. 0) and that gets written to Register_1.

In C that rung would look like:


if (button_2) {
   Register_1 = 10;
}else{
   Register_1 = 0;
}


Ladder logic is still pretty "new" to me so I haven't figured out everything yet and persistency of variables is one thing. There is the
constant/retain/non-retain alternatives in the Option column where you define your coils, contacts and variables. But I haven't found
any info as to whether they relate to persistency or not.
So I made my own dirty hack to keep the values between scans even when a contact in that rung evaluates to false:

ladder.png 


Here 3 values gets added together when the rung is enabled. When the ADD block is enabled it will set the SELECT block to use IN1 as it's input
feeding variable P_MEAS with a new value. When the rung eventually reverts to false the SELECT block will use IN0 instead which is fed by P_MEAS.
This way P_MEAS only changes when there's a new value calculated at the ADD block output. Obviously if you need to have the variable zeroed at some
stage you will have to make a rung that takes care of that.

But this is just an ugly hack, hopefully someone more fluent in ladder logic can chime in and suggest a more elegant solution.
Reply 0 0
cpeppler

Thanks again, rPi_Tester for your response.

When I used to program GE Series 6 PLCs (many years ago,
they are probably defunct by now), retaining the
value of the memory register was the default behavior
(as long as ladder didn't modify the value, it stayed the way you
set it from "the host").

After your mention of the Option column, I started playing
with it to determine how it behaves.  "Retain" doesn't really retain values,
but "Constant" does.  "Constant" doesn't let the ladder write to that
register, but the host can.

I'm a little confused by the behavior of the "Enable" bit on the Move
function.  I assumed that if the Enable bit was NOT set, then
the Move block would be inactive and leave the value the way it was
set.  Actual behavior is as you describe.  If the enable
bit is NOT set, it moves a 0 to the register value.
Ladder2.JPG 
RegisterResults2a.jpg 

What I need is a one shot from ladder that moves a value to a register,
and then leaves it there, so I can read it from the host.

I'm closer to where I needed to be.  Thanks for the tip of the Options
field.  Lack of docs (not a criticism...thanks for the open source!), means
there is a fair amount of trial and error to discover specific syntax
and actual behavior.

Kind of feeling my way along here....but slowly making progress.

Reply 0 0
rPi_Tester

I know, it ain't pretty, but if you're in a hurry this should do the trick:



ld.png 

Now when you press the button_2 MOVE is going to shuffle the 10 into Register_1 (through IN1 in SEL). When you release the button_2 SEL is going to move
IN0 (which happens to be the contents of Register_1) to it's output which is back to Register_1. So you will endlessly be moving Register_1 to Register_1.
That should keep your Register_1 safe and sound between the scans (from the ladder logic at least).

I'm not sure about the Option field in this case, you might have to leave it blank.

Reply 0 0
cpeppler

Well, after much trial and error (I am rusty at Ladder), and your help,
I think I have a working model that shows how it works.  Thanks for the 
snippet, and given the behavior of the move command, I can't do any 
better:

Ladder3.JPG 
And I got some sensible host results:
RegisterResults3.JPG 

Like you said, it isn't particularly pretty, but it does work.  Now I have to get back to my real job ;-)

Reply 0 0
jeskudero
Hello

I was searching for problems with MOVE block funtcion in OpenPLCeditor and i have a similar issue.

I am working with a raspberry pi with openplc v3.

I am trying to move some static value from one register to another, but i cant figure it out how MOVE works.

Captura de pantalla de 2019-01-22 15-51-46.png 

When i press the button, i can see the LED shinning  but i cant see the register changing value. I also have problems to see the initial value of the registers. I have palyed with te "option" column and no results.

Thanks in advance!
Reply 0 0
thiagoralves
If you’re not seeing the initial value then probably you’re poking the wrong address? What Modbus address you’re using to read %MW1 and %MW2? Also, you should remove the “0” from these variables (instead of %MW01, write %MW1) as it may confuse the parser.
Reply 0 0
jeskudero
Thiago you are right, i have searched the initial values and %MW1 and %MW2 is writing the values in the 1025th and 1026th holding registers.

How can i write the values in the 1 and 2 holding registers? i'm trying with location %MBX (byte?), i dont know if its posible to use this location. %MW is the only location to write and read holding registers?

Thanks
Reply 0 0
thiagoralves
Check http://www.openplcproject.com/scada to see the correspondence between Modbus addresses and OpenPLC variables.

Answering your question, Modbus holding register 0 would be %QW0, but that variable is also associated with the physical analog outputs. If you are running OpenPLC on a hardware that has analog outputs, writing to this variable will change the voltage (or current depending on your device) of the first physical output.
Reply 0 0
jeskudero
Thanks Thiago!
Reply 0 0
Reply