private void LdsWorkFunctionSet1() { int nIndex = 1; int nCmd = 0; const string cmdReg = "R310"; int C1 = 0; int C2 = 0; const string bool_Calib2m = "R311"; const string bool_Calib4m = "R366"; try { while (!cts.IsCancellationRequested) { bool bRet = false; nCmd = PLC.ReadInt(cmdReg); switch (nCmd) { case 1: //读取2米强度值 bRet = GetCenterFocus(nIndex, out C1); PLC.WriteInt(bool_Calib2m, bRet ? 2 : 1); PLC.WriteInt(cmdReg, nCmd + 1); ShowInfo("读取LDS1的2米处激光中心值"); break; case 3: //读取4米强度值 bRet = GetCenterFocus(nIndex, out C1); PLC.WriteInt(bool_Calib4m, bRet ? 2 : 1); PLC.WriteInt(cmdReg, nCmd + 1); ShowInfo("读取LDS1的4米处激光中心值"); break; case 5: //计算结果给LDS bRet = SetLDSCalidData(nIndex, C1, C2); PLC.WriteInt(cmdReg, nCmd + 1); ShowInfo("计算结果写入LDS1"); //结果写在哪 break; case 100: ReadResutFromPLC(nIndex); PLC.WriteInt(cmdReg, nCmd + 1); break; default: break; } Thread.Sleep(100); } ShowInfo("LDS1的服务器被用户退出"); } catch (Exception ex) { ShowInfo($"LDS1的服务器异常终止:{ex.Message}"); } }
private void LdsWorkFunctionSet1() { int nIndex = 1; int nCmd = 0; const string cmdReg = "R211"; const string Angle_Join_Reg = "R213"; const string bool_Join_Reg = "R212"; const string Intensity6m_Reg = "R272"; const string bool_6m_Reg = "R268"; try { while (!cts.IsCancellationRequested) { bool bRet = false; nCmd = PLC.ReadInt(cmdReg); switch (nCmd) { case 1: //计算对接角度 bRet = GetTune2JoinAngle(nIndex, out double Angle); PLC.WriteDint(Angle_Join_Reg, /*Convert.ToInt32(Angle * 1000)*/ 765); PLC.WriteInt(bool_Join_Reg, bRet ? 2 : 1); PLC.WriteInt(cmdReg, nCmd + 1); ShowInfo($"计算LDS1的对接角度结果{bRet},{Angle}"); break; case 5: //获取强度值 bRet = GetLaserIntensityValue(nIndex, out int intensityValue); PLC.WriteDint(Intensity6m_Reg, /*intensityValue*/ 99); PLC.WriteInt(bool_6m_Reg, bRet ? 2 : 1); PLC.WriteInt(cmdReg, nCmd + 1); ShowInfo($"读取LDS1的6.5米处水平强度值{bRet},{intensityValue}"); break; case 100: ReadResutFromPLC(nIndex); PLC.WriteInt(cmdReg, nCmd + 1); break; default: break; } Thread.Sleep(100); } ShowInfo($"LDS1的服务器正常退出"); } catch (Exception ex) { ShowInfo($"LDS1的服务器异常终止:{ex.Message}"); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { if (taskMonitor == null || taskMonitor.IsCompleted || taskMonitor.IsCanceled) //实时显示部分 { DataTable dtError = ConfigMgr.PLCErrorDataTable; QSerisePlc PLC = InstrumentMgr.Instance.FindInstrumentByName("PLC") as QSerisePlc; cts = new CancellationTokenSource(); taskMonitor = new Task(() => { while (!cts.IsCancellationRequested) { #if TEST int[] errorCodes = new int[] { 0x00FF, 0xFF00, 0x000F }; #else if (PLC != null) { int[] errorCodes = new int[] { PLC.ReadInt("R5011"), PLC.ReadInt("R5012"), PLC.ReadInt("R5013"), PLC.ReadInt("R5014"), PLC.ReadInt("R5015"), PLC.ReadInt("R5016"), PLC.ReadInt("R5017"), PLC.ReadInt("R5018") }; ShowPLCError(errorCodes, dtError); Thread.Sleep(300); } #endif } }, cts.Token); } taskMonitor.Start(); }
private void LdsWorkFunctionSet1() { int nIndex = 1; int nCmd = 0; const string cmdReg = "R107"; const string Angle_Join_Reg = "R109"; const string bool_Join_Reg = "R108"; const string Angle_Blob_Reg = "R164"; const string Bool_Blob_Reg = "R163"; const string Intensity2m_Reg = "R171"; const string bool_2m_Reg = "R173"; const string Intensity6m_Reg = "R171"; const string bool_6m_Reg = "R173"; try { while (!cts.IsCancellationRequested) { bool bRet = false; nCmd = PLC.ReadInt(cmdReg); switch (nCmd) { case 1: //计算对接角度 bRet = GetTune1JoinAngle(nIndex, out double Angle); PLC.WriteDint(Angle_Join_Reg, /*Convert.ToInt32(Angle * 1000)*/ 123); PLC.WriteInt(bool_Join_Reg, bRet ? 2 : 1); PLC.WriteInt(cmdReg, nCmd + 1); ShowInfo($"LDS1拍照并计算对接角度结果{bRet},{Angle}"); break; case 3: //计算光斑角度 bRet = GetBlobAngle(nIndex, out double BlobAngle); PLC.WriteDint(Angle_Blob_Reg, /*Convert.ToInt32(BlobAngle * 1000)*/ 11111111); PLC.WriteInt(Bool_Blob_Reg, bRet ? 2 : 1); PLC.WriteInt(cmdReg, nCmd + 1); ShowInfo($"LDS1拍照并计算光板角度结果{bRet},{BlobAngle}"); break; case 5: //获取2米水平强度值 bRet = GetLaserIntensity(nIndex, EnumTarget.T2, out int InstensityValue2m); PLC.WriteDint(Intensity2m_Reg, /*InstensityValue2m*/ 777777); PLC.WriteInt(bool_2m_Reg, bRet ? 2 : 1); PLC.WriteInt(cmdReg, nCmd + 1); ShowInfo($"LDS1获取2米处的水平强度值结果{bRet},{InstensityValue2m}"); break; case 7: //获取6米水平强度值 bRet = GetLaserIntensity(nIndex, EnumTarget.T6, out int InstensityValue6m); PLC.WriteDint(Intensity6m_Reg, /*InstensityValue6m*/ 76); PLC.WriteInt(bool_6m_Reg, bRet ? 2 : 1); PLC.WriteInt(cmdReg, nCmd + 1); ShowInfo($"LDS1获取6.5米处的水平强度值结果{bRet},{InstensityValue6m}"); break; case 100: ReadResutFromPLC(nIndex); PLC.WriteInt(cmdReg, nCmd + 1); break; default: break; } Thread.Sleep(100); } ShowInfo($"LDS1的服务器正常退出"); } catch (Exception ex) { ShowInfo($"LDS1的服务器异常终止:{ex.Message}"); } }