Crimson 3.1 - Strange Array Behaviour

neilsibub

Member
Join Date
Aug 2012
Location
Carlisle
Posts
19
Hi All,

I am using a Red Lion graphite G12 panel to draw a scatter graph, all works well until I run this code every morning to reset the arrays back to zero:

// Reset graph data at 6am

if(System.Time.Day >0 || System.Time.Day <6){
if(System.Time.Hour ==5)
if(System.Time.Minute ==59 && System.Time.Seconds ==59){
Fill(System.Graph.Time_Array[0], 0, 1440);
Fill(System.Graph.Count_Array[0], 0, 1440);
System.Graph.Door_Counter = 0;}}

All the arrays in System.Graph.Count_Array zero correctly and all the arrays in System.Graph.Time_Array zero correctly except for Array [359] which always retains its value.
I have tried zeroing the array using a for loop and I get the same result, if I write a zero to that array on its own it zeros and stays like that until it is written into again.

Has anyone had anything similair?
 
Something else is probably overwriting it right after your code runs.

Are those arrays tied to PLC addresses?

If so, and the HMI attempts to write to all those addresses very quickly, perhaps there is a driver limitation affecting it, but if that were the case, I'd expect more than one value not to be cleared.
 
hmm, no similar experience.


Array[359] is the last element of the first quarter of the array. What happens if the array is made larger (e.g. 1441, 1444, 1600, 5764) and it clears that (1440 or the full size), although the code would use only the first 1440.



At least you have a workaround, assuming the write of a zero works in the code.


what happens if the Fill is run twice?


sidebar: why no curly braces for if(...Hour)?
 
Just to check it isn't strange, try edit/find global/find, and enter Time_Array[359] as your search parameter.

You could try swapping the line over:
Fill(System.Graph.Count_Array[0], 0, 1440);
Fill(System.Graph.Time_Array[0], 0, 1440);
to see if it changes anything

or
Fill(System.Graph.Time_Array[0], 0, 720);
Fill(System.Graph.Time_Array[0], 720, 720);


Otherwise give Tech Support a contact, they are generally very helpful and knowledgeable.:
https://support.redlion.net/hc/en-us


If I have problems I tend to stick a sleep(500); in somewhere to give the system chance to catch it breath.
 
Are those arrays tied to PLC addresses?

No, they are all generated by the HMI, I am using them to draw a live minute by minute line graph, running from 6am to 5:59am the next day, they just count up from 0 to 1439 (1440 mins) then get zeroed and start again.
 
hmm, no similar experience.


Array[359] is the last element of the first quarter of the array. What happens if the array is made larger (e.g. 1441, 1444, 1600, 5764) and it clears that (1440 or the full size), although the code would use only the first 1440.



At least you have a workaround, assuming the write of a zero works in the code.


what happens if the Fill is run twice?

I will try these when I'm back at my desk on Tuesday and report back.
 
Just to check it isn't strange, try edit/find global/find, and enter Time_Array[359] as your search parameter.

You could try swapping the line over:
Fill(System.Graph.Count_Array[0], 0, 1440);
Fill(System.Graph.Time_Array[0], 0, 1440);
to see if it changes anything

or
Fill(System.Graph.Time_Array[0], 0, 720);
Fill(System.Graph.Time_Array[0], 720, 720);

I will also give these a go and let you know the outcome.
 
sidebar: why no curly braces for if(...Hour)?

I've always been a bit confused about the curly brace rule, I always indent my if statements to make it easier to read and sometimes forget to add a curly brace, but it still seems to work. Should I have curly braces around every if statement?
 
I've always been a bit confused about the curly brace rule, I always indent my if statements to make it easier to read and sometimes forget to add a curly brace, but it still seems to work. Should I have curly braces around every if statement?


not really necessary in those cases, but it's safer to, and eliminates the need to memorize precedence rules (i.e. lazy wins;)).


TL;DR



In many languages, the [if (expression)] applies to exactly and only one statement* after it, and that statement can be, among other things**,


  • <statement without trailing substatement>
  • <if then statement>
  • <for statement>
  • ...
and that <statement without trailing substatement>, can be, among other things


  • a single thingie with a semicolon <summat;> *** or
  • a curly-braced block of thingies { summat; summat; ... }. Also, the

Basically it's all defined so it is unambiguous to say which <if> any later <else> pairs with.



That's the long way around to say that


  • summat;
AND

  • { summat; summat; ...}
AND


  • if (...) summat;
AND


  • if (...) { summat; summat; .. }
are each considered a <statement> in the formal BNF sense, and so can be that "exactly and only one statement" after an <if (...)>


So looking at the code in the OP, none of the curly braces are needed except for the innermost if, because each is <if> is a single "statement." That said, save yourself from having to waste more neurons than necessary (like me;)) and use curly braces and indentation so you know what you meant.



* the semantics may change but the concept is fairly universal
** from Java BNF I found here
*** I used thingie because the BNF already used statement and the lingo gets too busy after that
 
Last edited:
So looking at the code in the OP, none of the curly braces are needed except for the innermost if, because each is <if> is a single "statement." That said, save yourself from having to waste more neurons than necessary (like me;)) and use curly braces and indentation so you know what you meant.

Thanks for that thorough explanation, if I understand you properly, my code should look like this?
// Reset graph data at 6am

if(System.Time.Day >0 || System.Time.Day <6){
if(System.Time.Hour ==5){
if(System.Time.Minute ==59 && System.Time.Seconds ==59){
Fill(System.Graph.Time_Array[0], 0, 1440);
Fill(System.Graph.Count_Array[0], 0, 1440);
System.Graph.Door_Counter = 0;}}}
 
Thanks for that thorough explanation, if I understand you properly, my code should look like this?
// Reset graph data at 6am

if(System.Time.Day >0 || System.Time.Day <6){
if(System.Time.Hour ==5){
if(System.Time.Minute ==59 && System.Time.Seconds ==59){
Fill(System.Graph.Time_Array[0], 0, 1440);
Fill(System.Graph.Count_Array[0], 0, 1440);
System.Graph.Door_Counter = 0;}}}

I did indent all this but they seem to get removed.
 
I did indent all this but they seem to get removed.




yes, it will work as you had it, but it could be like that; the nice thing about always using curly braces, even if they are unnecessary because there is only one line, is that you can add lines later. The number of times I have added a line in that situation and then the code didn't work are beyond counting.


For showing code here, put it in code blocks i.e. put a "
Code:
" in front, and a "[<slash>code]" after it where <slash>code is /code.


E.g. reply to this and you should see how it is done


[code]
indent0
  indent2
  indent2
    indent4
 
Last edited:
yes, it will work as you had it, but it could be like that; the nice thing about always using curly braces, even if they are unnecessary because there is only one line, is that you can add lines later. The number of times I have added a line in that situation and then the code didn't work are beyond counting.


For showing code here, put it in code blocks i.e. put a "
Code:
" in front, and a "[<slash>code]" after it where <slash>code is /code.


E.g. reply to this and you should see how it is done


[code]
indent0
  indent2
  indent2
    indent4

Code:
// Reset graph data at 6am

if(System.Time.Day >0 || System.Time.Day <6){
   if(System.Time.Hour ==5){
     if(System.Time.Minute ==59 && System.Time.Seconds ==59){
        Fill(System.Graph.Time_Array[0], 0, 1440);
        Fill(System.Graph.Count_Array[0], 0, 1440);
        System.Graph.Door_Counter = 0;}}}

Everyday is a school day!🍺
 
Code:
// Reset graph data at 6am

if(System.Time.Day >0 || System.Time.Day <6) {
   if(System.Time.Hour ==5) {
     if(System.Time.Minute ==59 && System.Time.Seconds ==59) {
        Fill(System.Graph.Time_Array[0], 0, 1440);
        Fill(System.Graph.Count_Array[0], 0, 1440);
         System.Graph.Door_Counter = 0;
     }
   }
}
Everyday is a school day!🍺


🍺


The funny thing is that that code, the way you had it, but without the curly braces, works in Python (there are no braces; indentation is mandatory). Also, I edited it above to demonstrate a common style convention for the closing braces that is perhaps more clear but wastes a few lines.


N.B. style conventions can start wars on the 'net
 
Code:
if(System.Time.Day >0 || System.Time.Day <6){
...


I don't know what the Red Lion day-of-week convention is here, but whether it's [0=Sunday to 6=Saturday] or [1=Monday to 7=Sunday], I am pretty sure this code runs seven days a week; should that be && instead of ||?


Also, if you care about not doing this on the weekend, then I have to ask why: if it's performance, then you want to invert the order of the if-expressions i.e. System.Time.Seconds outermost, then .Minutes, etc.


I've got to get a life;).
 
Last edited:

Similar Topics

Hey guys, hoping someone here could give me a little advice. I'm working with a CR1000-04000 in Crimson 3.1 and I was interested in adding the...
Replies
4
Views
93
Hi, I'm having an issue in crimson 3.0 when I create a programme using a case statement referencing a fault word that each bit needs to change the...
Replies
1
Views
81
How do you install update on Red Lion Crimson ver 3.1. Do I just need to run the exe file on the host server?
Replies
1
Views
102
Has anyone found a way to convert/replace/update the firmware on old Parker TS80xx series HMIs (i.e. TS8010, TS8006, etc) to accept Crimson...
Replies
0
Views
87
Has anyone setup communications with Red Lion 3.0 MODBUS to Baker Hughes Centrilift GCS VFD? Thanks
Replies
0
Views
86
Back
Top Bottom