private void UpdateDataPLC() { // Đặt giá trị mặc định cho chuỗi nhận về stringReceive = "NoBarcode" + DateTime.Now.ToString("yy_MM_dd_hh_mm_ss"); // Chạy liên tục Thread while (true) { /// Kiểm tra kết nối PLC và Barcode /// Nếu chưa kết nối, báo Message, Setbit Error Connect #region <Summary> Kiểm tra kết nối PLC Barcode // Kiểm tra Bit SM400 để xác nhận PLC có đang kết nối không var iret = plcKefico.GetDevice("SM400", out SM400); if (iret != 0) { MessageBox.Show(String.Format("0x{0:x8} [HEX]", iret)); return; } // Kiểm tra đã kết nối Barcode hay chưa, nếu chưa thì ResetBit M3012 PLC if (btnConnect.Text == "Connected") { plcKefico.SetDevice("M3012", 1); } else { plcKefico.SetDevice("M3012", 0); } #endregion #region <Summary> Xử lý khi nhận được tín hiệu chụp ảnh từ PLC /// Nếu nhận tín hiệu = 1, và cờ trạng thái captureRunning chưa bật thì chạy hàm CaptureImage iret = plcKefico.GetDevice("M3010", out M3010); // Barcode Begin if ((M3010 == 1) && (!captureRunning)) { // Bật cờ báo đang chụp captureRunning = true; // Bật bit PLC - M3011 báo đang chụp plcKefico.SetDevice("M3011", 1); // Chạy hàm chụp ảnh CaptureImage(stringReceive); // Đặt lại giá trị Barcode mặc định là NoBarcode stringReceive = "NoBarcode" + DateTime.Now.ToString("yy_MM_dd_hh_mm_ss"); } // Reset trạng thái chụp ảnh về chưa chụp if ((M3010 == 0) && (captureRunning)) { // Tắt cờ báo đang chụp khi tín hiệu chụp ảnh từ PLC off captureRunning = false; } #endregion Thread.Sleep(100); } }
private void incProcess(object sender, EventArgs e) { countProcess += 1; countAllowEnd += 1; if (countProcess > 8) { countProcess = 0; } lblProcess.Text = ""; for (int i = 0; i < countProcess; i++) { lblProcess.Text += "_"; } // Check Button ReClick if ((plcRef != null) && (countAllowEnd > 20)) { int buttonRead; var iret = plcRef.GetDevice("X11", out buttonRead); if (buttonRead == 1) { if (stringDoneKheho != null) { stringDoneKheho((valueMax - valueMin).ToString("0.000")); } this.Close(); } } }
private void Button1_Click(object sender, EventArgs e) { int read_result; plc.GetDevice(textBox1.Text, out read_result); textBox2.Text = read_result.ToString(); }
/// <summary> /// 软元件的单个读取 (4 字节数据 ) /// </summary> /// <param name="device"></param> /// <param name="lData"></param> /// <returns></returns> public bool GetDevice(string device, out int lData) { lock (this) { try { int result = actUtlType.GetDevice(device, out lData); if (0 == result) { message = "PLC地址" + device + "读取成功,结果:" + lData; return(true); } else { message = "PLC地址" + device + "读取失败,错误代码:" + (uint)result; return(false); } } catch (Exception ex) { message = "error:\n" + ex.Message; lData = -1; return(false); } finally { //Console.WriteLine(message); } } }
internal int GetValue(string adr, out bool value) { int buf; Err = plc.GetDevice(adr, out buf); value = buf == 1 ? true : false; return(Err); }
/// <summary> /// Xử lý hiển thị thanh Process, đồng thời đợi tín hiệu kết thúc từ PLC /// Cần phải điều chỉnh chuối gửi ra để phù hợp với hoạt động 3 thiết bị đo cùng lúc /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void incProcess(object sender, EventArgs e) { countDisplayProcessBar += 1; countTimeToAlowFinish += 1; if (countDisplayProcessBar > 8) { countDisplayProcessBar = 0; } lblProcess.Text = ""; for (int i = 0; i < countDisplayProcessBar; i++) { lblProcess.Text += "_"; } if (btnTEST_Finish) { btnTEST_Finish = false; MessageBox.Show((valueMax1 - valueMin1).ToString("0.000") + (valueMax2 - valueMin2).ToString("0.000") + (valueMax3 - valueMin3).ToString("0.000")); ComDodao01.Write("OUT0\r\n"); ComDodao02.Write("OUT0\r\n"); ComDodao03.Write("OUT0\r\n"); this.Close(); } // Check Button ReClick => Cần đổi giá trị X12?? if ((plcRef != null) && (countTimeToAlowFinish > 20)) { int buttonRead; var iret = plcRef.GetDevice("X12", out buttonRead); if (buttonRead == 1) { if (stringDoneDodao != null) { stringDoneDodao((valueMax1 - valueMin1).ToString("0.000"), (valueMax2 - valueMin2).ToString("0.000"), (valueMax3 - valueMin3).ToString("0.000")); } this.Close(); } } }
private void runCamera() { while (true) { try { if (conditionRunCam) { if (captureV == null) { captureV = new VideoCapture(0); } captureV.Read(m); Mat tempImage = new Mat(); CvInvoke.Resize(m, tempImage, new Size(imageBox1.Width, imageBox1.Height), 0, 0, Emgu.CV.CvEnum.Inter.Linear); if (!m.IsEmpty) { imageBox1.Image = tempImage; } Thread.Sleep(50); } //if (!conditionRunCam) // if (captureV != null) captureV.Dispose(); plcFX3G.GetDevice("X13", out buttonRead); if (buttonRead == 1) { Invoke(new MethodInvoker(delegate { btnCapture.PerformClick(); })); break; } } catch { return; } } }
/// <summary> /// Đọc giá trị 3 nút nhấn - Chụp ảnh, Đo khe hở, Đo độ đảo /// </summary> /// //public delegate void BringToFrontMain(); //BringToFrontMain _bring; //private void bringToFrontMain() //{ // this.BringToFront(); //} private void ReadNewPLCButtonStatus() { int buttonRead; try { var iret = plcFX3G.GetDevice("X10", out buttonRead); if (buttonRead == 1) { Console.WriteLine("Nhan nut X10!"); if (!currentPLCBit["X10"]) { this.Invoke(new MethodInvoker(delegate { this.StartPosition = FormStartPosition.Manual; this.Top = 650; this.Left = 800; })); currentPLCBit["X10"] = true; wfDodao wftemp1 = new wfDodao(); wftemp1.stringDoneDodao += InputDodaoToExcel; wftemp1.ShowDialog(); formLock = false; } } else { currentPLCBit["X10"] = false; } iret = plcFX3G.GetDevice("X11", out buttonRead); // Kiểm tra nhấn nút đo Khe hở if (buttonRead == 1) { Console.WriteLine("Nhan nut X11!"); if (!currentPLCBit["X11"]) { this.Invoke(new MethodInvoker(delegate { this.StartPosition = FormStartPosition.Manual; this.Top = 650; this.Left = 800; })); currentPLCBit["X11"] = true; wfKheho wftemp = new wfKheho(ref plcFX3G, ref COMSylvacKheho); wftemp.stringDoneKheho += InputKhehoToExcel; wftemp.ShowDialog(); } } else { currentPLCBit["X11"] = false; } // Kiểm tra nhấn nút đo độ đảo plcFX3G.GetDevice("X12", out buttonRead); if (buttonRead == 1) { Console.WriteLine("Nhan nut X12!"); if (!currentPLCBit["X12"]) { this.Invoke(new MethodInvoker(delegate { this.StartPosition = FormStartPosition.Manual; this.Top = 650; this.Left = 800; // this.BringToFront(); })); currentPLCBit["X12"] = true; wfDodaoSylvac wftemp1 = new wfDodaoSylvac(ref plcFX3G, ref COMSylvacDodao01, ref COMSylvacDodao02, ref COMSylvacDodao03); wftemp1.stringDoneDodao += InputDodaoSylvacToExcel; wftemp1.ShowDialog(); wftemp1.stringDoneDodao -= InputDodaoSylvacToExcel; wftemp1.Dispose(); formLock = false; } } else { currentPLCBit["X12"] = false; } // Kiểm tra nhấn nút chụp ảnh plcFX3G.GetDevice("X13", out buttonRead); if (buttonRead == 1) { if (!currentPLCBit["X13"]) { this.Invoke(new MethodInvoker(delegate { this.StartPosition = FormStartPosition.Manual; this.Top = 650; this.Left = 800; })); currentPLCBit["X13"] = true; // Mở form chụp ảnh, gửi kèm địa chỉ lưu ảnh //string tempDic = @txtLoggingFolder.Text + "\\" + DateTime.Now.ToString("ddMMyyyy") + @"Image\" + productName + "_" + (numberRead + 1).ToString(); if (!string.IsNullOrWhiteSpace(_FileName) && _ColName.StartsWith("colImage")) { Capture wftemp2 = new Capture(_pathImage, ref plcFX3G); wftemp2._FileName = _FileName + ".jpg"; wftemp2.saveImageComplete += ProcessImageSavedLink; wftemp2.ShowDialog(); Console.WriteLine("Nhan nut X13!"); } } } else { currentPLCBit["X13"] = false; } } catch (Exception ex) { File.AppendAllText(_PathError + "/Error_" + DateTime.Now.ToString("dd_MM_yyyy") + ".txt", DateTime.Now.ToString("HH:mm:ss") + ":ReadNewPLCButtonStatus(): " + ex.ToString() + Environment.NewLine); } }
private void but_Read_Click(object sender, EventArgs e) { if (plcStat == false) { int read_result; plc.GetDevice(TxtAdd_R.Text, out read_result); TxtVal_R.Text = read_result.ToString(); } }