private void Event_Hdl_connectionlost(int iRetMethod) { var iRetClose = axActUtlType1.Close(); clear_plcstatus(); //Reset moi hien thi trang thai cua PLC va RD77 txt_LogicalStationNo.Enabled = true; //Enable o nhap ket noi voi PLC btn_PLCConnect.Enabled = true; //Enable nut ket noi voi PLC btn_PLCDisconnect.Enabled = false; //Disable nut ket noi voi PLC Tmr_PLCMntr.Stop(); MessageBox.Show( string.Format("Kết nối bị ngắt đột ngột. Kiểm tra lại mọi thiết bị, đường dây, khởi động lại phần mềm hoặc máy tính nếu cần.\nError Code: {0}", string.Format("0x{0:x8}", iRetMethod)), @"Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); }
private void btn_PLCDisconnect_Click(object sender, EventArgs e) { var iReturnCode = axActUtlType1.Close(); if (iReturnCode == 0) { txt_LogicalStationNo.Enabled = true; btn_PLCConnect.Enabled = true; btn_PLCDisconnect.Enabled = false; Tmr_PLCMntr.Stop(); //ngat timer clear_plcstatus(); MessageBox.Show(@"PLC đã được ngắt kết nối.", @"PLC Disconnection", MessageBoxButtons.OK); } else { MessageBox.Show("ERROR"); } }
private void btn_PLCConnect_Click(object sender, EventArgs e) { int iLogicalStationNumber = 0; if (Int32.TryParse(txt_LogicalStationNo.Text, out iLogicalStationNumber)) { axActUtlType1.ActLogicalStationNumber = iLogicalStationNumber; int iReturnCode = this.axActUtlType1.Open(); if (iReturnCode == 0) { txt_LogicalStationNo.Enabled = false; btn_PLCConnect.Enabled = false; btn_PLCDisconnect.Enabled = true; if (Tmr_PLCMntr.Enabled == false) { Tmr_PLCMntr.Start(); } string szCPUName; int szCPUType; var cpuTypeRet = axActUtlType1.GetCpuType(out szCPUName, out szCPUType); if (cpuTypeRet == 0) { lbl_CPUName.Text = szCPUName; lbl_ConnectionStatus.Text = "OK"; lbl_ConnectionStatus.BackColor = Color.DarkGreen; } else { lbl_CPUName.Text = "ERROR"; } MessageBox.Show(@"PLC đã được kết nối.", @"PLC Connection", MessageBoxButtons.OK); } } else { MessageBox.Show("Nhap lai "); } }