Esempio n. 1
0
        private void DM8120讀取2D()
        {
            if (InvokeRequired)
            {
                BeginInvoke((Action)DM8120讀取2D);
            }
            else
            {
                if (GlobalData.DM[DmTable.DM_8120CCD讀取2D碼].Equals("1"))
                {
                    string readCode = readerAccessor.ExecCommand("LON", 8000);
                    if (!string.IsNullOrEmpty(readCode))
                    {
                        PLCcommand.PLC_Write(PLCcommand.Cmd_Mode.Mode_Write_Single,
                                             PLCcommand.PLC_IO.DM, DmTable.DM_8220CCD讀2D碼完成, 1, 0, null);
                        lblText.Text = readCode;
                        MessageBox.Show("讀取成功。");
                    }
                    else
                    {
                        PLCcommand.PLC_Write(PLCcommand.Cmd_Mode.Mode_Write_Single,
                                             PLCcommand.PLC_IO.DM, DmTable.DM_8221CCD讀2D檔失敗, 1, 0, null);
                        liveviewForm1.EndReceive();
                        MessageBox.Show("讀取錯誤,請檢查讀取器或材料是否有異常。");
                    }

                    PLCcommand.PLC_Write(PLCcommand.Cmd_Mode.Mode_Write_Single,
                                         PLCcommand.PLC_IO.DM, DmTable.DM_8120CCD讀取2D碼, 0, 0, null);
                    CCD讀取Tag = false;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 條碼讀取器-讀取
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnRead_Click(object sender, EventArgs e)
        {
            try
            {
                // 異動紀錄
                AddRecChangeMethod("手動流程:條碼讀取");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            if (GlobalParameter.UseMode.Equals("0"))
            {
                MessageBox.Show("測試模式,無法讀取。"); return;
            }
            if (GlobalData.DM[DmTable.DM_8111允許手動].Equals("1"))
            {
                PLCcommand.PLC_Write(PLCcommand.Cmd_Mode.Mode_Write_Single,
                                     PLCcommand.PLC_IO.DM, DmTable.DM_8213手動2D通知, 1, 0, null);
                CCD讀取Tag = true;
            }
            else
            {
                MessageBox.Show("PLC點位[DM_8111允許手動]:不允許手動,請檢查PLC參數。");
                return;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 雷射打印,[DM_8111允許手動][DM_8214手動打印通知]
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripbtnPoint_Click(object sender, EventArgs e)
        {
            toolStripbtnSet.Enabled   = true;
            toolStripbtnPoint.Enabled = false;

            try
            {
                // 異動紀錄
                AddRecChangeMethod("手動流程:雷射打印執行");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            if (GlobalParameter.UseMode.Equals("0"))
            {
                MessageBox.Show("測試模式,無法雷射打印。"); return;
            }
            try
            {
                if (GlobalData.PLC線路異常)
                {
                    MessageBox.Show("PLC線路異常。"); return;
                }
                if (GlobalData.DM[DmTable.DM_8111允許手動] != "1")
                {
                    MessageBox.Show("PLC讀取異常[DM_8111允許手動]:不允許手動,請檢查PLC參數。");
                    return;
                }

                if (SHT遮光閥狀態 == "0")
                {
                    string cmd      = LaserCommand.MKM指令接收控制設定("1");
                    string response = LaserExecuteWrite.執行MRK印字觸控制設定(cmd);
                    if (ValidateUtility.DisplayMessage(response))
                    {
                        return;
                    }
                    SHT遮光閥狀態 = "1";
                }

                PLCcommand.PLC_Write(PLCcommand.Cmd_Mode.Mode_Write_Single,
                                     PLCcommand.PLC_IO.DM, DmTable.DM_8214手動打印通知, 1, 0, null);
                formStartModel.允許雷射打印Tag = true;
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exception錯誤");
                MessageBox.Show("Exception_PLC系統異常錯誤:" + ex.Message);
                return;
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 傳送資料 TO PLC
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPLCWrite_Click(object sender, EventArgs e)
        {
            try
            {
                // 使用者異動紀錄
                recChangeService.AddData(new RecChange
                {
                    NowTime  = Convert.ToDateTime(DateTime.Now.ToString("yyyy/MM/dd HH:ss:mm")),
                    Message  = "PLC傳送資料",
                    UserName = GlobalParameter.UserName
                });

                if (string.IsNullOrEmpty(lblPartNo.Text))
                {
                    MessageBox.Show("未選取一筆"); return;
                }
                if (GlobalData.PLC初始連線是否成功 && !GlobalData.PLC線路異常)
                {
                    // DWORD
                    List <string> data = new List <string>();
                    PLCMethod.SetParameterSplitForPoint(partNoJoinTrayAndLaser.PieceSizeX, data);
                    PLCMethod.SetParameterSplitForPoint(partNoJoinTrayAndLaser.PieceSizeY, data);
                    PLCMethod.SetParameterSplitForPoint(partNoJoinTrayAndLaser.PieceSizeT, data);
                    PLCMethod.SetParameterSplitForPoint(partNoJoinTrayAndLaser.PositionX2D, data);
                    PLCMethod.SetParameterSplitForPoint(partNoJoinTrayAndLaser.PositionY2D, data);
                    PLCMethod.SetDefultParameter("0", 20, data);
                    PLCMethod.SetParameterSplit(partNoJoinTrayAndLaser.TrayNo.ToString(), data);
                    PLCMethod.SetParameterSplit(partNoJoinTrayAndLaser.DivideNoX.ToString(), data);
                    PLCMethod.SetParameterSplit(partNoJoinTrayAndLaser.DivideNoY.ToString(), data);
                    PLCMethod.SetParameterSplitForPoint(partNoJoinTrayAndLaser.DividePitchX, data);
                    PLCMethod.SetParameterSplitForPoint(partNoJoinTrayAndLaser.DividePitchY, data);
                    PLCMethod.SetParameterSplitForPoint(partNoJoinTrayAndLaser.PieceCenterX, data);
                    PLCMethod.SetParameterSplitForPoint(partNoJoinTrayAndLaser.PieceCenterY, data);
                    PLCMethod.SetParameterSplitForPoint(partNoJoinTrayAndLaser.TrayThickness, data);
                    PLCMethod.SetParameterSplitForPoint(partNoJoinTrayAndLaser.TrayCenter, data);
                    PLCMethod.SetParameterSplitForPoint(partNoJoinTrayAndLaser.TrayLength, data);
                    PLCMethod.SetDefultParameter("0", 10, data);
                    PLCMethod.SetParameterSplitForPoint(partNoJoinTrayAndLaser.TrayOffsetX, data);
                    PLCMethod.SetParameterSplitForPoint(partNoJoinTrayAndLaser.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斷線異常");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 5
0
 /// <summary>
 /// PLC循環
 /// </summary>
 /// <param name="sender"></param>
 private static void PLC循環(object sender)
 {
     while (true)
     {
         if (!GlobalData.PLC線路異常)
         {
             Thread.Sleep(100);
             PLCcommand.PLC_Read(PLCcommand.Cmd_Mode.Mode_Read_Multiple,
                                 PLCcommand.PLC_IO.DM, GlobalData.PLC_D區起始位址,
                                 (GlobalData.PLC_D區結束位址 - GlobalData.PLC_D區起始位址));
         }
     }
 }
Esempio n. 6
0
 /// <summary>
 /// PLC參數拆解設定,
 /// 傳入條件: 1.參數(例:3)、2.儲存資料物件
 /// </summary>
 /// <param name="parameter">參數</param>
 /// <param name="date">儲存資料物件</param>
 public static void SetParameterSplit(string parameter, List <string> date)
 {
     if (!string.IsNullOrEmpty(parameter))
     {
         string DM_1 = string.Empty, DM_2 = string.Empty, Error = string.Empty;
         PLCcommand.DWORD拆解(parameter, ref DM_1, ref DM_2, ref Error);
         date.Add(DM_1);
         date.Add(DM_2);
     }
     else
     {
         PLCMethod.SetDefultParameter("0", 2, date);
     }
 }
Esempio n. 7
0
        private void Step2寫入PLC資料()
        {
            // DWORD
            List <string> data = new List <string>();

            PLCMethod.SetParameterSplitForPoint(partNoJoinTrayAndLaser.PieceSizeX, data);
            PLCMethod.SetParameterSplitForPoint(partNoJoinTrayAndLaser.PieceSizeY, data);
            PLCMethod.SetParameterSplitForPoint(partNoJoinTrayAndLaser.PieceSizeT, data);
            PLCMethod.SetParameterSplitForPoint(partNoJoinTrayAndLaser.PositionX2D, data);
            PLCMethod.SetParameterSplitForPoint(partNoJoinTrayAndLaser.PositionY2D, data);
            PLCMethod.SetDefultParameter("0", 20, data);
            PLCMethod.SetParameterSplit(partNoJoinTrayAndLaser.TrayNo.ToString(), data);
            PLCMethod.SetParameterSplit(partNoJoinTrayAndLaser.DivideNoX.ToString(), data);
            PLCMethod.SetParameterSplit(partNoJoinTrayAndLaser.DivideNoY.ToString(), data);
            PLCMethod.SetParameterSplitForPoint(partNoJoinTrayAndLaser.DividePitchX, data);
            PLCMethod.SetParameterSplitForPoint(partNoJoinTrayAndLaser.DividePitchY, data);
            PLCMethod.SetParameterSplitForPoint(partNoJoinTrayAndLaser.PieceCenterX, data);
            PLCMethod.SetParameterSplitForPoint(partNoJoinTrayAndLaser.PieceCenterY, data);
            PLCMethod.SetParameterSplitForPoint(partNoJoinTrayAndLaser.TrayThickness, data);
            PLCMethod.SetParameterSplitForPoint(partNoJoinTrayAndLaser.TrayCenter, data);
            PLCMethod.SetParameterSplitForPoint(partNoJoinTrayAndLaser.TrayLength, data);
            PLCMethod.SetDefultParameter("0", 10, data);
            PLCMethod.SetParameterSplitForPoint(partNoJoinTrayAndLaser.TrayOffsetX, data);
            PLCMethod.SetParameterSplitForPoint(partNoJoinTrayAndLaser.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);

            // judge判斷寫入PLC
            List <string> listJudge = partNoJoinTrayAndLaser.JudgeStatus.Split('、').ToList();
            List <int>    listDM    = new List <int> {
                { DmTable.DM_8231PASS }, { DmTable.DM_8232UNTEST }, { DmTable.DM_8233LO },
                { DmTable.DM_8234LEAK }, { DmTable.DM_8235CCD }, { DmTable.DM_8236OPEN },
                { DmTable.DM_8237LOW4W }, { DmTable.DM_8238VISUAL }, { DmTable.DM_8239FAIL10 },
                { DmTable.DM_8240FAIL11 }, { DmTable.DM_8241FAIL12 }, { DmTable.DM_8242FAIL13 },
                { DmTable.DM_8243SKIP }
            };

            if (listJudge.Count == listDM.Count)
            {
                for (int i = 0; i < listJudge.Count; i++)
                {
                    int value = listJudge[i] == "ON" ? 1 : 0;
                    PLCcommand.PLC_Write(PLCcommand.Cmd_Mode.Mode_Write_Single,
                                         PLCcommand.PLC_IO.DM, listDM[i], value, 0, null);
                }
            }
        }
Esempio n. 8
0
 /// <summary>
 /// PLC參數拆解設定(小數點處理),
 /// 傳入條件: 1.參數(例:123.000)、2.儲存資料物件
 /// </summary>
 /// <param name="parameter">參數</param>
 /// <param name="date">儲存資料物件</param>
 public static void SetParameterSplitForPoint(string parameter, List <string> date)
 {
     if (!string.IsNullOrEmpty(parameter))
     {
         string[] 參數分割 = parameter.Split('.');
         string   小數點左邊 = 參數分割[0], 小數點右邊 = TypeMethod.SetParameterPad(參數分割[1], false, 3);
         string   DM_1 = string.Empty, DM_2 = string.Empty, Error = string.Empty;
         PLCcommand.DWORD拆解(小數點左邊 + 小數點右邊, ref DM_1, ref DM_2, ref Error);
         date.Add(DM_1);
         date.Add(DM_2);
     }
     else
     {
         PLCMethod.SetDefultParameter("0", 2, date);
     }
 }
Esempio n. 9
0
        private void DM8123雷射打印執行緒(object sender)
        {
            string cmd = string.Empty, response = string.Empty;

            while (true)
            {
                if (!GlobalData.PLC線路異常)
                {
                    if (formStartModel.允許雷射打印Tag)
                    {
                        if (GlobalData.DM[DmTable.DM_8123雷射打印開始].Equals("1"))
                        {
                            try
                            {
                                cmd      = LaserCommand.MRK印字觸控制設定("1");
                                response = LaserExecuteWrite.執行MRK印字觸控制設定(cmd);
                                Thread.Sleep(500);
                                if (ValidateUtility.DisplayMessage(response))
                                {
                                    PLCcommand.PLC_Write(PLCcommand.Cmd_Mode.Mode_Write_Single,
                                                         PLCcommand.PLC_IO.DM, DmTable.DM_8230雷射打印異常, 1, 0, null);
                                    MessageBox.Show(response);
                                }
                                else
                                {
                                    PLCcommand.PLC_Write(PLCcommand.Cmd_Mode.Mode_Write_Single,
                                                         PLCcommand.PLC_IO.DM, DmTable.DM_8229雷射打印完畢, 1, 0, null);
                                    MessageBox.Show("打印成功");
                                }
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex, "Exception錯誤");
                                MessageBox.Show(ex.Message);
                            }

                            PLCcommand.PLC_Write(PLCcommand.Cmd_Mode.Mode_Write_Single,
                                                 PLCcommand.PLC_IO.DM, DmTable.DM_8123雷射打印開始, 0, 0, null);
                            formStartModel.允許雷射打印Tag = false;
                        }
                    }
                }
            }
        }
Esempio n. 10
0
 /// <summary>
 /// PLC單次寫入,
 /// 傳入條件: 1.DM點位、2.數值:0或1
 /// </summary>
 /// <param name="dm">DM</param>
 /// <param name="number">數值</param>
 public static void WriteSingle(int dm, int number)
 {
     PLCcommand.PLC_Write(PLCcommand.Cmd_Mode.Mode_Write_Single, PLCcommand.PLC_IO.DM, dm, number, 0, null);
 }
Esempio n. 11
0
        /// <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 雷射寫入
        }