Comparing bits, bytes, words and double words in SCL?

BoSChoW

Member
Join Date
Apr 2006
Location
Nova Gorica
Posts
107
Hello all, i have a question for you guys, how can i compare bits, bytes, words and double words that are stored in data bock with the SCL programming language?

All your help is very much apprishiated, thanks again. Regards.
 
scl comparisons

Bools can either be true or false; so comparing them isn't really an option
Bytes kept as bytes can be = or not equal to do a greater than or less than operation need to convert to int... some examples....
VAR_INPUT
int1: int;
real2: REAL;
byte1: BYTE;
bool4: BOOL;

END_VAR
VAR_OUTPUT
out_int1:INT;
out_real2: REAL;
out_byte3: BYTE;
out_bool4: BOOL;

END_VAR
//example of integer comparison
IF int1< help.int_example THEN //db10.dbw0
out_int1:=200;
END_IF;

IF real2 <> help.real_example THEN //db10.dbd2
out_real2:=1.234;
END_IF;
IF BYTE_TO_INT(byte1) >= BYTE_TO_INT(help.byte_example) THEN //help.byte_example = db10.dbb6
out_byte3:=44;
END_IF;

IF bool4 = true THEN
out_bool4:=false;
END_IF;
 
Thanks for your help guys but still i have a problem, i wrote some data to DB15 which contains 16 entryes type of bool, and DB10 which contains 16 words.

So i was trying to compare IF (DB15.W0.0=DB10.0.0) THEN ....
but it says non-existent component...

Whats wrong ?
 
Yes but it is possible to compare whole words, the program would be much shorter...i just need to compare 16 bits with another 16 bits.
IF word1=word2 then outpu1:=true;
end_if;

instead of

IF (db15.dbx0.0=db10.dbx0.0) and ... and (db15.dbx1.7=db10.dbx1.7) then output1:=true;
end_if;
 
And if i want to compare more words from this blocks then i should write :

IF DB10.DBW0=DB15.DBW1 and DB10.DBW1=DB15.DBW2 .... and so on ?
 
Last edited:
BoSChoW said:
And if i want to compare more words from this blocks then i should write :

IF DB10.DBW0=DB15.DBW1 and DB10.DBW1=DB15.DBW2 .... and so on ?
u just have to make the concept what the DB syntax is clearly .u will find the answer easier.
 
a word is 2 bytes in length; so if you say
DBW0 then the next word available is DBW2 and DBW4, etc...
if you are looking at 32 bits or a double word (4 bytes) then
DBD0 next would be DBD4, DBD8, DBD12, etc...
The only place you should have odd numbers is on bytes and bits
DBB0, DBB1, DBB2, DBB3, etc
or DBX1.5

Hope that helps. There are always exceptions, but to keep it easy and so you don't step on yourself always start words and double words on an even value. Good luck!
 
Hi BoSCHoW

I really, really hope that you are not using absolute addressing in SCL. The names, Luke, use the names.

If your Data Blocks are declared as "Alpha" and "Beta", the declarations in them are, say, Word01, Word02 etc, and you want to control Out01 then write -

Out01 := (Alpha.Word01=Beta.Word02);

Use sensible names that you and everyone else will still understand in a year's time and forget about the actual bit and byte numbers. What happens if you insert a new declaration at the beginning of DB01? Are you going to re-write all your code because the addresses of all the other parts have changed? Well, if you use absolute addressing, yes. If you use symbolic addressing, no.

Regards

Ken
 
Yes but, i stored all the data in BD as bits, so it is possible to group them into the words and name that words as word01, word02,...word16 for example?
 
No.

I'm certain I pointed out in an earlier answer to another post that Structured Text is a heavily typed language: you must declare variables, and if you have defined something as a bit then you can not later take 16 of them and pretend they are a word.

This is a very common problem in Structured Text where people take the same make-it-up-as-you-go-along approach that lightly typed languages like IL (or STL in Siemens-speak) permit. You really have to do your design work first before starting coding. What data will I need? What operations will I perform on it? What data type(s) should I use to hold it?

I also identified earlier the concept of declaring multiple variables of different data types using the AT construction. This works if you are prepared to pass your DB info in to an FC or FB as a parameter.

Finally, the only data type which covers groups of bits is the ARRAY. Define an ARRAY of BOOL in your DB. Then you can assign or test each bit individually, and also compare whole ARRAYs.

Regards

Ken
 

Similar Topics

Hello, Im here to ask all you well learned professionals a few questions which im struggling with. Im a noob and trying to learn all i can. I...
Replies
10
Views
1,802
I am telling a relay card to turn on in four different sequences. The outputs are tied back to an input card to verify contact closure. I tried...
Replies
13
Views
3,130
I’m running a micro 820 to measure a tank level, then turning on equipment at certain levels. I have an analog input (4-20) that I’m storing and...
Replies
10
Views
208
How do you go about implementing, on the M580 PLC, how many days, hours, minutes before a predefine event in the future? The RRTC_DT yields the...
Replies
3
Views
1,788
This is a Citect SCADA question I have Six variables of type REAL (Float) to compare and determine (identify) which variable has the highest...
Replies
4
Views
1,390
Back
Top Bottom