Status History & Count History

🔁 Derived Events เช่น Asset Status และ Production Count

📌 ใช้ทำอะไร

  • สร้าง Derived Data (ข้อมูลอนุพันธ์) จาก Tag เช่น

    • สถานะเครื่องจักร: Running, Idle, Stop

    • จำนวนการผลิต: นับชิ้นที่ผลิต

  • บันทึกลงฐานข้อมูล MS-SQL เพื่อใช้ในการรายงาน, Dashboard, วิเคราะห์ OEE

🧩 กระบวนการทำงาน

  1. Tag ถูกสร้างเป็น UDT Instance เช่น Machine01.Status, Machine01.Counter

  2. เขียน Gateway Event Script หรือ Tag Change Script เพื่อตรวจสอบการเปลี่ยนแปลง แล้ว Insert ลงฐานข้อมูล

  3. บันทึกลง:

    • MS-SQL (ใช้ร่วมกับระบบ  Dashboard, Analysis , ERP/BI หรือ External Tool)

🔧 ตัวอย่าง Script (Tag Change → Insert PostgreSQL + MS-SQL)

Tag Change Script:

# ตัวอย่างใน Ignition Tag Change Script if previousValue.value != currentValue.value: status = currentValue.value timestamp = system.date.now() # เขียนลง MS-SQL system.db.runPrepUpdate( "INSERT INTO asset_status_history (asset_code, status, timestamp) VALUES (?, ?, ?)", ["MACHINE01", status, timestamp], database="mssql_db" )

Count Example (Production Count):

if currentValue.value > previousValue.value: count = currentValue.value timestamp = system.date.now() system.db.runPrepUpdate( "INSERT INTO production_count (machine_code, count, timestamp) VALUES (?, ?, ?)", ["MACHINE01", count, timestamp], database="mssql_db" )

📦 โครงสร้างตารางที่ใช้ (แนะนำ)

✅ Table: asset_status_history

CREATE TABLE asset_status_history ( id SERIAL PRIMARY KEY, asset_code VARCHAR(50), status VARCHAR(20), timestamp TIMESTAMP DEFAULT NOW() );

✅ Table: production_count

CREATE TABLE production_count ( id SERIAL PRIMARY KEY, machine_code VARCHAR(50), count INTEGER, timestamp TIMESTAMP DEFAULT NOW() );

🧩 สรุปภาพรวมการทำงาน Store

หมวดใช้สำหรับเก็บไว้ที่เก็บเมื่อใช้โมดูล
Raw Parameters (Tag Historian)Digital Twin, TrendMS-SQLเมื่อค่าเปลี่ยนTag Historian Module
Status HistoryDowntime AnalysisMS-SQLเมื่อ State เปลี่ยนGateway/Tag Scripts
Count Historyผลิตชิ้นงานMS-SQLเมื่อค่าจำนวนเพิ่มGateway/Tag Scripts