This I'm thinking is supposed to be a simple Function Block but I can't seem to get it
What I'm trying to do.
If Input 1 = high then output = 5000
if Input 2 = high then output = 5001
VAR_INPUT
IN1:BOOL;
IN2:BOOL;
END_VAR
VAR_OUTPUT
OUT: INT;
END_VAR
VAR
The code I've written:
==============
IF IN1 THEN;
OUT := 5000;
ELSE IN2 := TRUE THEN;
OUT:= 5001;
END_IF
==============
I keep getting a Error 4024: Error1 (5) Expecting";" or ":=" before 'THEN'
(I've highlighted the affected line in red)
I've tried a few different things but it's still not compiling
I know I'm writing it wrong, just need some help please.
What I'm ultimately trying to do is write a value from 5000 to 5200 to a memory word (%QW441)
My HMI then will read those codes and depending on what the value is will display a different fault on the screen.
This is my first time using codesys so any help would be greatly appreciated.
Thanks in advance
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm realizing this might not be the best way to do this.
What I'm trying to do is create fault messages.
If an alarm is triggered it'll display a fault on the screen.
All of my faults right now are grouped in 10's.. I was going to send a value to a word and have the HMI read the values and display its corresponding message.
I'm realizing that's not working very well because if more then one fault from one group is generated, by the time the scan is complete, the word only has one value in it.. so the HMI misses the other faults.
Is there a better way to do this?
As of now I'm going to create a ladder program with individual alarms coiled to individual bits..
I'm hoping to find a more effective way to do this.
Thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
t.lundahl hat geschrieben:
Hi!
What you can do, for each alarm:
IF IN1 AND NOT Alarm1 THEN
Alarm1 := TRUE;
END_IF;
IF Reset THEN
Alarm1:=FALSE;
END_IF;
See if I do it this way, there will be values written to the word that might not get scanned
let's say I have 4 inputs, IN1, IN2, IN3, IN4.
My output is Alarm = INT
Values are: 5000, 5001, 5002, 5003
Here's what I'm afraid of.. say IN1, IN2, IN3 are on..
the block will push values, 5000, 5001 and 5002 to the Alarm output
during the scan, it'll only scan what's in the memory of that output.. in this case, the last value which is 5002.. so my HMI will only display the corresponding message.. and the user will not know that alarms 1 and 2 were even on..
They may proceed to repair the third alarm, hit reset, then of course it'll scan again displaying the 2nd alarm, repair that and then repair alarm 1.. it's inefficient.
I have a ladder logic now with all alarms going to single bits.. and the HMI reading those.. individually. Looking for ways to not do it that way.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This I'm thinking is supposed to be a simple Function Block but I can't seem to get it
What I'm trying to do.
If Input 1 = high then output = 5000
if Input 2 = high then output = 5001
VAR_INPUT
IN1:BOOL;
IN2:BOOL;
END_VAR
VAR_OUTPUT
OUT: INT;
END_VAR
VAR
The code I've written:
==============
IF IN1 THEN;
OUT := 5000;
ELSE
IN2 := TRUE THEN;
OUT:= 5001;
END_IF
==============
I keep getting a Error 4024: Error1 (5) Expecting";" or ":=" before 'THEN'
(I've highlighted the affected line in red)
I've tried a few different things but it's still not compiling
I know I'm writing it wrong, just need some help please.
What I'm ultimately trying to do is write a value from 5000 to 5200 to a memory word (%QW441)
My HMI then will read those codes and depending on what the value is will display a different fault on the screen.
This is my first time using codesys so any help would be greatly appreciated.
Thanks in advance
Hi!
If you want the OUT:=5001 only if IN2 is TRUE and not everytime the IN1 in FALSE then
use:
Remove the (;) after THEN
ELSIF IN2 THEN (:= TRUE, not needed)
/TorbjΓΆrn
Hey
Thanks for the reply,
I'm realizing this might not be the best way to do this.
What I'm trying to do is create fault messages.
If an alarm is triggered it'll display a fault on the screen.
All of my faults right now are grouped in 10's.. I was going to send a value to a word and have the HMI read the values and display its corresponding message.
I'm realizing that's not working very well because if more then one fault from one group is generated, by the time the scan is complete, the word only has one value in it.. so the HMI misses the other faults.
Is there a better way to do this?
As of now I'm going to create a ladder program with individual alarms coiled to individual bits..
I'm hoping to find a more effective way to do this.
Thanks
Hi!
What you can do, for each alarm:
IF IN1 AND NOT Alarm1 THEN
Alarm1 := TRUE;
END_IF;
IF Reset THEN
Alarm1:=FALSE;
END_IF;
See if I do it this way, there will be values written to the word that might not get scanned
let's say I have 4 inputs, IN1, IN2, IN3, IN4.
My output is Alarm = INT
Values are: 5000, 5001, 5002, 5003
Here's what I'm afraid of.. say IN1, IN2, IN3 are on..
the block will push values, 5000, 5001 and 5002 to the Alarm output
during the scan, it'll only scan what's in the memory of that output.. in this case, the last value which is 5002.. so my HMI will only display the corresponding message.. and the user will not know that alarms 1 and 2 were even on..
They may proceed to repair the third alarm, hit reset, then of course it'll scan again displaying the 2nd alarm, repair that and then repair alarm 1.. it's inefficient.
I have a ladder logic now with all alarms going to single bits.. and the HMI reading those.. individually. Looking for ways to not do it that way.
Try this small change.
IF IN1 AND NOT Alarm.1 THEN
Alarm.1 := TRUE; (Secondbit in AlarmRegister)
END_IF;
Also make it as Functionblock to add to your ladder.
mr lundahl does not explain what he does:
You want to see each alarm, so each alarm has a unique code.
alarm1 is 1
alarm2 is 2
alarm3 is 4
alarm4 is 8 etc.
example
alarm2 and 3 are active.
for a is alarm1 to alarmx
hmicode is hmicode +2 sqr(a);
this way you can put 16 alarms in one WORD.
or
hmicode=0
if alarm1 then hmicode=hmicode+1;
if alarm2 then hmicode=hmicode+2;
etc.