ReKnTr
Hi there,

the XOR function throws this error on compile:

In file included from ./lib/iec_std_FB.h:24:0,
from ./lib/iec_std_lib.h:740,
from Res0.c:6:
POUS.c: In function ‘void CHECKINPUTS_body__(CHECKINPUTS*)’:
POUS.c:163:40: error: ‘XOR__WORD__WORD’ was not declared in this scope
(WORD)__GET_VAR(data__->BITMASK,)));
^
./lib/accessor.h:126:74: note: in definition of macro ‘__SET_VAR’
if (!(prefix name.flags & __IEC_FORCE_FLAG)) prefix name.value suffix = new_value
^

Other bit operations like AND, OR and NOT work with the same variables.

Is this a known bug of OpenPLC Editor / Server?

BTW: Is it possible to set / read all Inputs / Output on a PiXtend with one Byte based operation (e.g. writing a BYTE to %QX0) instead of setting each Bit manually (e.g. %QX0.0 ... %QX0.7)?

Thanks,
Reiner
Reply 0 0
thiagoralves
Hi Reiner,

I've never seen this error before. Can you attach you project file here? I would like to take a look at it.

About your second question, since OpenPLC has a separate address space for each I/O type (coils, inputs, analogs, etc), it is not possible to address multiple I/Os at the same time.
Reply 0 0
ReKnTr
I tried to shorten the project to just the XOR lines and tried to upload it to the PI.
Unfortunately, the server application seemed to crash and cannot be started anymore.
This error occurs:

events.js:72
throw er; // Unhandled 'error' event
^
Error: spawn ENOENT
at errnoException (child_process.js:1000:11)
at Process.ChildProcess._handle.onexit (child_process.js:791:34)

[1]+ Exit 8 sudo nodejs server.js

The project is attached below:

PROGRAM checkInputs
VAR_EXTERNAL
outPort : WORD;
inPort : WORD;
InPortRef : WORD;
END_VAR
VAR
bitMask : WORD := 0;
resMask : WORD := 0;
tmp1 : WORD := 0;
tmp2 : WORD := 0;
END_VAR

if (InPortRef <> InPort) THEN
bitMask := inPort;
resMask := inPortRef;
bitMask := XOR(bitMask,resMask);

resMask := outPort;
outPort := XOR(resMask, bitMask);
inPortRef := inPort;
END_IF;
END_PROGRAM


CONFIGURATION Config0
VAR_GLOBAL
inPort : WORD := 0;
inPortRef : WORD := 0;
outPort : WORD := 0;
END_VAR

RESOURCE Res0 ON PLC
TASK TaskMain(INTERVAL := T#1ms,PRIORITY := 0);
PROGRAM Inst1 WITH TaskMain : checkInputs;
END_RESOURCE
END_CONFIGURATION
Reply 0 0
thiagoralves
This error appears because the OpenPLC application got corrupted (GCC deleted the executable and didn't put a good one in its place). I'm sorry, I still need to fix this error. Perhaps if you run ./build_core script again from the OpenPLC_v2 folder it might fix the issue. Also, can you attach your PLCOpen project file (the .xml one)? Thanks!
Reply 0 0
ReKnTr
Hi,

please find the XML file attached...

I rebuilt the OpenPLC Server and it works again, thanks.

Best regards,
Reiner
Reply 0 0
ReKnTr
Hi again,

Just a carification for my second question about setting multiple i/o...
I understand that coils, input etc are in different address spaces.
I just wanted to know, if it is possible to map the single bit inputs %IX0.x of type BOOL to a BYTE/WORD register, that is just called %IX0, so state of all input bit could be read in one turn. Same for outputs. As the Pixtend board supports this in the communication Protocoll... 
Reply 0 0
thiagoralves
Hi ReKnTr,

I understood your question. This is not possible exactly because each data type lives in a different address space. Boolean registers can't see byte registers (actually there are no byte registers in OpenPLC). I know that some manufacturers make it easy to write to multiple outputs at once by sending a whole byte or word to the IO registers, but this is only possible on devices that have a single address space, which means that the addressing overlaps between all types. To give a clearer example, on some PLCs the address %IX0.1 means the second digital input, or the second bit in the word %IW0. This is because %IX0.0 and %IW0 are mapped to the same memory region, therefore they live in the same address space. For OpenPLC, %IX0.0 points to a memory location and %IW0 points to another memory location. They can't see each other, unless you specifically copy memory from one region to another (using MOVE command). For this reason, it is not possible to write or read from multiple IO using a single command.

About your XOR question, I'll check that and get back to you.


Thanks!
Reply 1 0
thiagoralves
ReKnTr, the XOR function is in fact broken. MatIEC is not declaring the function for two WORD operands. I'll check that later and will get back to you if I have a solution. Thanks for finding the bug! =)
Reply 0 0
ReKnTr
Thank you very much.
Though I did a mistake in learning SPS language ;-)

I am glad to be helpful hunting bugs :-)

Cheers,
Reiner
Reply 0 0
thiagoralves
I know that it sucks to have such a basic function broken, but fixing MatIEC is gonna take a while. In the mean time, an alternative solution is to create your own custom_xor function:

FUNCTION_BLOCK custom_xor
  VAR_INPUT
    IN1 : WORD;
    IN2 : WORD;
  END_VAR
  VAR_OUTPUT
    OUT : WORD;
  END_VAR
  VAR
    result1 : WORD;
    result2 : WORD;
  END_VAR
  result1 := NOT(AND(IN1,IN2));
  result2 := OR(IN1,IN2);
  OUT := AND(result1,result2);
END_FUNCTION_BLOCK

I've attached here my example project where I use this custom_xor function. It works perfectly with WORD variables. You might need to change the function variable type to something else if you want to use a different datatype.
Reply 0 0
ReKnTr
Hi,

No worries. I already replaced the xor with the combination of and, or and not operations, so i was able to move forward.

Thanks for the workaround :-)
Reply 0 0
skv
I published fix for Matiec for this problem on beremiz mailing list. it was pretty trivial.
http://beremiz-devel.2374573.n4.nabble.com/Beremiz-devel-MatIEC-PATCH-Fix-xor-operator-for-ANY-BIT-types-td176.html
Reply 0 0
thiagoralves
I saw the fix when I was looking for a solution for the problem. What happens is that it relies on a newer version of MatIEC, which would require some minor changes in OpenPLC. Since I'm in my last semester for my Ph.D. classes I don't have a lot of spare time to work on OpenPLC. As soon as I get a little bit more of free time I'll update MatIEC in OpenPLC and bring your fix. Thanks!
Reply 0 0
Reply