19 KiB
SCL Scripts Functionality Analysis
Overview of Script Organization
The project consists of several SCL scripts that manage different aspects of the Gateway and Motor-Box control system. Here's a breakdown of the main functional areas:
- Data Conversion (002_FC, 101_FC)
- Remote Control (003_FC, 100_FC)
- System Configuration (004_FC, 020_FC, 021_FC)
- Alarms Management (010_FC)
- Operation Modes (030_FC, 032_FC, 035_FC, 036_FC)
- HMI Interface (050_FC)
Let's analyze each script in detail.
Data Conversion Scripts
002_FC Data Read Conversion
This script handles the reading of data from the ADI structures provided by the Gateway and converts it into a more usable format for the PLC program.
Key functions:
- Determines which Gateway is active based on mode (Auto or Manual)
- Reads ADI_110 data to extract Gateway firmware and box communication status
- Reads ADI_111 data to extract motor and box status information
- Performs byte-by-byte data mapping including:
- Motor status (forward/backward motion, alarms, position status)
- Box status (firmware version, power issues)
- Repeats the same process for Port 2 (ADI_120, ADI_121) if configured
101_FC Data Write Conversion
This script converts the PLC program data format into the proper byte format required by the Gateway ADI structures for writing commands.
Key functions:
- Formats motor position commands into ADI_211 byte structure for each motor
- Sets motor direction, position type, stop command, and reset flags
- Configures current limits for both forward and reverse motion in ADI_212
- Repeats the same process for Port 2 (ADI_221, ADI_222) if configured
Remote Control Scripts
003_FC Remote Control Read
This script handles data transfer from the I/O controller (remote system) to the Gateway control system.
Key functions:
- Reads control word bits from the remote I/O controller
- Reads lifecycle counter and bottle type information
- Checks if local/remote selection is active and accordingly processes or ignores remote commands
100_FC Remote Control Write
This script manages data transfer to the I/O controller, sending status information from the Gateway system.
Key functions:
- Updates status word bits based on system state (manual mode, changeover status, alarms)
- Sends lifecycle counter, actual bottle type, and required bottle type
- Transfers alarm list to remote system
- Maps all data to appropriate I/O controller data locations
System Configuration Scripts
004_FC Zone Activation
A simple script that enables the four operational zones of the system.
020_FC Format Parameters
This script manages format changes and recipe handling for different bottle types.
Key functions:
- Processes format selection requests (manual or from remote control)
- Initiates and monitors recipe loading process
- Transfers recipe data to zone parameters
- Updates position offset information for each actuator
021_FC Area Parameters
This script manages the assignment of actuators to operational zones.
Key functions:
- Checks actuator availability for zone configuration
- Assigns actuators to zones in both zone parameters and motor parameters
- Manages actuator configuration errors
- Monitors zones that haven't completed format change
- Checks if format change is complete across all zones
Alarms Management
010_FC Alarms
This is a comprehensive script handling all system alarms including:
Key functions:
- Box communication alarms for both ports
- Burned fuse detection
- Low voltage detection
- Motor error monitoring
- Gateway communication issues
- Area configuration validation
- Area-specific alarms
- Safety module monitoring
- Area timeout detection
- Recipe loading errors
The script uses various timers for alarm indication and implements a scrolling mechanism to highlight different alarms in sequence.
Operation Modes Scripts
030_FC Aut_Man Selection
This script manages the switching between automatic and manual modes.
Key functions:
- Processes local/remote selection input
- Uses timers to implement mode switching delays
- Sets the appropriate mode flags (Auto or Man)
032_FC Manual Function
This script handles manual control of motors.
Key functions:
- Processes manual movement commands (forward, backward, zero/position)
- Implements motor stop logic
- Handles alarm reset functionality
- Manages motor current limitation settings
- Updates HMI with motor status information
035_FC Automatic Cycle
This script implements the automatic cycle state machine for the format change process.
Key functions:
- Manages 13 states of the automatic cycle (from Manual to Clearing)
- Handles transitions between states based on conditions
- Processes external commands (reset, alarm, format change request)
- Controls the zone state machine
036_FC Area Cycle
This script manages the cycling through zones during format changes.
Key functions:
- Implements a 7-state zone state machine (from inactive to completion)
- Calculates actuator positions based on bottle dimensions
- Checks if actuators have reached their positions
- Controls actuator commands (zero/position, forward/backward)
- Manages manual movement of zones
- Handles stop commands and alarm reset functionality
HMI Interface
050_FC HMI
This script handles the HMI (Human-Machine Interface) functionality.
Key functions:
- Controls lamp blinking for visual indicators
- Updates HMI elements based on system state
- Manages screen-specific elements for different HMI screens
- Updates status LEDs for motors and boxes
- Controls stackable light and buzzer based on system state
Execution Flow
The overall execution flow can be summarized as:
- The system reads configuration from Gateway through data conversion (002_FC)
- Based on mode (auto/manual), it either:
- In Auto mode: Follows the automatic cycle (035_FC) and area cycle (036_FC) state machines
- In Manual mode: Processes manual commands (032_FC)
- Commands are sent to Gateway after conversion (101_FC)
- Alarm conditions are continuously monitored (010_FC)
- HMI is updated with status information (050_FC)
- Remote control information is exchanged (003_FC, 100_FC)
The system uses a combination of state machines, timers, and direct command processing to manage the format change process across multiple zones, ensuring actuators move to the correct positions based on bottle dimensions and configuration parameters.
Motor Movement Command Flow Diagram
This diagram shows how movement commands flow through the system from various input sources (HMI, Automatic Cycle, Remote Control) to the Gateway and ultimately to the motors. It highlights:
- Different command sources
- Processing through the manual and automatic functions
- Data conversion for Gateway communication
- The structure of movement commands, including the Zero/Position mode
- Feedback flow of motor status information
flowchart TD
subgraph "Input Sources"
HMI["HMI Commands\n(Manual Mode)"]
AUT["Automatic Cycle\n(Auto Mode)"]
RMT["Remote Control\n(External Commands)"]
end
subgraph "Command Processing"
MAN_FUNC["FC032 Manual Function\n- Forward/Backward\n- Zero/Position\n- Stop\n- Reset Alarm"]
AREA_CYC["FC036 Area Cycle\n- Automatic Zero/Position\n- Zone Movement\n- Position Calculation"]
MOV_CMD["Movement Command Generation\n- Position Value\n- Direction\n- Mode\n- Stop/Reset"]
end
subgraph "Data Conversion"
DATA_CONV["FC101 Data Write Conversion\n- Byte/Bit Formatting\n- ADI Structure Mapping"]
end
subgraph "Gateway Communication"
ADI_211["ADI#211/ADI#221\n- Motor Commands Port 1/2"]
ADI_212["ADI#212/ADI#222\n- Current Limits Port 1/2"]
end
subgraph "Feedback Processing"
DATA_READ["FC002 Data Read Conversion\n- Status Interpretation"]
ADI_111["ADI#111/ADI#121\n- Motor Status Port 1/2"]
MOT_STATUS["Motor Status\n- InPosition\n- InZero\n- Moving\n- Alarm"]
end
%% Connections
HMI --> MAN_FUNC
AUT --> AREA_CYC
RMT --> AREA_CYC
MAN_FUNC --> MOV_CMD
AREA_CYC --> MOV_CMD
MOV_CMD --> DATA_CONV
DATA_CONV --> ADI_211
DATA_CONV --> ADI_212
ADI_111 --> DATA_READ
DATA_READ --> MOT_STATUS
MOT_STATUS --> MAN_FUNC
MOT_STATUS --> AREA_CYC
%% Special Motor Commands Breakdown
subgraph "Zero/Position Command Structure (Bit Layout)"
ZP1["Position Value\n(12-bit value 0-4095)"]
ZP2["Direction Sign\n(Bit 4: 1=+, 0=-)"]
ZP3["Position Mode\n(Bit 5: 1=Zero then Position, 0=Relative)"]
ZP4["Stop Motor\n(Bit 6: 1=Stop)"]
ZP5["Reset Alarm\n(Bit 7: 1=Reset)"]
end
MOV_CMD -.-> ZP1
MOV_CMD -.-> ZP2
MOV_CMD -.-> ZP3
MOV_CMD -.-> ZP4
MOV_CMD -.-> ZP5
Data Structures Flow Between Scripts
This diagram illustrates how data flows between the different SCL scripts and data blocks in the system:
- Shows all major data blocks (DB Gateway, DB Cycle, DB AreaPar, etc.)
- Maps connections between functional blocks and data storage
- Highlights key cross-function data flows
- Identifies important data elements (ADI structures, motor status, commands)
flowchart TD
subgraph "Data Storage Blocks"
DB_GW["DB Gateway\n- ADI Input/Output\n- Motor Box Control\n- Status Information"]
DB_CYCLE["DB Cycle\n- Operation Mode\n- State Machines\n- Current Zone\n- Format Data"]
DB_AREA["DB AreaPar\n- Zone Configuration\n- Motor Assignments\n- Position Settings"]
DB_HMI["DB HMI\n- UI Parameters\n- User Selections\n- Status Display"]
DB_MOTOR["DB MotorPar\n- Motor Enables\n- Current Limits\n- Zone Assignments"]
DB_ALARMS["DB Alarms\n- Alarm Conditions\n- Error States\n- Diagnostic Info"]
DB_FORMAT["DB FormatPar\n- Recipe Information\n- Format Settings\n- Bottle Parameters"]
DB_REMOTE["DB Remote Control\n- External Commands\n- Status Reporting"]
end
subgraph "Data Flow Functions"
FC002["FC002\nData Read Conversion"]
FC003["FC003\nRemote Control Read"]
FC010["FC010\nAlarms Management"]
FC020["FC020\nFormat Parameters"]
FC021["FC021\nArea Parameters"]
FC030["FC030\nAut/Man Selection"]
FC032["FC032\nManual Function"]
FC035["FC035\nAutomatic Cycle"]
FC036["FC036\nArea Cycle"]
FC050["FC050\nHMI Interface"]
FC100["FC100\nRemote Control Write"]
FC101["FC101\nData Write Conversion"]
end
%% Primary Data Flows
DB_GW <--> FC002
DB_GW <--> FC101
DB_CYCLE <--> FC035
DB_CYCLE <--> FC036
DB_AREA <--> FC021
DB_AREA <--> FC020
DB_AREA <--> FC036
DB_HMI <--> FC050
DB_HMI <--> FC032
DB_MOTOR <--> FC021
DB_MOTOR <--> FC032
DB_MOTOR <--> FC101
DB_ALARMS <--> FC010
DB_FORMAT <--> FC020
DB_REMOTE <--> FC003
DB_REMOTE <--> FC100
%% Cross-Function Data Flows
FC002 --> FC010
FC002 --> FC032
FC002 --> FC036
FC002 --> FC050
FC003 --> FC035
FC020 --> FC036
FC030 --> FC035
FC032 --> FC101
FC035 --> FC036
FC036 --> FC101
FC050 --> FC032
FC010 --> FC100
%% Key Data Elements
subgraph "Key Data Elements"
ADI_IN["ADI Input Structures\n(110, 111, 120, 121)"]
ADI_OUT["ADI Output Structures\n(211, 212, 221, 222)"]
MOT_STAT["Motor Status\n(Position, Alarms, Movement)"]
MOT_CMD["Motor Commands\n(Position, Direction, Mode)"]
AREA_CONF["Area Configuration\n(Assignments, Parameters)"]
BOT_PARAM["Bottle Parameters\n(Dimensions, Distances)"]
ALARM_STAT["Alarm Status\n(Communication, Hardware)"]
end
ADI_IN -.-> DB_GW
DB_GW -.-> ADI_OUT
MOT_STAT -.-> DB_GW
DB_GW -.-> MOT_CMD
AREA_CONF -.-> DB_AREA
BOT_PARAM -.-> DB_FORMAT
ALARM_STAT -.-> DB_ALARMS
Motor Command Sequence Diagram
This sequence diagram shows the exact flow of a motor command through the system:
- Step-by-step process from command initiation to execution
- Data conversion through FC101
- Command transmission through Gateway to Motor-Box
- Status feedback loop through FC002
- Command termination and final status
sequenceDiagram
autonumber
participant PLC as PLC Control Logic
participant DBGateway as DB Gateway
participant FC101 as FC101 Data Write Conversion
participant Gateway as Gateway Device
participant MotorBox as Motor-Box
participant Motor as Actuator Motor
participant FC002 as FC002 Data Read Conversion
%% Command Generation
Note over PLC: Movement request initiated
PLC->>DBGateway: Set command parameters in<br>DB Gateway.N[g].write.P[p].MotorBoxCtrl[b].Mot[m]
Note over PLC: Position value, PosType, Sign, Stop, Reset bits set
%% Command Conversion & Formatting
PLC->>FC101: Call data write conversion
FC101->>DBGateway: Format command into ADI structure
Note over FC101: Bit-by-bit mapping to ADI_211/221
FC101->>DBGateway: Map current limits to ADI_212/222
%% Command Transmission
DBGateway->>Gateway: Transmit ADI_211/221 command bytes
Gateway->>MotorBox: Forward command to target Motor-Box
MotorBox->>Motor: Execute motor command
%% Feedback Loop
Motor->>MotorBox: Return status (moving, position, alarm)
MotorBox->>Gateway: Send status data
Gateway->>DBGateway: Update ADI_111/121 structures
DBGateway->>FC002: Call data read conversion
FC002->>DBGateway: Update status in structured format
DBGateway->>PLC: Status available for program logic
%% Command Termination
alt In Position Reached
PLC->>DBGateway: Clear command (detected from status)
else Stop Requested
PLC->>DBGateway: Send explicit stop command
end
%% Final Command Flow
PLC->>FC101: Convert final command
FC101->>DBGateway: Update ADI structure
DBGateway->>Gateway: Transmit final command
Gateway->>MotorBox: Forward to Motor-Box
MotorBox->>Motor: Execute final command (stop)
Automatic Cycle and Zone State Machines
This diagram illustrates the state machines that control automatic operation:
- Automatic Cycle State Machine (FC035) with all 13 states
- Zone State Machine (FC036) with 7 states
- Manual Control Functions
- Transitions between states and conditions that trigger them
stateDiagram-v2
[*] --> Manual: System Start
state "Automatic Cycle State Machine (FC035)" as AutoCycle {
state "00 - Manual" as Auto00
state "01 - Stopped" as Auto01
state "02 - Resetting" as Auto02
state "03 - Idle" as Auto03
state "04 - Starting" as Auto04
state "05 - Execute" as Auto05
state "06 - Completing" as Auto06
state "07 - Complete" as Auto07
state "10 - Stopping" as Auto10
state "11 - Aborting" as Auto11
state "12 - Aborted" as Auto12
state "13 - Clearing" as Auto13
Auto00 --> Auto01 : Auto Mode Selected
Auto01 --> Auto02 : Reset Pressed
Auto02 --> Auto03 : No Area Alarms
Auto03 --> Auto04 : Auto Start Delay Complete
Auto04 --> Auto05 : Configure Initial Zone
Auto05 --> Auto10 : Stop Request
Auto05 --> Auto11 : Alarm Condition
Auto05 --> Auto06 : All Zones Complete
Auto06 --> Auto07 : Update Format Status
Auto07 --> Auto01 : Reset Pressed
Auto10 --> Auto01 : Zone Stopped
Auto11 --> Auto12 : Zone Stopped
Auto12 --> Auto01 : Reset Pressed
Auto13 --> Auto01 : No Active Alarms
}
state "Zone State Machine (FC036)" as ZoneSM {
state "00 - Disabled" as Zone00
state "01 - Format Change Required" as Zone01
state "02 - Initial Zone Assignment" as Zone02
state "03 - Load Positions" as Zone03
state "04 - Start Actuators" as Zone04
state "05 - Stop Actuators" as Zone05
state "06 - Zone Completion" as Zone06
Zone00 --> Zone01 : Format Changed
Zone01 --> Zone02 : Auto Cycle Execute
Zone02 --> Zone03 : Recipe Loaded
Zone03 --> Zone04 : Positions Calculated
Zone04 --> Zone05 : All Motors In Position
Zone05 --> Zone06 : All Motors Stopped
Zone06 --> Zone02 : More Zones To Process
Zone06 --> Auto06 : All Zones Complete
}
state "Manual Control Functions (FC032)" as ManualFuncs {
state "Forward/Backward Movement" as ManMove
state "Zero/Position Command" as ManZero
state "Stop Command" as ManStop
state "Reset Alarm" as ManReset
}
Manual --> AutoCycle : Auto Mode
AutoCycle --> Manual : Manual Mode
Manual --> ManualFuncs : Manual Commands
AutoCycle --> ZoneSM : Auto Cycle Execute
Command Data Structure Diagram
This class diagram shows the detailed structure of command data:
- Hierarchical organization of DB Gateway data
- Structure of port, box, and motor specific information
- Command and status data fields
- Command structure interfaces showing bit layouts
- Current limit structure with value definitions
classDiagram
class DBGateway {
+Array[8] N[Gateway]
}
class Gateway {
+Struct read
+Struct write
}
class GatewayRead {
+Array[2] P[Port]
+Array[] ADI_110
+Array[] ADI_111
+Array[] ADI_120
+Array[] ADI_121
}
class GatewayWrite {
+Array[2] P[Port]
+Array[] ADI_211
+Array[] ADI_212
+Array[] ADI_221
+Array[] ADI_222
}
class PortRead {
+USINT MboxNumber
+USINT Firmware
+Array[32] BoxCommunication[Box]
+Array[32] MotorsBoxStatus[Box]
}
class PortWrite {
+Array[32] MotorBoxCtrl[Box]
}
class MotorBoxStatus {
+Array[8] MotorStatus[Motor]
+Struct BoxStatus
}
class MotorStatus {
+BOOL MovingFW
+BOOL MovingBW
+BOOL InPOS
+BOOL Alarm
+BOOL InZero
+BOOL MovingSlowly
+BOOL Reserved1
+BOOL Reserved2
}
class BoxStatus {
+USINT FirmwareVersion
+USINT FirmwareRevision
+BOOL BurnedFuse
+BOOL Undervoltage
}
class MotorBoxCtrl {
+Array[8] Mot[Motor]
}
class MotorCommand {
+INT Position
+BOOL Sign
+BOOL PosType
+BOOL Stop
+BOOL Reset
}
DBGateway "1" *-- "8" Gateway
Gateway "1" *-- "1" GatewayRead
Gateway "1" *-- "1" GatewayWrite
GatewayRead "1" *-- "2" PortRead
GatewayWrite "1" *-- "2" PortWrite
PortRead "1" *-- "32" MotorBoxStatus
PortWrite "1" *-- "32" MotorBoxCtrl
MotorBoxStatus "1" *-- "8" MotorStatus
MotorBoxStatus "1" *-- "1" BoxStatus
MotorBoxCtrl "1" *-- "8" MotorCommand
%% ADI Structure notes
class CommandStructure {
<<Interface>>
Position: 12-bit value (0-4095)
Sign: 1=positive, 0=negative
PosType: 1=Zero then Position, 0=Relative
Stop: 1=stop motor, 0=continue movement
Reset: 1=reset alarm, 0=normal operation
}
class CurrentLimitStructure {
<<Interface>>
Bits 0-2: Reverse current limit
Bits 3-5: Forward current limit
000: 650mA (default)
001: 200mA
010: 300mA
011: 400mA
100: 500mA
101: 600mA
110: 700mA
111: 800mA
}
MotorCommand ..|> CommandStructure