MOULDLKnowledge BaseElectrical Knowledge Base3D Model DownloadsMembership
中文版Model Store »
Knowledge Base › Electrical Knowledge Base › How do PLC-side communication routines work together with HMI macro scripts?
HomeModels
Table of contents

On this page

PLC & Programming (100 articles)

Quick Reference

  • PLC & Programming
  • Electrical & Electronic Basics (monthly)(每月更新中)
  • Electrical Control & Drawings (monthly)(每月更新中)
  • Drives & Actuators (monthly)(每月更新中)
  • Sensors & Detection (monthly)(每月更新中)
  • Industrial Communication & Networks (monthly)(每月更新中)
  • HMI & Host Systems (monthly)(每月更新中)
  • Industrial Robots & Motion Control (monthly)(每月更新中)
  • Mechatronic System Integration (monthly)(每月更新中)
  • Fault Diagnosis & Standards (monthly)(每月更新中)

How do PLC-side communication routines work together with HMI macro scripts?

HMI macros are small programs on the panel: they can scale data, manage pop-ups, query history. But as macros multiply, logic "moves house" — control logic migrates into the HMI while the PLC becomes a mere database. The iron division: judgement and control in the PLC; display and input assistance in the HMI. This article covers what macros may do, what they must not, and how the two sides cooperate.

1. The division table: who does the work

FunctionWhereReason
Start/stop judgement, interlocks, flow controlPLCControl logic must be single, reliable, auditable
Alarm judgement and loggingPLC judges, HMI displaysAlarms must not depend on the screen being on
Display-only format scalingHMI macroAffects display only, never control
Login, permissions, screen jumpsHMI macroPure human-interface affairs
Operation logs, queries, exportsHMI macroScreen-level matters
Parameter-validity checkingPLC as the last gate (HMI pre-check auxiliary)The final defence sits on the control side

The test, one sentence: with the HMI dead, should the machine still run correctly on this logic? Yes — PLC; it is only "invisible or ugly on screen" — HMI.

2. Legitimate uses of macros

UseWhat the macro doesCooperation
Scaled displayRead raw value × factor for display; reverse-scale on inputPLC stores raw only; scaling lives only in the HMI
Permission managementLogin check, show/hide buttons by levelPLC holds a permission-level word; the macro reads and shows/hides
Alarm history pagingRead the PLC's alarm history area page by pagePLC records; the macro leafs through
Input pre-checkRange-check on entry, prompt without writingThe PLC still clamps as the backstop
One-key exportPack data to USB / export CSVData from the PLC area; the macro only moves it

Note the "scaling in one place only" principle: the scaling factor lives either only in the HMI macro or only in the PLC — both sides doing it guarantees an eventual edit-miss and display/control divergence.

3. How the PLC prepares for the HMI

① Interface-area planning: a dedicated HMI read/write region (setpoints, status, commands, alarms) with fixed D-area blocks and a drawn mapping table; ② command handshake: HMI buttons write a "command word + command number", the PLC processes on edge detection and writes back "done/failed" — the same protocol as module handshakes; ③ standardised alarm area: active alarm word + history area in fixed format, HMI-mapped by bit/word; ④ write protection: critical parameters (calibration, interlock settings) kept out of HMI-writable addresses, or protected by a "write-enable word" (HMI writes the enable first, edits, and the enable auto-locks on timeout).

4. Handshake example: how an HMI button commands safely

StepHMI macroPLC
1Check the ready status wordStatus word refreshed by the PLC
2Write parameters to the agreed area, write command number, set the request bitDetects the request bit's rising edge
3Wait for the done bit (macro polls with timeout)Executes, writes the result code, sets done
4Read the result code, show success/reasonClears done for the next round

The macro's "wait" is polling with a timeout (macros cannot block); never a dead loop — a looping macro freezes the screen thread and the whole panel stops responding.

5. Common errors

SymptomCauseFix
Machine uncontrolled when the HMI diesKey control logic inside macrosMove the logic back to the PLC
Buttons execute multiple times when tappedCommand on level, no edge/handshakeCommand word + edge + done handshake
Display and control values disagreeScaling on both sidesScaling in one place only
Operator edits what he should notNo permission zones / write-enableTiered permissions + write-enable protection
HMI occasionally freezesDead-loop waiting in a macroPolling + timeout

6. Notes

The PLC–HMI relation is master and servant: the PLC is the machine's brain, the HMI its face and mouth. Macros make the face cleverer (scaling, guidance, records) — but the brain's duties (judgement, control, protection) yield not one inch. Every "control logic in a macro" scheme is exposed the moment the HMI loses power — test the division with that sentence and it never goes wrong.

7. References

The functional allocation between HMI and control follows GB 5226.1 / IEC 60204-1 (control functions must not depend on the human-machine interface); macro syntax and capabilities follow the HMI manual (Weinview, Kinco, Pro-face etc.); parameter write-protection and permission management follow the corporate quality system.

8. Cautions

⚠️ Three traps to avoid:
① Interlock judgements written into HMI macros — screen off or page switched, protection dies;
② A dead-loop wait for the PLC's answer inside a macro — the whole screen freezes;
③ The scaling factor kept in both PLC and HMI — one edit missed, display and control diverge.

Add one review question: "with the screen dead, what happens to this logic?" — no answer means it moves back to the PLC.

Related reading

Related 3D models: Ready to build it? Download free 3D models & CAD drawings at MOULDL »
MOULDL · Electrical Knowledge Base · free self-study reference for electrical & automation engineers, 3D CAD models at MOULDL