vishnus
Hello, I have created a simple test function block that performs an AND operation on 2 input BOOLs. These two input BOOLs are contained in a user datatype datatype0 that is of type 'structure'.
 
Now, I am using the OpenPLC simulator to test this program. I can see the output in the debugger window, but where can I set the values of the inputs that are contained within the datatype0 structure? The red lines have a "Force True/False" option, but those don't seem to do anything.
 
I have also tried with the IN_VALS variable set to Input.
 
Thanks,
--swamiSetInputs.png
Reply 0 0
thiagoralves
You can only force default datatypes (BOOL, INT, SINT, etc). Custom datatypes are complex structures that can't be forced on the debugger. I know it sucks, but what you could do is use an intermediary variable that holds the value of the datatype variable you want to force. Something like temp_bool := IN_VALS.IN1. Then connect temp_bool to your AND block. Since temp_bool is a default BOOL variable, you will be able to force that.
Reply 0 0
vishnus
Thanks, @ThiagoAlves, that's good to know. It is unfortunate, but a small price to pay for a great piece of (free) software!
--swami
Reply 1 0
thiagoralves
I've added that to the list of (many) things to add to OpenPLC 🙂
Reply 0 0
vishnus
Thanks, @ThiagoAlves. On a similar note, I have a block, created by a colleague, that takes a user datatype structure as an input. Let's say this is the testAND function block as defined above. So, the testAND block takes as input one user datatype datatype0 (that internally contains 2 BOOLs) and generates an AND output of the datatype0 input. How can I create this datatype0 structure with 2 discrete BOOLs as inputs so I can force the values during debug?
Thanks,
--swami
Reply 0 0
thiagoralves
You would have to dismember the datatype members inside the block into individual BOOLs and then debug the block to force the dismembered BOOLs. The other option is to build the datatype externally from individual BOOLs that you can force, and then send the built datatype to the block.
Reply 0 0
vishnus
Yes, I'd prefer the second option, but I'm unsure how to build that external datatype. Maybe it's easier done in ST text than graphically?
Reply 0 0
thiagoralves
Before calling the block passing the datatype, just use intermediary variables to expose the datatype members. Something like:
 
temp_bool := IN_VALS.IN1;
IN_VALS.IN1 := temp_bool;
 
If you force temp_bool, you will be forcing IN_VALS.IN1
Reply 0 0
vishnus
Thank you, @ThiagoAlves. I created an ST FB that takes basic datatypes as inputs and outputs a custom user datatype. The code is simply assignment of inputs to structure members.
Reply 0 0
Reply