BASIC IDE sections

Hi,

Can someone please explain the difference between the sections ‘Init’ and ‘Cyclic’ ?
What are the differences and why should they be used?

I assume ‘Init’ is code that only runs once on boot-up… aka "initialization’ ?
And cyclic runs every scan cycle?
Or is that incorrect?

Hello,

The cyclic section executes with each processor cycle resulting in extremely fast execution. Having a file write execute in the cyclic section can cause a new execution to occur far before the main execution is done. Generally we don’t recommend people do any coding in this area.

The init section is the first part of the code that will execute when you hit the run button. People will often initialize variables in this section to be used globally because this section will always be ran.

You can also create other BASIC IDE sections and have write code in these as an organizational tool. But you could also just write everything inside of the Init section

Thank you for the explanation. Just to confirm, a few more questions:

Should ‘ONCHANGE’ functions be used in ‘Init Section’ ?
Should ‘ONTIMER’ functions be used in ‘Init Section’ ?
Can multiple functions use the same ‘ONTIMER’ ? If yes, how are they both called out?
What is the limitations of ‘TSET’ for the minimum and maximum time period?

Thanks!

Onchange and Ontimer functions should be done in the Init Section.

Multiple functions can use the same TSET timer, but you’ll need to make a new ONTIMER for each time you want to call that function. Either that or include everything all in one function that is called by one ONTIMER.

As for TSET, you’re limited to 4 timers where the first parameter shows which timer your talking about. The second parameter is the amount of seconds before the timer is activated. I’m not entirely sure what the limitation for the most time you can set for TSET, but the minimum would be 1 second.

I’d recommend using a Timer for anything that’s going to be called repeatedly in about a minute, and anything larger than that I would probably recommend using ONDATE.

1 Like

Hi Tim,

I have the same logic program running on (4) different eWon units (see attached program).

All eWons have the same firmware version (13.2s0 #564), and all are using a Modbus tag named ‘Heartbeat’ to perform an ONCHANGE.

However, (2) of my eWons see the ONCHANGE Heartbeat@ fine and the logic works as expected, and the other (2) eWons do not perform the ONCHANGE. I’ve verified the Heartbeat tag is being read in as expected on all units (it’s a BOOL that changes 0/1 ever 1 second).

Any ideas what is causing them not to work as expected? If a Teamviewer session is needed, let me know.

program.bas (1.44 KB)

Apologies, the basic program attached earlier was the wrong file. Please see attached.

AgetoHQ_program.bas (1.28 KB)

Hello,

can you try and take a backup of one of the working devices and then load it onto one of the one’s that isn’t currently working and just have it go through the internet and talk2m wizard again?

I’m thinking that it might just be a small change between the devices that is causing the issue but if we already have some working ones this might be the easiest way to solve it

Hi Tim,

I can’t do that - these are on live systems (unlike the one we tested in my office a week ago) and they also are in California and Arizona, so if anything goes wrong with the backup/restore i’m SOL.

Is there any other troubleshooting of the BASIC IDE? Or is it unreliable?

Can I try and take a look at the devices either through teamviewer or can you give me your account info to take a closer look at these?

Hi Tim,

I could set that up tomorrow.

Would it be advised to try resetting anything on the ‘Erase & Format’ page? Like the following:
Erase program

Erase Historical Recording file

Erase Events file

Erase Alarms History file

Clear pending actions

(keeping in mind this unit is remote, will any of the above cause the unit to not be remotely accessible?)

As long as you don’t erase the config settings you should still stay online. You could try and erase the Basic Program and see if it becomes more responsive after that

I actually just ran into this issue working on another project. For some reason it seems like sometimes the BASIC IDE seems to just stop responding if you copy large sections of code.

I ended up just going to the Setup > Storage > Erase & Format > Erase Program

After that I copied in sections of the program one at a time and that seemed to get it working again

Hi Tim,

I just tried that. I did ‘Erase Program’ and then copied each line of code in one at a time, and saved after each line. The program still doesn’t work properly, and it does not seem to be able to recognize the ‘Heartbeat@’ variable tag as shown in the image below.

What can I do next?

not%20a%20variable%20error%20message

try changing it to
Onchange “Heartbeat”,"@CounterReset()"

Hi Tim,

ONCHANGE “Heartbeat”,"@CounterReset()" seems to be working a lot better.

Is “tagname” the preferred method to call a tag, compared to using tagname@ ?

I think it might just be a syntax thing for functions like ONCHANGE, for all of the other times that I’ve called tags I use the @ symbol