/// <summary> /// 設定存檔 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void toolStripbtnSet_Click(object sender, EventArgs e) { string cmd = string.Empty, response = string.Empty, record = string.Empty; toolStripbtnSet.Enabled = false; toolStripbtnPoint.Enabled = true; try { // 異動紀錄 AddRecChangeMethod("手動流程:雷射設定存檔"); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } if (GlobalParameter.UseMode.Equals("0")) { MessageBox.Show("測試模式,無法設定存檔。"); return; } // 驗證資料 List <string> parameter = new List <string> { { cbBoxPartNo.Text }, { lblFNO.Text }, { lblPower.Text }, { lblSpeed.Text } }; response = ValidateUtility.CheckParameter(parameter); if (ValidateUtility.DisplayMessage(response)) { return; } // 板子計算方式 PieceResultModel pieceResultModel = new PieceCalculationMethod() .PieceCalculation(new PieceRequestModel { 板子X尺寸 = Convert.ToDouble(partNoJoinLaser[0].PieceSizeX), 板子Y尺寸 = Convert.ToDouble(partNoJoinLaser[0].PieceSizeY), X偏移位置 = Convert.ToDouble(lblXoffset.Text), Y偏移位置 = Convert.ToDouble(lblYoffset.Text), 台與雷射中心點差距 = GlobalParameter.VehicleAndPieceCenter }); #region PLC寫入 try { if (!GlobalData.PLC線路異常) { List <string> data = new List <string>(); PLCMethod.SetParameterSplitForPoint(partNoJoinLaser[0].PieceSizeX, data); PLCMethod.SetParameterSplitForPoint(partNoJoinLaser[0].PieceSizeY, data); PLCMethod.SetParameterSplitForPoint(partNoJoinLaser[0].PieceSizeT, data); PLCMethod.SetParameterSplitForPoint(partNoJoinLaser[0].PositionX2D, data); PLCMethod.SetParameterSplitForPoint(partNoJoinLaser[0].PositionY2D, data); PLCMethod.SetDefultParameter("0", 20, data); PLCMethod.SetParameterSplit(dataTray.TrayNo.ToString(), data); PLCMethod.SetParameterSplit(dataTray.DivideNoX.ToString(), data); PLCMethod.SetParameterSplit(dataTray.DivideNoY.ToString(), data); PLCMethod.SetParameterSplitForPoint(dataTray.DividePitchX, data); PLCMethod.SetParameterSplitForPoint(dataTray.DividePitchY, data); PLCMethod.SetParameterSplitForPoint(dataTray.PieceCenterX, data); PLCMethod.SetParameterSplitForPoint(dataTray.PieceCenterY, data); PLCMethod.SetParameterSplitForPoint(dataTray.TrayThickness, data); PLCMethod.SetParameterSplitForPoint(dataTray.TrayCenter, data); PLCMethod.SetParameterSplitForPoint(dataTray.TrayLength, data); PLCMethod.SetDefultParameter("0", 10, data); PLCMethod.SetParameterSplitForPoint(dataTray.TrayOffsetX, data); PLCMethod.SetParameterSplitForPoint(dataTray.TrayOffsetY, data); PLCMethod.SetDefultParameter("0", 6, data); PLCcommand.PLC_Write(PLCcommand.Cmd_Mode.Mode_Write_Multiple, PLCcommand.PLC_IO.DM, DmTable.DM_8300DWORD_板寬X, 0, data.Count, data); } else { MessageBox.Show("PLC線路異常。"); return; } } catch (Exception ex) { logger.Error(ex, "Exception錯誤"); MessageBox.Show("Exception_PLC系統異常錯誤:" + ex.Message); return; } #endregion PLC寫入 #region 雷射寫入 try { if (SHT遮光閥狀態.Equals("1")) { cmd = LaserCommand.MKM指令接收控制設定("0"); response = LaserExecuteWrite.執行MRK印字觸控制設定(cmd); if (ValidateUtility.DisplayMessage(response)) { return; } SHT遮光閥狀態 = "0"; record += "1.SHT,"; } // 設定 FNO cmd = LaserCommand.FNO文件變更控制設定(lblFNO.Text); response = LaserExecuteWrite.執行FNO文件變更控制設定(cmd); if (ValidateUtility.DisplayMessage(response)) { return; } record += "2.FNO,"; // 雷射功率 cmd = LaserCommand.LPW激光功率控制設定(string.Format("{0:000.0}", Convert.ToInt32(lblPower.Text))); response = LaserExecuteWrite.執行LPW激光功率控制設定(cmd); if (ValidateUtility.DisplayMessage(response)) { return; } record += "3.LPW,"; // 掃描速度 cmd = LaserCommand.SSP掃描速度控制設定(string.Format("{0:00000}", Convert.ToInt32(lblSpeed.Text))); response = LaserExecuteWrite.執行SSP掃描速度控制設定(cmd); if (ValidateUtility.DisplayMessage(response)) { return; } record += "4.SSP,"; // 設定座標位置 List <double> list = new List <double> { { pieceResultModel.X位置 }, { pieceResultModel.Y位置 } }; List <string> laserList = TypeMethod.SetFormatValue(list, "{0:000.000}"); ModelSPC modelSPC = new ModelSPC { SonCmd = "S", Xposition = laserList[0], Yposition = laserList[1] }; cmd = LaserCommand.SPC文字條件控制設定(modelSPC); response = LaserExecuteWrite.執行SPC文字條件控制設定(cmd); if (ValidateUtility.DisplayMessage(response)) { return; } record += "5.SPC,"; // 雷射參數儲存 LaserExecuteWrite.執行FOR文件覆盖保存控制設定(LaserCommand.FOR文件覆盖保存控制設定); record += "6.FOR,"; // DB資料寫入 IDataLaserService dataLaserService = new DataLaserService(); ResponseModel ResponseModel = dataLaserService.UpdateData(new DataLaser { PartNo = cbBoxPartNo.Text, FnoNo = lblFNO.Text, Xoffset = lblXoffset.Text, Yoffset = lblYoffset.Text, Power = lblPower.Text, Speed = lblSpeed.Text }); if (ResponseModel.Status.Equals(StatusEnum.Error)) { logger.Error(ResponseModel.ResponseMsg); MessageBox.Show(ResponseModel.ResponseMsg); return; } record += "7.DB"; if (!ValidateUtility.DisplayMessage(response)) { MessageBox.Show("設定完成,執行紀錄:" + record); } } catch (Exception ex) { logger.Error(ex, "Exception_Error:" + record); MessageBox.Show("Exception_雷射系統異常錯誤:" + ex.Message + ",執行紀錄:" + record); } #endregion 雷射寫入 }
private void Step3寫入Laser資料(PieceResultModel pieceResultModel) { string cmd = string.Empty, response = string.Empty, record = string.Empty; if (formStartModel.允許雷射打印Tag) { // 設定 MKM if (formStartModel.SHT遮光閥狀態.Equals("1")) { cmd = LaserCommand.MKM指令接收控制設定("0"); response = LaserExecuteWrite.執行MRK印字觸控制設定(cmd); if (ValidateUtility.DisplayMessage(response)) { return; } formStartModel.SHT遮光閥狀態 = "0"; record += "1.SHT,"; } // 設定 FNO cmd = LaserCommand.FNO文件變更控制設定(partNoJoinTrayAndLaser.FnoNo); response = LaserExecuteWrite.執行FNO文件變更控制設定(cmd); if (ValidateUtility.DisplayMessage(response)) { return; } record += "2.FNO,"; // 雷射功率 cmd = LaserCommand.LPW激光功率控制設定(string.Format("{0:000.0}", Convert.ToInt32(partNoJoinTrayAndLaser.Power))); response = LaserExecuteWrite.執行LPW激光功率控制設定(cmd); if (ValidateUtility.DisplayMessage(response)) { return; } record += "3.LPW,"; // 掃描速度 cmd = LaserCommand.SSP掃描速度控制設定(string.Format("{0:00000}", Convert.ToInt32(partNoJoinTrayAndLaser.Speed))); response = LaserExecuteWrite.執行SSP掃描速度控制設定(cmd); if (ValidateUtility.DisplayMessage(response)) { return; } record += "4.SSP,"; // 設定座標位置 List <double> list = new List <double> { { pieceResultModel.X位置 }, { pieceResultModel.Y位置 } }; List <string> laserList = TypeMethod.SetFormatValue(list, "{0:000.000}"); ModelSPC modelSPC = new ModelSPC { SonCmd = "S", Xposition = laserList[0], Yposition = laserList[1] }; cmd = LaserCommand.SPC文字條件控制設定(modelSPC); response = LaserExecuteWrite.執行SPC文字條件控制設定(cmd); if (ValidateUtility.DisplayMessage(response)) { return; } record += "5.SPC,"; // 雷射參數儲存 LaserExecuteWrite.執行FOR文件覆盖保存控制設定(LaserCommand.FOR文件覆盖保存控制設定); record += "6.FOR,"; } }
/// <summary> /// 程序確定 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void toolStripbtnSave_Click(object sender, EventArgs e) { string cmd = string.Empty, response = string.Empty, record = string.Empty; try { // 使用者異動紀錄 recChangeService.AddData(new RecChange { NowTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy/MM/dd HH:ss:mm")), Message = "雷射設定", UserName = GlobalParameter.UserName }); // 檢查欄位是否有空白 List <string> parameter = new List <string> { { txtFNO.Text }, { lblJisCode.Text }, { txtHeight.Text }, { txtWidth.Text } }; response = ValidateUtility.CheckParameter(parameter); if (ValidateUtility.DisplayMessage(response)) { return; } if (GlobalParameter.UseMode.Equals("1")) { // 寫入db ILaserFnoService laserFnoService = new LaserFnoService(); LaserFNO laserFNO = new LaserFNO { LaserFnoNo = txtFNO.Text }; ResponseModel ResponseModel = laserFnoService.AddData(laserFNO); if (ResponseModel.Status != StatusEnum.Ok) { MessageBox.Show(ResponseModel.ResponseMsg); return; } // 寫入雷射 if (SHT遮光閥狀態 == "1") { cmd = LaserCommand.MKM指令接收控制設定("0"); response = LaserExecuteWrite.執行MRK印字觸控制設定(cmd); if (ValidateUtility.DisplayMessage(response)) { return; } record += "1.SHT,"; SHT遮光閥狀態 = "0"; } // 設定 FNO cmd = LaserCommand.FNO文件變更控制設定(txtFNO.Text); response = LaserExecuteWrite.執行FNO文件變更控制設定(cmd); if (ValidateUtility.DisplayMessage(response)) { return; } record += "2.FNO,"; // 雷射功率 cmd = LaserCommand.LPW激光功率控制設定(string.Format("{0:000.0}", 40)); response = LaserExecuteWrite.執行LPW激光功率控制設定(cmd); if (ValidateUtility.DisplayMessage(response)) { return; } record += "3.LPW,"; // 掃描速度 cmd = LaserCommand.SSP掃描速度控制設定(string.Format("{0:00000}", 500)); response = LaserExecuteWrite.執行SSP掃描速度控制設定(cmd); if (ValidateUtility.DisplayMessage(response)) { return; } record += "4.SSP,"; // 設定條件 ALC cmd = LaserCommand.ALC整體條件的控制設定(new ModelALC { SonCmd = "S", Xoffset = "+000.000", Yoffset = "+000.000", RotationOffset = "-090.00" }); response = LaserExecuteWrite.執行ALC整體條件的控制設定(cmd); if (ValidateUtility.DisplayMessage(response)) { return; } record += "5.ALC,"; // 設定文字型狀 STR cmd = LaserCommand.STR印字文字列設定(lblJisCode.Text); response = LaserExecuteWrite.執行STR印字文字列設定(cmd); if (ValidateUtility.DisplayMessage(response)) { return; } record += "6.STR,"; /* 文字條件控制設定STC * 範例:"STCS010010101006.000006.000+000.000+000.000000.000000.000+100.0011.000100100"; */ ModelSTC modelSTC = new ModelSTC { SonCmd = "S", Height = string.Format("{0:000.000}", Convert.ToDouble(txtHeight.Text)), Width = string.Format("{0:000.000}", Convert.ToDouble(txtWidth.Text)), Xposition = "+000.000", Yposition = "+000.000", Bold = "0.000" }; cmd = LaserCommand.STC文字條件控制設定(modelSTC); response = LaserExecuteWrite.執行STC文字條件控制設定(cmd); if (ValidateUtility.DisplayMessage(response)) { return; } record += "7.STC,"; // 雷射參數儲存 LaserExecuteWrite.執行FOR文件覆盖保存控制設定(LaserCommand.FOR文件覆盖保存控制設定); record += "8.FOR"; if (!ValidateUtility.DisplayMessage(response)) { MessageBox.Show("設定完成,執行紀錄:" + record); } } } catch (Exception ex) { logger.Error(ex, "Error"); MessageBox.Show(ex.Message); } }