Help with Red Lion "C Like" programming

DLMUK

Member
Join Date
Jun 2013
Location
Southampton
Posts
311
hi,

we have a piece of C like programming written by an ex-employee. I am trying to get it to operate but with no luck.

Could anybody look at the below and tell me if there are any errors in the program (i.e. brackets missing, wrong place etc).

There are 16 cases in the program but they are mostly copies of each other with slight variations. And it is around 1000 lines long so I have copied out the first 3 smaller statements.

Any help would be greatly appreciated!





switch(Loadcell1_parameters.Number_of_Points)

{
case 1: Loadcell1_parameters.Last_Value_Entered := Display_Value_loadcell1.dsp1;
if(Tonne_loadcell1.Tonne1 <= (Display_Value_loadcell1.dsp2/100.0) || ((Display_Value_loadcell1.dsp2/100.0) == Loadcell1_parameters.Last_Value_Entered) && (Display_Value_loadcell1.dsp2/100.0) == Loadcell1_parameters.Enter_Max_Load ){
Tension_Final_loadcell1 := Tonne_loadcell1.Tonne1;
Tension_Final_loadcell1_kn := Tension_Final_loadcell1 * 9.80665;
return Tension_Final_loadcell1;
return Tension_Final_loadcell1_kn;}
break;

case 2: Loadcell1_parameters.Last_Value_Entered := Display_Value_loadcell1.dsp2;
if(Tonne_loadcell1.Tonne1 <= (Display_Value_loadcell1.dsp2/100.0) || (Display_Value_loadcell1.dsp2/100.0) == Loadcell1_parameters.Enter_Max_Load ){
Tension_Final_loadcell1 := Tonne_loadcell1.Tonne1;
Tension_Final_loadcell1_kn := Tension_Final_loadcell1 * 9.80665;
return Tension_Final_loadcell1;
return Tension_Final_loadcell1_kn;
}
if ((Display_Value_loadcell1.dsp2/100.0) == Loadcell1_parameters.Last_Value_Entered){
Tension_Final_loadcell1 := Tonne_loadcell1.Tonne1;
Tension_Final_loadcell1_kn := Tension_Final_loadcell1 * 9.80665;
return Tension_Final_loadcell1;
return Tension_Final_loadcell1_kn;
}
if ((Display_Value_loadcell1.dsp2/100.0) <= Loadcell1_parameters.Enter_Max_Load){
Last_tonne_loadcell1.Last_Tonne2 = (Display_Value_loadcell1.dsp2/100.0)+((Tension1-(Volt_Inputs_Loadcell1.Volt_2/10))/100.0)/(Volt_Tonne_Gain_Loadcell1.Volt_Tonne_Gain2);
Tension_Final_loadcell1 := Last_tonne_loadcell1.Last_Tonne2;
Tension_Final_loadcell1_kn := Tension_Final_loadcell1 * 9.80665;
return Tension_Final_loadcell1;
return Tension_Final_loadcell1_kn;
}
break;

case 3: Loadcell1_parameters.Last_Value_Entered := Display_Value_loadcell1.dsp3;
if(Tonne_loadcell1.Tonne1 <= (Display_Value_loadcell1.dsp2/100.0)){
Tension_Final_loadcell1 := Tonne_loadcell1.Tonne1;
Tension_Final_loadcell1_kn := Tension_Final_loadcell1 * 9.80665;
return Tension_Final_loadcell1;
return Tension_Final_loadcell1_kn;
}
if( Tonne_loadcell1.Tonne2 <= (Display_Value_loadcell1.dsp3/100.0) || (Display_Value_loadcell1.dsp3/100.0) == Loadcell1_parameters.Enter_Max_Load ){
Tension_Final_loadcell1 := Tonne_loadcell1.Tonne2;
Tension_Final_loadcell1_kn := Tension_Final_loadcell1 * 9.80665;
return Tension_Final_loadcell1;
return Tension_Final_loadcell1_kn;
}
if ((Display_Value_loadcell1.dsp3/100.0) == Loadcell1_parameters.Last_Value_Entered){
Tension_Final_loadcell1 := Tonne_loadcell1.Tonne2;
Tension_Final_loadcell1_kn := Tension_Final_loadcell1 * 9.80665;
return Tension_Final_loadcell1;
return Tension_Final_loadcell1_kn;
}
if ((Display_Value_loadcell1.dsp3/100.0) <= Loadcell1_parameters.Enter_Max_Load){
Last_tonne_loadcell1.Last_Tonne3 = (Display_Value_loadcell1.dsp3/100.0)+((Tension1-(Volt_Inputs_Loadcell1.Volt_3/10))/100.0)/(Volt_Tonne_Gain_Loadcell1.Volt_Tonne_Gain3);
Tension_Final_loadcell1 := Last_tonne_loadcell1.Last_Tonne3;
Tension_Final_loadcell1_kn := Tension_Final_loadcell1 * 9.80665;
return Tension_Final_loadcell1;
return Tension_Final_loadcell1_kn;
}
break;
 
You can only "Return" one Value in a Program.

However, you can set the value of a tag directly in a program and I suspect that what really needs to be done here is that two tags need to be set directly by the "Case" that is active and nothing really needs to be "Returned". Try determining what tag is supposed to be set by Tension_Final_loadcell1 and Tension_Final_loadcell1_kn and simply set them directly rather than trying to "return" those values.

If this program is supposed to set a number of different tags, you may need to have multiple copies of it or pare it down so that it only "Returns" one value and directly sets the other one.

I realize that my response may not be clear, but I am trying to guess based on a code snippet completely disassociated with the actual project requirements.
 
Could anybody look at the below and tell me if there are any errors in the program (i.e. brackets missing, wrong place etc).
Can you be more specific about the problem? If it's a syntax issue as you suggest, then it won't compile and I believe Crimson will point out the error. Or does the program run and just doesn't do what you want?
 
This part right here

Code:
switch(Loadcell1_parameters.Number_of_Points) {
    case 1: Loadcell1_parameters.Last_Value_Entered := Display_Value_loadcell1.dsp1;
            if(Tonne_loadcell1.Tonne1 <= (Display_Value_loadcell1.dsp2/100.0) || ((Display_Value_loadcell1.dsp2/100.0) == Loadcell1_parameters.Last_Value_Entered) && Display_Value_loadcell1.dsp2/100.0) == Loadcell1_parameters.Enter_Max_Load ){
                Tension_Final_loadcell1 := Tonne_loadcell1.Tonne1;
                Tension_Final_loadcell1_kn := Tension_Final_loadcell1 * 9.80665;
                return Tension_Final_loadcell1;    
                return Tension_Final_loadcell1_kn;
            }
     break;
is an example of one of the places where the two returns are (there are double returns in all the if statements under each case). If the IF statement evaluates as true then the value Tension_Final_loadcell1 will be returned. The next line, return Tension_Final_loadcell1_kn will never be executed.

Also you may need a default case to return a value if Loadcell1_parameters.Number_of_Points is some value other than 1, 2, or 3.

Also, what happens when the if statement evaluates as false. Nothing will be returned.

Consider if the code really should look like this:
Code:
switch(Loadcell1_parameters.Number_of_Points) {
    case 1: Loadcell1_parameters.Last_Value_Entered := Display_Value_loadcell1.dsp1;
            if(Tonne_loadcell1.Tonne1 <=  (Display_Value_loadcell1.dsp2/100.0) ||  ((Display_Value_loadcell1.dsp2/100.0) ==  Loadcell1_parameters.Last_Value_Entered) &&  Display_Value_loadcell1.dsp2/100.0) ==  Loadcell1_parameters.Enter_Max_Load ){
                Tension_Final_loadcell1 := Tonne_loadcell1.Tonne1;
                return Tension_Final_loadcell1;    
            }
            Tension_Final_loadcell1_kn := Tension_Final_loadcell1 * 9.80665;
            return Tension_Final_loadcell1_kn;
     break;
which has something to return when the IF statement evaluates as false. (Its up to you to determine if this is how it really should be, this is just one possible alternative).
 
Thanks for all you replies - I will look into them all.

With regards to the case not being 1, 2 or 3. The tag controlling the case input is limited to 2-16 (so infact case 1 would never be used, but was put in before the tag was limiting). There are 16 cases in the full program, so the tag related to the "number of points" should always ensure a case will be used.

You say about setting a tag rather than returning a value, please could you explain how you would do this?

A brief overview...

We have built two systems, one uses a load cell with a mA input into our Red Lion gear. The other uses 0-10V.

the program we used worked fine for the mA setup. However since "converting" it to try and take a voltage input it does not seem to function. The idea of the program is two work out a mA/tonne or volt/tonne gain value. And chose which gain value to use depending on the input from the load cell. It would take a long time to explain how it is supposed to work fully but I can do so if needs be.

I understand what you are syaing about have two return statements, I think this has been hidden because a data tag is actually doing the conversion as well. I will amend this.


I cannot paste the full program as I get this error

  1. The text that you have entered is too long (45799 characters). Please shorten it to 10000 characters long.
 
You say about setting a tag rather than returning a value, please could you explain how you would do this?

Whether this is possible or not will depend on how the function is used. If the function is used as a data source for a tag or called by another function then doing this won't be simple as you'll need to significantly restructure your project.

However, to answer your question - you would use the statement tag:=value to assign a value directly to a tag and you would change the function type to void.
 

Similar Topics

Hello, We are currently running a bunch of g310's connected to their SLC5 PLCs through ethernet. I've attempted to upgrade the program from 2.0...
Replies
1
Views
1,121
I'm working on a Graphite that is continuously looping through the start up sequence then stops and shows a page that says "system could not...
Replies
15
Views
4,904
Hey guys, I was wondering if a G303 Red Lion HMI can be used as a scanner? I am having trouble finding information on this. Thanks
Replies
4
Views
1,374
When you are compiling (translating in Red Lion parlance) user defined programs - what does "Unexpected End-of-Text" error mean? It is at the END...
Replies
3
Views
1,791
Hello everyone, Brian the Newb here again regarding Crimson 3.0 and J1939 CAN protocols. I had searched the archives and I DID find a couple of...
Replies
2
Views
2,989
Back
Top Bottom