private void DisplayMachineData(ModbusTcp.TcpResponse tcpResponse) { if (tcpResponse.Exception == null) { ModbusTcp.MachineResponseData responseData = tcpResponse.MachineResponses[0]; if (responseData.Message.Length > 0) { //사출기 문제발생 } else { Dictionary <string, string> machineData = responseData.MachineData; string[] fieldCodes = machineData.Keys.ToArray(); for (int i = 0; i < fieldCodes.Length; i++) { string fieldCode = fieldCodes[i]; if (dataControls.ContainsKey(fieldCode)) { setControlText(dataControls[fieldCode], machineData[fieldCode]); } } try { decimal tCount; decimal cCount; int targetCount; int currentCount; if (decimal.TryParse(machineData["S00002"], out tCount) && decimal.TryParse(machineData["A00011"], out cCount)) { targetCount = Convert.ToInt32(tCount); currentCount = Convert.ToInt32(cCount); setChartLeft(0, currentCount, targetCount); } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } } } else { ModbusTcp.LogWriter.WriteLog_Error(tcpResponse.Exception); } }
private void DisplayMoldName(ModbusTcp.TcpResponse tcpResponse) { if (tcpResponse.Exception == null) { ModbusTcp.MachineResponseData responseData = tcpResponse.MachineResponses[0]; if (responseData.Message.Length > 0) { //사출기 문제발생 } else { Dictionary <string, string> machineData = responseData.MachineData; string[] fieldCodes = machineData.Keys.ToArray(); string moldName = string.Empty; for (int i = 0; i < machineData.Count; i++) { string fieldCode = fieldCodes[i]; string valueString = machineData.ContainsKey(fieldCode) ? machineData[fieldCode] : ""; decimal valueDecimal; if (decimal.TryParse(valueString, out valueDecimal)) { char charA = (char)(valueDecimal / 256); char charB = (char)(valueDecimal % 256); moldName += charA; moldName += charB; } } //금형명 표기 setControlText(labelMoldName, moldName); } } else { ModbusTcp.LogWriter.WriteLog_Error(tcpResponse.Exception); } }
private void DisplayMachineState(ModbusTcp.TcpResponse tcpResponse) { string mode = string.Empty; if (tcpResponse.Exception == null) { ModbusTcp.MachineResponseData responseData = tcpResponse.MachineResponses[0]; if (responseData.Message.Length > 0) { //사출기 문제발생 } else if (responseData.IsConnected == false) { if (commonVar.whichLang == "English") { mode = "No Response"; } else { mode = "연결안됨"; } setControlText(stateDriveMode, mode, (Image)(Properties.Resources.lostConnection_iconOnly)); } else { Dictionary <string, string> machineState = responseData.MachineData; if (machineState["A00007"].Equals("1")) { //경보 on setControlBackColor(stateAlarm, colorRed); } else { //경보 off setControlBackColor(stateAlarm, colorBlue); } if (machineState["A00001"].Equals("1")) { //저속개폐 if (commonVar.whichLang == "English") { mode = "Mold setup"; } else { mode = "저속개폐"; } setControlText(stateDriveMode, mode, (Image)(Properties.Resources.slow_icononly)); } else if (machineState["A00002"].Equals("1")) { //수동운전 if (commonVar.whichLang == "English") { mode = "Manual"; } else { mode = "수동"; } setControlText(stateDriveMode, mode, (Image)(Properties.Resources.manual_icononly)); } else if (machineState["A00003"].Equals("1")) { //semi auto if (commonVar.whichLang == "English") { mode = "Semi Auto"; } else { mode = "반자동"; } setControlText(stateDriveMode, mode, (Image)(Properties.Resources.semiauto_icononly)); } else if (machineState["A00004"].Equals("1")) { //full auto if (commonVar.whichLang == "English") { mode = "Full Auto"; } else { mode = "자동"; } setControlText(stateDriveMode, mode, (Image)(Properties.Resources.fullauto_icononly)); } else//가끔 전부다 0인 경우가 있음 { setControlText(stateDriveMode, mode); } if (machineState["A00005"].Equals("1")) { //1사이클 완료 //flash 혹은 다른 방법 } if (machineState["A00008"].Equals("1")) { //히터 on setControlBackColor(stateHeater, colorRed); } else { //히터 off setControlBackColor(stateHeater, colorBlue); } if (machineState["A00009"].Equals("1")) { //모터 on setControlBackColor(stateMotor, colorYellow); } else { //모터 off setControlBackColor(stateMotor, colorBlue); } } } else { if (commonVar.whichLang == "English") { mode = "No Response"; } else { mode = "연결안됨"; } setControlText(stateDriveMode, mode, (Image)(Properties.Resources.lostConnection_iconOnly)); ModbusTcp.LogWriter.WriteLog_Error(tcpResponse.Exception); } }