bit from byte IEC61131-3

hapetter

Member
Join Date
Feb 2009
Location
Kristiansand
Posts
58
Hi.

I use TwinCAT, but I guess its a general IEC61131-3 question.

So I have a Profibus slave with 16 digital input. I like to link this fysical channels to variables in my PLC program. The 16 digital input are given as 2xUSINT (2bytes)

So my question is:
How to get a bit from a byte? Read hexcode?

If you are familiar with TwinCAT:
Is it possible to link a boolean to a bit in an USINT in system manager? How?

Best Regards
hans
 
Here's an example for word to bool;

Code:
(*
Converts word to Boolean
*)
FUNCTION_BLOCK FB_WordToBool
VAR_INPUT
bEnable:BOOL:=FALSE;
bByteSwap:BOOL:=FALSE;
wWord:WORD:=16#0;
END_VAR
VAR_OUTPUT
END_VAR
VAR_IN_OUT
bBit0:BOOL;
bBit1:BOOL;
bBit2:BOOL;
bBit3:BOOL;
bBit4:BOOL;
bBit5:BOOL;
bBit6:BOOL;
bBit7:BOOL;
bBit8:BOOL;
bBit9:BOOL;
bBit10:BOOL;
bBit11:BOOL;
bBit12:BOOL;
bBit13:BOOL;
bBit14:BOOL;
bBit15:BOOL;
END_VAR
VAR
END_VAR
(* @END_DECLARATION := '0' *)
IF(NOT bEnable) THEN
RETURN;
END_IF;
IF (NOT bByteSwap) THEN
bBit0:=wWord.0;
bBit1:=wWord.1;
bBit2:=wWord.2;
bBit3:=wWord.3;
bBit4:=wWord.4;
bBit5:=wWord.5;
bBit6:=wWord.6;
bBit7:=wWord.7;
bBit8:=wWord.8;
bBit9:=wWord.9;
bBit10:=wWord.10;
bBit11:=wWord.11;
bBit12:=wWord.12;
bBit13:=wWord.13;
bBit14:=wWord.14;
bBit15:=wWord.15;
ELSE
bBit0:=wWord.8;
bBit1:=wWord.9;
bBit2:=wWord.10;
bBit3:=wWord.11;
bBit4:=wWord.12;
bBit5:=wWord.13;
bBit6:=wWord.14;
bBit7:=wWord.15;
bBit8:=wWord.0;
bBit9:=wWord.1;
bBit10:=wWord.2;
bBit11:=wWord.3;
bBit12:=wWord.4;
bBit13:=wWord.5;
bBit14:=wWord.6;
bBit15:=wWord.7;
END_IF;
 
END_FUNCTION_BLOCK
 

Similar Topics

Hello everyone, friends. I need help with something. I want to read and change Bit and Byte numbers via HMI. I found a code snippet for this as...
Replies
18
Views
3,061
Hello All! I am having difficulties mapping register values. In the TURCK register there are 24 unique register bytes corresponding to different...
Replies
2
Views
2,574
Hi Just have a quick question, I am updating HW config of a system which uses a few DI / RO and AI inside with an ET200S. Card one uses byte...
Replies
10
Views
3,341
Hi there, Can any tell me a simple way of decting if more than one bit is set in a byte. when using a S7 400. Cheers
Replies
20
Views
8,215
Hi All, I'm trying to write (STL) a function(blok) in S7 I just want to in-output a "byte" and use it in my function as "byte.bit" format. I...
Replies
14
Views
3,597
Back
Top Bottom