using System; using System.Linq; using System.Collections.ObjectModel; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; using ITC81DB_0H.Forms; using ITC81DB_2H_ImageDll; using SmartX; using ITC81DB_2H.Datastore; namespace ITC81DB_0H.Controls { public partial class ControlMainDisplayModbus : UserControl { #region Field private FormMainDisplay m_ParentForm; private UInt32 ReceiveCount; private static int ModbusCount = 20; private Collection CollectionOffset; private Collection CollectionContents; #endregion #region Constructor public ControlMainDisplayModbus(FormMainDisplay parent) { InitializeComponent(); this.ParentForm = parent; this.DefaultSetting(); this.InitializeDesign(); } #endregion #region Property public FormMainDisplay ParentForm { get { return this.m_ParentForm; } private set { this.m_ParentForm = value; } } #endregion #region Method public void InitializeDesign() { if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.English) { #region 영문 this.labelTitlePort.Text = "Port"; this.labelTitleStartAddr1.Text = "Start"; this.labelTitleStartAddr2.Text = "Address"; this.labelTitleReceiveCount1.Text = "Receive"; this.labelTitleReceiveCount2.Text = "Count"; this.labelTitleOffset1.Text = this.labelTitleOffset2.Text = this.labelTitleOffset3.Text = "Offset"; this.labelTitleContents1.Text = this.labelTitleContents2.Text = this.labelTitleContents3.Text = "Contents"; this.labelTitleValue1.Text = this.labelTitleValue2.Text = this.labelTitleValue3.Text = "Value"; for (int i = 1; i <= ModbusCount; i++) this.CollectionOffset[i - 1].Font = new Font("새굴림", 9, FontStyle.Regular); this.labelContents1.Text = "Update Flag"; this.labelContents2.Text = "Equip-ID"; this.labelContents3.Text = "Current No."; this.labelContents4.Text = "Under Value"; this.labelContents5.Text = "Pass Value"; this.labelContents6.Text = "Over Value"; this.labelContents7.Text = "Tare Value"; this.labelContents8.Text = "Under Count"; this.labelContents9.Text = "Pass Count"; this.labelContents10.Text = "Over Count"; this.labelContents11.Text = "Faulty Count"; this.labelContents12.Text = "ExNG Count"; this.labelContents13.Text = "Total Count"; this.labelContents14.Text = "Grade"; this.labelContents15.Text = "Weight"; this.labelContents16.Text = "Operation"; this.labelContents17.Text = "Alarm"; this.labelContents18.Text = "Speed(ea/m)"; this.labelContents19.Text = "Metal Count"; this.labelContents20.Text = "Double Count"; this.labelHelp.Text = "※ Grade 0:Over, 1:Pass, 2:Under, 3:Metal, 4:Double, 5:ETC"; #endregion } else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Chinese) { #region 중문 this.labelTitlePort.Text = "端口"; this.labelTitleStartAddr1.Text = "起始"; this.labelTitleStartAddr2.Text = "地址"; this.labelTitleReceiveCount1.Text = "接收"; this.labelTitleReceiveCount2.Text = "计数"; this.labelTitleOffset1.Text = this.labelTitleOffset2.Text = this.labelTitleOffset3.Text = "抵消"; this.labelTitleContents1.Text = this.labelTitleContents2.Text = this.labelTitleContents3.Text = "物品"; this.labelTitleValue1.Text = this.labelTitleValue2.Text = this.labelTitleValue3.Text = "值"; for (int i = 1; i <= ModbusCount; i++) this.CollectionOffset[i - 1].Font = new Font("새굴림", 9, FontStyle.Regular); this.labelContents1.Text = "更新旗帜"; this.labelContents2.Text = "设备编号"; this.labelContents3.Text = "当前号码"; this.labelContents4.Text = "下限"; this.labelContents5.Text = "标准"; this.labelContents6.Text = "上限"; this.labelContents7.Text = "皮重"; this.labelContents8.Text = "下限计数"; this.labelContents9.Text = "标准计数"; this.labelContents10.Text = "上限计数"; this.labelContents11.Text = "剔除计数"; this.labelContents12.Text = "其他不良计数"; this.labelContents13.Text = "总共计数"; this.labelContents14.Text = "等级"; this.labelContents15.Text = "目前的体重"; this.labelContents16.Text = "运行状态"; this.labelContents17.Text = "报警状态"; this.labelContents18.Text = "速度(个/分钟)"; this.labelContents19.Text = "金属计数"; this.labelContents20.Text = "双重计数"; this.labelHelp.Text = "※ 等级 0:上限, 1:标准, 2:下限, 3:金属, 4:双重, 5:等等"; #endregion } else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Czech) { #region 체코어 this.labelTitlePort.Text = "Port"; this.labelTitleStartAddr1.Text = "Počáteční"; this.labelTitleStartAddr2.Text = "adresa"; this.labelTitleReceiveCount1.Text = "Příjem"; this.labelTitleReceiveCount2.Text = "Count"; this.labelTitleOffset1.Text = this.labelTitleOffset2.Text = this.labelTitleOffset3.Text = "Offset"; this.labelTitleContents1.Text = this.labelTitleContents2.Text = this.labelTitleContents3.Text = "Položka"; this.labelTitleValue1.Text = this.labelTitleValue2.Text = this.labelTitleValue3.Text = "Hodnota"; for (int i = 1; i <= ModbusCount; i++) this.CollectionOffset[i - 1].Font = new Font("새굴림", 8, FontStyle.Regular); this.labelContents1.Text = "Aktualizovat příznak"; this.labelContents2.Text = "ID zařízení"; this.labelContents3.Text = "Aktuální číslo"; this.labelContents4.Text = "Min."; this.labelContents5.Text = "Váha"; this.labelContents6.Text = "Max."; this.labelContents7.Text = "Tára"; this.labelContents8.Text = "Min. Počítat"; this.labelContents9.Text = "Váha Počítat"; this.labelContents10.Text = "Max. Počítat"; this.labelContents11.Text = "Vadný Počítat"; this.labelContents12.Text = "Jiné vadné Počítat"; this.labelContents13.Text = "Celkový součet"; this.labelContents14.Text = "Stupnice"; this.labelContents15.Text = "Aktuální hmotnost"; this.labelContents16.Text = "Provozní stav"; this.labelContents17.Text = "Stav alarmu"; this.labelContents18.Text = "Rychlost (ea/min)"; this.labelContents19.Text = "Kovový hrabě"; this.labelContents20.Text = "Dvojitý počet"; this.labelHelp.Text = "※ Stupnice 0:Max., 1:Váha, 2:Min., 3:Metal, 4:Dvojitý, 5:Ostatní"; #endregion } else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Russian) { #region 러시아어 this.labelTitlePort.Text = "Порт"; this.labelTitleStartAddr1.Text = "Начальный"; this.labelTitleStartAddr2.Text = "адрес"; this.labelTitleReceiveCount1.Text = "Счетчик"; this.labelTitleReceiveCount2.Text = "приема"; this.labelTitleOffset1.Text = this.labelTitleOffset2.Text = this.labelTitleOffset3.Text = "Oфсетный"; this.labelTitleContents1.Text = this.labelTitleContents2.Text = this.labelTitleContents3.Text = "Элемент"; this.labelTitleValue1.Text = this.labelTitleValue2.Text = this.labelTitleValue3.Text = "Ценить"; for (int i = 1; i <= ModbusCount; i++) this.CollectionOffset[i - 1].Font = new Font("새굴림", 8, FontStyle.Regular); this.labelContents1.Text = "Обновить флаг"; this.labelContents2.Text = "ID оборудования"; this.labelContents3.Text = "Текущий номер"; this.labelContents4.Text = "Мало"; this.labelContents5.Text = "Норма"; this.labelContents6.Text = "Много"; this.labelContents7.Text = "Тара"; this.labelContents8.Text = "Мало счет"; this.labelContents9.Text = "Норма счет"; this.labelContents10.Text = "Много счет"; this.labelContents11.Text = "Дефект счет"; this.labelContents12.Text = "Другие дефект счет"; this.labelContents13.Text = "Итого"; this.labelContents14.Text = "Сортировка"; this.labelContents15.Text = "Нынешний вес"; this.labelContents16.Text = "Статус работы"; this.labelContents17.Text = "Состояние тревоги"; this.labelContents18.Text = "Скорость(ea/m)"; this.labelContents19.Text = "Металлов счет"; this.labelContents20.Text = "Двойной счет"; this.labelHelp.Text = "※ Сортировка 0:Много, 1:Норма, 2:Мало, 3:Металл, 4:Двойной, 5:и т.д."; #endregion } else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.German) { #region 독일어 this.labelTitlePort.Text = "Port"; this.labelTitleStartAddr1.Text = "Start-"; this.labelTitleStartAddr2.Text = "adresse"; this.labelTitleReceiveCount1.Text = "Anzahl"; this.labelTitleReceiveCount2.Text = "empfangen"; this.labelTitleOffset1.Text = this.labelTitleOffset2.Text = this.labelTitleOffset3.Text = "Ausgleichen"; this.labelTitleContents1.Text = this.labelTitleContents2.Text = this.labelTitleContents3.Text = "Artikel"; this.labelTitleValue1.Text = this.labelTitleValue2.Text = this.labelTitleValue3.Text = "Wert"; for (int i = 1; i <= ModbusCount; i++) this.CollectionOffset[i - 1].Font = new Font("새굴림", 8, FontStyle.Regular); this.labelContents1.Text = "Flag aktualisieren"; this.labelContents2.Text = "ID-Vorrichtung"; this.labelContents3.Text = "Aktuelle Nummer"; this.labelContents4.Text = "Min. "; this.labelContents5.Text = "Bestehen"; this.labelContents6.Text = "Max."; this.labelContents7.Text = "Tara"; this.labelContents8.Text = "Min. Zahl"; this.labelContents9.Text = "Bestehen Zahl"; this.labelContents10.Text = "Max. Zahl"; this.labelContents11.Text = "Schlecht Zahl"; this.labelContents12.Text = "Andere Schlecht Zahl"; this.labelContents13.Text = "Komplette Anzahl"; this.labelContents14.Text = "Grad"; this.labelContents15.Text = "Aktuelles Gewicht"; this.labelContents16.Text = "Betriebsstatus"; this.labelContents17.Text = "Alarmstatus"; this.labelContents18.Text = "Geschwindigkeit"; this.labelContents19.Text = "Metallanzahl"; this.labelContents20.Text = "Doppelte Zählung"; this.labelHelp.Text = "※ Grad 0:Max., 1:Bestehen, 2:Min., 3:Metall, 4:Doppelte Eingabe, 5:Usw."; #endregion } else { #region 한글 this.labelTitlePort.Text = "Port"; this.labelTitleStartAddr1.Text = "Start"; this.labelTitleStartAddr2.Text = "Address"; this.labelTitleReceiveCount1.Text = "Receive"; this.labelTitleReceiveCount2.Text = "Count"; this.labelTitleOffset1.Text = this.labelTitleOffset2.Text = this.labelTitleOffset3.Text = "Offset"; this.labelTitleContents1.Text = this.labelTitleContents2.Text = this.labelTitleContents3.Text = "항목"; this.labelTitleValue1.Text = this.labelTitleValue2.Text = this.labelTitleValue3.Text = "Value"; for (int i = 1; i <= ModbusCount; i++) this.CollectionOffset[i - 1].Font = new Font("새굴림", 9, FontStyle.Regular); this.labelContents1.Text = "갱신 Flag"; this.labelContents2.Text = "장비 ID"; this.labelContents3.Text = "현재 품번"; this.labelContents4.Text = "하한값"; this.labelContents5.Text = "기준값"; this.labelContents6.Text = "상한값"; this.labelContents7.Text = "용기값"; this.labelContents8.Text = "경량 개수"; this.labelContents9.Text = "정량 개수"; this.labelContents10.Text = "과량 개수"; this.labelContents11.Text = "불량 개수"; this.labelContents12.Text = "기타불량 개수"; this.labelContents13.Text = "총 개수"; this.labelContents14.Text = "판정등급"; this.labelContents15.Text = "현재 중량값"; this.labelContents16.Text = "운전 상태"; this.labelContents17.Text = "알람 상태"; this.labelContents18.Text = "속도(ea/m)"; this.labelContents19.Text = "금속검출 개수"; this.labelContents20.Text = "이중진입 개수"; this.labelHelp.Text = "※ 판정등급 0:과량, 1:정량, 2:경량, 3:금속검출, 4:이중진입, 5:기타"; #endregion } } private void DefaultSetting() { this.CollectionOffset = new Collection(); this.CollectionOffset.Clear(); this.CollectionOffset.Add(this.labelOffset1); this.CollectionOffset.Add(this.labelOffset2); this.CollectionOffset.Add(this.labelOffset3); this.CollectionOffset.Add(this.labelOffset4); this.CollectionOffset.Add(this.labelOffset5); this.CollectionOffset.Add(this.labelOffset6); this.CollectionOffset.Add(this.labelOffset7); this.CollectionOffset.Add(this.labelOffset8); this.CollectionOffset.Add(this.labelOffset9); this.CollectionOffset.Add(this.labelOffset10); this.CollectionOffset.Add(this.labelOffset11); this.CollectionOffset.Add(this.labelOffset12); this.CollectionOffset.Add(this.labelOffset13); this.CollectionOffset.Add(this.labelOffset14); this.CollectionOffset.Add(this.labelOffset15); this.CollectionOffset.Add(this.labelOffset16); this.CollectionOffset.Add(this.labelOffset17); this.CollectionOffset.Add(this.labelOffset18); this.CollectionOffset.Add(this.labelOffset19); this.CollectionOffset.Add(this.labelOffset20); this.CollectionContents = new Collection(); this.CollectionContents.Clear(); this.CollectionContents.Add(this.labelContents1); this.CollectionContents.Add(this.labelContents2); this.CollectionContents.Add(this.labelContents3); this.CollectionContents.Add(this.labelContents4); this.CollectionContents.Add(this.labelContents5); this.CollectionContents.Add(this.labelContents6); this.CollectionContents.Add(this.labelContents7); this.CollectionContents.Add(this.labelContents8); this.CollectionContents.Add(this.labelContents9); this.CollectionContents.Add(this.labelContents10); this.CollectionContents.Add(this.labelContents11); this.CollectionContents.Add(this.labelContents12); this.CollectionContents.Add(this.labelContents13); this.CollectionContents.Add(this.labelContents14); this.CollectionContents.Add(this.labelContents15); this.CollectionContents.Add(this.labelContents16); this.CollectionContents.Add(this.labelContents17); this.CollectionContents.Add(this.labelContents18); this.CollectionContents.Add(this.labelContents19); this.CollectionContents.Add(this.labelContents20); this.buttonBypassDirection.ButtonUp(); this.ReceiveCount = 0; this.labelReceiveCount.Text = this.ReceiveCount.ToString(); this.labelUpdateFlag.Text = ""; this.labelEquipmentID.Text = ""; this.labelCurrentNo.Text = ""; this.labelUnder.Text = ""; this.labelPass.Text = ""; this.labelOver.Text = ""; this.labelTare.Text = ""; this.labelUnderCount.Text = ""; this.labelPassCount.Text = ""; this.labelOverCount.Text = ""; this.labelNGCount.Text = ""; this.labelExNGCount.Text = ""; this.labelTotalCount.Text = ""; this.labelGrade.Text = ""; this.labelWeight.Text = ""; this.labelOperationStatus.Text = ""; this.labelAlarmStatus.Text = ""; this.labelSpeed.Text = ""; this.labelMetal.Text = ""; this.labelDouble.Text = ""; } public void Clear() { this.UpdateData(this.ParentForm.ParentForm.Current30000ModbusData); } public void UpdateEquipmentStatusDisplay(Define.E_EquipmentStatus status) { } public void UpdateReceiveCount() { if (this.ReceiveCount > 999999999) this.ReceiveCount = 0; else { this.ReceiveCount++; this.labelReceiveCount.Text = this.ReceiveCount.ToString(); } } public void UpdateData(_30000_ModbusData mData) { if (this.buttonBypassDirection.ButtonStatus == SmartX.SmartButton.BUTSTATUS.UP) { this.labelUpdateFlag.Text = mData.IsUpdate.ToString(); this.labelEquipmentID.Text = mData.EquipmentID.ToString(); this.labelCurrentNo.Text = mData.ProductNo.ToString(); this.labelUnder.Text = mData.UnderValue.ToString(); this.labelPass.Text = mData.PassValue.ToString(); this.labelOver.Text = mData.OverValue.ToString(); this.labelTare.Text = mData.TareValue.ToString(); this.labelUnderCount.Text = mData.UnderCount.ToString(); this.labelPassCount.Text = mData.PassCount.ToString(); this.labelOverCount.Text = mData.OverCount.ToString(); this.labelNGCount.Text = mData.NGCount.ToString(); this.labelExNGCount.Text = mData.ExNGCount.ToString(); this.labelTotalCount.Text = mData.TotalCount.ToString(); this.labelGrade.Text = mData.Grade.ToString(); this.labelWeight.Text = mData.Weight.ToString(); this.labelOperationStatus.Text = mData.OperationStatus.ToString(); this.labelAlarmStatus.Text = mData.AlarmStatus.ToString(); this.labelSpeed.Text = mData.Speed.ToString(); this.labelMetal.Text = mData.MetalDetectionCount.ToString(); this.labelDouble.Text = mData.DoubleEntryCount.ToString(); } else { this.labelUpdateFlag.Text = mData.HexStringIsUpdate; this.labelEquipmentID.Text = mData.HexStringEquipmentID; this.labelCurrentNo.Text = mData.HexStringProductNo; this.labelUnder.Text = mData.HexStringUnderValue; this.labelPass.Text = mData.HexStringPassValue; this.labelOver.Text = mData.HexStringOverValue; this.labelTare.Text = mData.HexStringTareValue; this.labelUnderCount.Text = mData.HexStringUnderCount; this.labelPassCount.Text = mData.HexStringPassCount; this.labelOverCount.Text = mData.HexStringOverCount; this.labelNGCount.Text = mData.HexStringNGCount; this.labelExNGCount.Text = mData.HexStringExNGCount; this.labelTotalCount.Text = mData.HexStringTotalCount; this.labelGrade.Text = mData.HexStringGrade; this.labelWeight.Text = mData.HexStringWeight; this.labelOperationStatus.Text = mData.HexStringOperationStatus; this.labelAlarmStatus.Text = mData.HexStringAlarmStatus; this.labelSpeed.Text = mData.HexStringSpeed; this.labelMetal.Text = mData.HexStringMetalDetectionCount; this.labelDouble.Text = mData.HexStringDoubleEntryCount; } } public void UpdateOffset(bool master, int startAddress) { if (master == true) { for (int i = 0; i < ModbusCount; i++) { this.CollectionOffset[i].Text = startAddress.ToString(); startAddress += 2; } } else { int address = 10; for (int i = 0; i < ModbusCount; i++) { this.CollectionOffset[i].Text = "0x" + address.ToString("X4"); address += 2; } } } public void UpdateDisplay(string portName) { switch (portName) { case "COM1": if (this.ParentForm.ParentForm.SystemConfig2.ModbusRTUSelectFunction == (int)Define.E_ModbusFunction._04_ReadInputRegister) { this.labelStartAddress.Text = "-"; this.UpdateOffset(false, this.ParentForm.ParentForm.SystemConfig2.ModbusRTUStartAddressCOM1); } else { this.labelStartAddress.Text = this.ParentForm.ParentForm.SystemConfig2.ModbusRTUStartAddressCOM1.ToString(); this.UpdateOffset(true, this.ParentForm.ParentForm.SystemConfig2.ModbusRTUStartAddressCOM1); } break; case "COM3": if (this.ParentForm.ParentForm.SystemConfig2.ModbusRTUSelectFunction == (int)Define.E_ModbusFunction._04_ReadInputRegister) { this.labelStartAddress.Text = "-"; this.UpdateOffset(false, this.ParentForm.ParentForm.SystemConfig2.ModbusRTUStartAddressCOM3); } else { this.labelStartAddress.Text = this.ParentForm.ParentForm.SystemConfig2.ModbusRTUStartAddressCOM3.ToString(); this.UpdateOffset(true, this.ParentForm.ParentForm.SystemConfig2.ModbusRTUStartAddressCOM3); } break; case "COM4": if (this.ParentForm.ParentForm.SystemConfig2.ModbusRTUSelectFunction == (int)Define.E_ModbusFunction._04_ReadInputRegister) { this.labelStartAddress.Text = "-"; this.UpdateOffset(false, this.ParentForm.ParentForm.SystemConfig2.ModbusRTUStartAddressCOM4); } else { this.labelStartAddress.Text = this.ParentForm.ParentForm.SystemConfig2.ModbusRTUStartAddressCOM4.ToString(); this.UpdateOffset(true, this.ParentForm.ParentForm.SystemConfig2.ModbusRTUStartAddressCOM4); } break; case "TCP": if (this.ParentForm.ParentForm.SystemConfig2.ModbusTCPSelectFunction == (int)Define.E_ModbusFunction._04_ReadInputRegister) { this.labelStartAddress.Text = "-"; this.UpdateOffset(false, this.ParentForm.ParentForm.SystemConfig2.ModbusTCPStartAddress); } else { this.labelStartAddress.Text = this.ParentForm.ParentForm.SystemConfig2.ModbusTCPStartAddress.ToString(); this.UpdateOffset(true, this.ParentForm.ParentForm.SystemConfig2.ModbusTCPStartAddress); } break; default: break; } } public void DisplayRefresh(SystemStatus status) { this.comboBoxPort.Items.Clear(); if (this.ParentForm.ParentForm.SystemConfig1.SerialCOM1Mode == (int)Define.E_CommMode.f22_Modbus || this.ParentForm.ParentForm.SystemConfig1.SerialCOM1Mode == (int)Define.E_CommMode.f16_OPC) this.comboBoxPort.Items.Add("COM1"); if (this.ParentForm.ParentForm.SystemConfig1.SerialCOM3Mode == (int)Define.E_CommMode.f22_Modbus || this.ParentForm.ParentForm.SystemConfig1.SerialCOM3Mode == (int)Define.E_CommMode.f16_OPC) this.comboBoxPort.Items.Add("COM3"); if (this.ParentForm.ParentForm.SystemConfig1.SerialCOM4Mode == (int)Define.E_CommMode.f22_Modbus || this.ParentForm.ParentForm.SystemConfig1.SerialCOM4Mode == (int)Define.E_CommMode.f16_OPC) this.comboBoxPort.Items.Add("COM4"); if (this.ParentForm.ParentForm.SystemConfig2.EthernetCommMode == (int)Define.E_CommMode.f22_Modbus || this.ParentForm.ParentForm.SystemConfig2.EthernetCommMode == (int)Define.E_CommMode.f16_OPC) this.comboBoxPort.Items.Add("TCP"); this.comboBoxPort.SelectedIndex = 0; this.UpdateDisplay(this.comboBoxPort.SelectedItem.ToString()); this.UpdateData(this.ParentForm.ParentForm.Current30000ModbusData); } #endregion #region Event Handler private void buttonBypassDirection_Click(object sender, EventArgs e) { // Automatic Logout Reset if (this.ParentForm.ParentForm.SystemConfig3.IsPart11 == true) this.ParentForm.Part11AutomaticLogoutReset(); this.UpdateData(this.ParentForm.ParentForm.Current30000ModbusData); } private void comboBoxPort_SelectedIndexChanged(object sender, EventArgs e) { // Automatic Logout Reset if (this.ParentForm.ParentForm.SystemConfig3.IsPart11 == true) this.ParentForm.Part11AutomaticLogoutReset(); this.UpdateDisplay(this.comboBoxPort.SelectedItem.ToString()); } #endregion } }