Vidmar57
I am trying to Concantinate two Modbus Words into one Modbus Word.
 
Attached is the code with errors that I am receiving. Can you help me with what I am doing wrong?
Reply 0 0
PeBi
Das wird so einfach mittels Addition nicht funktionieren.
Register1 und Register2 sind ja vom Typ 'WORD' und UnionRegister vom Typ 'DWORD'.
Hab gerade in einem CODESYS-Forum eine älteren Beitrag gesehen.
Da gibts die Lösung zum Beispiel:
 
UnionRegister := SHL(WORD_TO_DWORD(Register1), 16) OR WORD_TO_DWORD(Register2);
 
Reply 0 0
Vidmar57
UnionRegister := SHL(WORD_TO_DWORD(Register1), 16) OR Register2;
Did not work.
[203128%2F9507377%2Fmceclip0]
Reply 0 0
thiagoralves
You’re trying to declare your variables twice. Drop the VAR declarations in the text code
Reply 0 0
PeBi
So funktioniert es :
 
UnionRegister := SHL(WORD_TO_DWORD(Register1), 16) OR WORD_TO_DWORD(Register2);
 
Und die Variable 'UnionRegister' sollte DWORD sein.
 
[203128%2F9507850%2Fmceclip0]
Reply 0 0
Vidmar57
Yes, I did see this after I posted this picture. I changed the data type to a "DWORD". The code did not work. Also, I removed the Variables in the code and the code would not Compile. Then, I tried to remove the Variables above the code and the code would not Compile without a a Variable listed in the Upper Variable area. So, I just added one Variable called Var0 and still recived errors. Frustrated!
Reply 0 0
thiagoralves
You are making different things that are causing different errors. Without knowing the specific errors you’re getting, our help is most likely guesses. In any case, if you don’t declare the variables in the text as I said, it will probably compile just fine. Variables MUST be declared in the variable table ONLY.
Reply 0 0
Reply