Write programs for an MC252
Цей контент ще не доступний вашою мовою.
You need the editor, admin, or owner role: only they see Setup. Open Setup → Endpoints, open the MC252, and select the Programs tab. The tab shows only on MC252 endpoints. Its top bar shows where the device’s programs stand; below it, the program list is on the left and the editor on the right, with Problems, Tasks on the device, and Variables under the editor. The language is in the MC252 program language reference. Common errors are listed in Avoid common errors.
Create a program
Section titled “Create a program”- Select New program (the plus button above the program list).
- Type a file name: up to eight letters, digits,
-or_. The dialog shows the name the device gets, upper case with.TXTadded. The device runs programs in file name order, so the name also sets the load order. - Select New program. The program opens empty; an empty program is never deployed.
- Select Start from an example in the note above the editor for a small program that counts its runs, or type your own.
Start from a starter
Section titled “Start from a starter”Edge program starters are proven programs for common tasks: periodic logging, hysteresis control, duty/standby alternation, astronomical and weekly timers, an SMS alarm, a run hours counter, and a setpoint adjustable from dashboards.
- Select New program from a starter (the template button above the program list), or From a starter when the device has no programs yet.
- Choose a starter and fill in its fields. Parameters of devices behind this MC252 are listed first; levels and limits are in the parameters’ units.
- Select Continue. A field the device cannot use is marked; correct it and continue again.
- The program opens unsaved in the editor, with the starter’s name above it. Review it, change it if you like, and select Save: this creates the program and the parameters the starter adds, which the note above the editor names. Discard drops it.
Edit and check a program
Section titled “Edit and check a program”- Select the program in the list (on a phone, in the list box in the editor’s toolbar).
- Edit the source. The editor highlights options, keywords, functions, types, labels, strings, and comments. Tab takes the selected suggestion or indents; press Esc, then Tab, to move on to the next control.
- An
IFcovers only the next action. Enter after anIFline indents the next line by four spaces, and Enter after that action goes back to theIF’s indent. To indent the action after eachIFin a whole program, select Indent actions after IF in the editor’s toolbar or press Shift+Alt+F; undo takes it back. The device ignores the spaces. - Problems are marked in the text as you type, counted in the status line under the editor, and listed under Problems with their line; select one to go to it. An enabled program is checked with the device’s other enabled programs in load order, so a shared parameter that two programs write shows here. A disabled program is checked on its own.
- Select Save in the toolbar, or press Ctrl+S (⌘S on a Mac). An amber dot next to the file name marks unsaved changes. With Deploy on save on, the status line warns that saving deploys the programs and restarts all of them on the device. A program with errors is saved, but nothing is deployed until the errors are fixed.
If someone else saved the program while you edited it, Save stops and offers to keep your version or load theirs. Leaving the program or the page with unsaved changes asks first.
Avoid common errors
Section titled “Avoid common errors”HMI checks the source the way the MC252 compiles it, for language version 12. Errors stop the deploy; warnings do not. The device’s own compile result is final: a program that passes HMI’s checks can still fail on the device, for example when it runs out of memory.
- Start every program with
@PROTOCOLVERSION 12. Examples written for version 11 are rejected until you change that line. - Keep each line at most 198 bytes long, not counting comments.
- Keep strings the program outputs, such as SMS and log texts, within 127 bytes. Longer strings compile, and HMI warns about them.
- Do not log a memory parameter (
MEMTEMP,MEMBAT,MEMFILE,MEMFLASH) withPARAMLOGorPARAMLOGNOCOMMENT: the write fails and the device stops all program logging until it restarts. Log a parameter of the controller itself at the same address instead, as Record readings on an MC252 shows. - To require two conditions, store them in condition names and use
IF AND a b. TwoIFs in a row do not mean “and”: when the first condition is not true, the action after the secondIFruns. HMI warns about anIFright after anIF. - Do not let two programs write the same memory address. HMI reports it when both programs are enabled.
Get help while you type
Section titled “Get help while you type”- Completion offers what fits where the cursor is: options, keywords, commands, functions, types, and the names the program defines. Where a parameter or address goes, it also offers the registers of this device’s HMI parameters: type part of a parameter’s name to find it. Inserting a parameter’s register also adds the Modbus device definition it needs.
- Hover a word to see how it is written, a one-line description, and a Docs link to its section of the language reference. While you type the operands of an action, the signature shows which one comes next.
- Quick fixes on a problem offer the closest names for a misspelling, and the HMI parameter’s type when the program reads a register as another type than the parameter does. Ask the assistant on each problem hands it to the assistant.
- Go to definition (F12, or Ctrl-click, ⌘-click on a Mac), find references (Shift+F12), and rename (F2) work within the program. References to a memory parameter also list the parameters other programs on the device map to the same register.
Rename, disable, or delete a program
Section titled “Rename, disable, or delete a program”- Rename (the pencil in the toolbar) opens the file name dialog: enter the new File name
and select Save. The next deploy removes the file with the old name from the device. To
rename a program of a local checkout, rename it here, then run
hmi pull. - The switch in the toolbar enables or disables the program. A disabled program stays in the workspace and is never deployed.
- The trash button deletes the program. The next deploy removes it from the device, and the device restarts its other programs.
See what the device runs
Section titled “See what the device runs”The bar at the top of the tab shows where the device’s programs stand and updates while a deploy runs; see Check the deploy status. In the list, a green dot marks programs the device runs since the last successful deploy, and red and amber counts mark programs with errors and warnings.
Variables, under the editor, shows the selected program’s variables, conditions, and run times on the device, live; see Watch program variables on an MC252.
Tasks on the device, under the editor, lists what the device reported after it last loaded its programs: each task’s program, state (idle or running), period, last run, and last error. A compile error the device reported shows under the top bar with its program and line; Show line opens the program there.
Device log, under the programs, shows what programs write with SYSLOG and the errors they do
not handle; see Debug programs on an MC252.