I'm writing a function block using Omron CX-Programmer for a CJ2M CPU. The FB is for interfacing with Slice I/O counter cards. The counter cards have 2 control words wherein writing certain bits enable/disable certain functions, and 2 status words wherein certain bits reflect certain statuses.
Simple example: if the counter enabled/disabled status bit (8) is low, I want to set the control bit (also 8) high.
In my ladder program I can access the status bits by the bit address like this:
LDNOT 3313.08 (status word bit 8 "count enabled") OUT 3206.08 (control word bit 8 "enable count")
But in my ST FB I cannot find a way to do the same:
IF StatusWord.08 = FALSE THEN ControlWord.08:=TRUE
or
IF StatusWord[8] = FALSE THEN ControlWord[8]:=TRUE
Neither of the above work, and I cannot find any functions in the manual that look promising.
One idea I had was converting the word to a string of its binary representation and then parsing out the specific character, and then converting to bool. But I can't figure out how to convert to a binary string; it seems it only wants to convert to HEX, and will not accept any formatting like 2#(SAMPLE16BITWORD) or @(SAMPLE16BITWORD) or HEX_TO_BIN(SAMPLE16BITWORD).
Here's what I have (doesn't work, converts to HEX,not BIN)
Simple example: if the counter enabled/disabled status bit (8) is low, I want to set the control bit (also 8) high.
In my ladder program I can access the status bits by the bit address like this:
LDNOT 3313.08 (status word bit 8 "count enabled") OUT 3206.08 (control word bit 8 "enable count")
But in my ST FB I cannot find a way to do the same:
IF StatusWord.08 = FALSE THEN ControlWord.08:=TRUE
or
IF StatusWord[8] = FALSE THEN ControlWord[8]:=TRUE
Neither of the above work, and I cannot find any functions in the manual that look promising.
One idea I had was converting the word to a string of its binary representation and then parsing out the specific character, and then converting to bool. But I can't figure out how to convert to a binary string; it seems it only wants to convert to HEX, and will not accept any formatting like 2#(SAMPLE16BITWORD) or @(SAMPLE16BITWORD) or HEX_TO_BIN(SAMPLE16BITWORD).
Here's what I have (doesn't work, converts to HEX,not BIN)
Code:
(*parse bits out of status word*)
StatusWORD:= INT_TO_WORD(StatusInt);
StatusSTRING:= WORD_TO_STRING(StatusWORD) ;
StatusSTRING_Character8:= mid(StatusSTRING,1,8);
CharacterINT:= STRING_TO_INT(StatusSTRING_Character8);
IF CharacterINT = 1 THEN
CountEnabled:=TRUE;
ELSIF CharacterINT = 0 THEN
CountEnabled:= FALSE;
ELSE
Error:= TRUE; (*something other than binary output*)
END_IF;
Last edited: