Exemplo n.º 1
0
        //一键开机 程序
        private bool One_Key_OFF()
        {
            //状态变量
            decimal Seed_Current = 0; //Seed电流
            decimal Amp1_Current = 0; //Amp1电流
            decimal Amp2_Current = 0; //Amp2电流
            byte    Status       = 0x00;

            Power_On.Enabled          = false; //禁用一键开机按钮
            Power_OFF.Enabled         = false; //禁用一键关机按钮
            Refresh_Status.Enabled    = false; //禁用状态更新按钮
            Reset_Laser.Enabled       = false; //禁用复位按钮
            Watt_Confirm.Enabled      = false; //禁用功率写入按钮
            Frequence_Confirm.Enabled = false; //禁用频率写入按钮
            Re_connect.Enabled        = false; //禁用串口开关按钮

            /**************AMP2 Ldd***************/
            //读取AMP2电流
            Initial.Laser_Operation_00.Read("02", "12");
            if (!(Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte == null) && (Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte.Length == 2))
            {
                Amp2_Current = ((decimal)BitConverter.ToUInt16(Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte, 0) / 100m);
            }
            Thread.Sleep(300);//等待300ms
            //关闭AMP2 Ldd
            if (Amp2_Current > 0.2m)
            {
                Initial.Laser_Operation_00.Write("02", "10", "00");
            }
            Task.Factory.StartNew(() =>
            {
                do
                {
                    //读取AMP2电流
                    Initial.Laser_Operation_00.Read("02", "12");
                    if (!(Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte == null) && (Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte.Length == 2))
                    {
                        Amp2_Current = ((decimal)BitConverter.ToUInt16(Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte, 0) / 100m);
                    }
                    Thread.Sleep(300); //等待300ms
                } while (Amp2_Current > 0.2m);
            }).Wait(120 * 1000);       //2 * 1000,ms,该时间范围内:代码段完成 或 超出该时间范围 返回并继续向下执行
            if (Amp2_Current > 0.2m)
            {
                return(false);
            }
            //刷新状态
            Refresh_All_Status();

            /**************AMP1 Ldd***************/
            //读取AMP1电流
            Initial.Laser_Operation_00.Read("01", "12");
            if (!(Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte == null) && (Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte.Length == 2))
            {
                Amp1_Current = ((decimal)BitConverter.ToUInt16(Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte, 0) / 100m);
            }
            Thread.Sleep(300);//等待300ms
            //关闭AMP1 Ldd
            if (Amp1_Current > 0.2m)
            {
                Initial.Laser_Operation_00.Write("01", "10", "00");
            }
            Task.Factory.StartNew(() =>
            {
                do
                {
                    //读取AMP1电流
                    Initial.Laser_Operation_00.Read("01", "12");
                    if (!(Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte == null) && (Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte.Length == 2))
                    {
                        Amp1_Current = ((decimal)BitConverter.ToUInt16(Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte, 0) / 100m);
                    }
                    Thread.Sleep(300); //等待300ms
                } while (Amp1_Current > 0.2m);
            }).Wait(120 * 1000);       //2 * 1000,ms,该时间范围内:代码段完成 或 超出该时间范围 返回并继续向下执行
            if (Amp1_Current > 0.2m)
            {
                return(false);
            }
            //刷新状态
            Refresh_All_Status();

            /**************AOM Pulse Status***************/
            //读取AOM Pulse
            Initial.Laser_Operation_00.Read("00", "66");
            if (!(Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte == null) && (Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte.Length == 1))
            {
                Status = Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte[Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte.Length - 1];
            }
            Thread.Sleep(300);//等待300ms
            //关闭AOM Pulse
            if (Bit_Value.GetBitValue(Status, 0))
            {
                Initial.Laser_Operation_00.Write("00", "66", "00");
            }
            Task.Factory.StartNew(() =>
            {
                do
                {
                    //读取AOM Pulse
                    Initial.Laser_Operation_00.Read("00", "66");
                    if (!(Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte == null) && (Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte.Length == 1))
                    {
                        Status = Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte[Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte.Length - 1];
                    }
                    Thread.Sleep(300); //等待300ms
                } while (Bit_Value.GetBitValue(Status, 0));
            }).Wait(5 * 1000);         //2 * 1000,ms,该时间范围内:代码段完成 或 超出该时间范围 返回并继续向下执行
            if (Bit_Value.GetBitValue(Status, 0))
            {
                return(false);
            }
            //刷新状态
            Refresh_All_Status();

            /**************PP Pulse Status***************/
            //读取PP Pulse
            Initial.Laser_Operation_00.Read("00", "65");
            if (!(Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte == null) && (Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte.Length == 1))
            {
                Status = Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte[Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte.Length - 1];
            }
            Thread.Sleep(300);//等待300ms
            //关闭PP Pulse
            if (Bit_Value.GetBitValue(Status, 0))
            {
                Initial.Laser_Operation_00.Write("00", "65", "00");
            }
            Task.Factory.StartNew(() =>
            {
                do
                {
                    //读取PP Pulse
                    Initial.Laser_Operation_00.Read("00", "65");
                    if (!(Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte == null) && (Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte.Length == 1))
                    {
                        Status = Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte[Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte.Length - 1];
                    }
                    Thread.Sleep(300); //等待300ms
                } while (Bit_Value.GetBitValue(Status, 0));
            }).Wait(5 * 1000);         //2 * 1000,ms,该时间范围内:代码段完成 或 超出该时间范围 返回并继续向下执行
            if (Bit_Value.GetBitValue(Status, 0))
            {
                return(false);
            }
            //刷新状态
            Refresh_All_Status();

            /**************Seed Shutter Status***************/
            //读取Seed Shutter
            Initial.Laser_Operation_00.Read("00", "04");
            if (!(Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte == null) && (Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte.Length == 1))
            {
                Status = Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte[Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte.Length - 1];
            }
            Thread.Sleep(300);//等待300ms
            //关闭Seed Shutter
            if (Bit_Value.GetBitValue(Status, 0))
            {
                Initial.Laser_Operation_00.Write("00", "04", "00");
            }
            Task.Factory.StartNew(() =>
            {
                do
                {
                    //读取Seed Shutter
                    Initial.Laser_Operation_00.Read("00", "04");
                    if (!(Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte == null) && (Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte.Length == 1))
                    {
                        Status = Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte[Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte.Length - 1];
                    }
                    Thread.Sleep(300); //等待300ms
                } while (Bit_Value.GetBitValue(Status, 0));
            }).Wait(5 * 1000);         //2 * 1000,ms,该时间范围内:代码段完成 或 超出该时间范围 返回并继续向下执行
            if (Bit_Value.GetBitValue(Status, 0))
            {
                return(false);
            }
            //刷新状态
            Refresh_All_Status();

            /**************Seed Ldd***************/
            //读取Seed电流
            Initial.Laser_Operation_00.Read("00", "12");
            if (!(Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte == null) && (Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte.Length == 2))
            {
                Seed_Current = ((decimal)BitConverter.ToUInt16(Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte, 0) / 100m);
            }
            Thread.Sleep(300);//等待300ms
            //关闭Seed Ldd
            if (Seed_Current > 0.2m)
            {
                Initial.Laser_Operation_00.Write("00", "10", "00");
            }
            //状态判断
            Task.Factory.StartNew(() =>
            {
                do
                {
                    //读取Seed电流
                    Initial.Laser_Operation_00.Read("00", "12");
                    if (!(Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte == null) && (Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte.Length == 2))
                    {
                        Seed_Current = ((decimal)BitConverter.ToUInt16(Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte, 0) / 100m);
                    }
                    Thread.Sleep(300); //等待300ms
                } while (Seed_Current > 0.2m);
            }).Wait(120 * 1000);       //2 * 1000,ms,该时间范围内:代码段完成 或 超出该时间范围 返回并继续向下执行
            if (Seed_Current > 0.2m)
            {
                return(false);
            }
            //刷新状态
            Refresh_All_Status();
            //返回True
            return(true);
        }
Exemplo n.º 2
0
        //状态刷新
        private void Refresh_All_Status()
        {
            //读取Seed电流
            Initial.Laser_Operation_00.Read("00", "12");
            if (!(Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte == null) && (Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte.Length == 2))
            {
                Seed1_Current.Text = ((decimal)BitConverter.ToUInt16(Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte, 0) / 100m).ToString();
            }
            //读取Amp1电流
            Initial.Laser_Operation_00.Read("01", "12");
            if (!(Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte == null) && (Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte.Length == 2))
            {
                Amp1_Current.Text = ((decimal)BitConverter.ToUInt16(Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte, 0) / 100m).ToString();
            }
            //读取Amp2电流
            Initial.Laser_Operation_00.Read("02", "12");
            if (!(Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte == null) && (Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte.Length == 2))
            {
                Amp2_Current.Text = ((decimal)BitConverter.ToUInt16(Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte, 0) / 100m).ToString();
            }
            //读取PEC功率值
            Initial.Laser_Operation_00.Read("00", "55");
            //if (!(Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte == null) && (Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte.Length == 2)) Laser_Watt_Set_Value.Text = Laser_Watt_Cal.Percent_To_Watt(((decimal)BitConverter.ToUInt16(Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte, 0) / 10m)).ToString();
            if (!(Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte == null) && (Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte.Length == 2))
            {
                Laser_Watt_Set_Value.Text = ((decimal)BitConverter.ToUInt16(Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte, 0) / 10m).ToString();
            }
            //读取PRF频率值
            Initial.Laser_Operation_00.Read("00", "21");
            if (!(Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte == null) && (Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte.Length == 3))
            {
                Laser_Frequence_Set_Value.Text = ((decimal)BitConverter.ToUInt32(new byte[] { Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte[0], Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte[1], Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte[2], 0x00 }, 0) / 1000m).ToString();
            }
            //读取状态
            Initial.Laser_Operation_00.Read("00", "0F");
            byte Status = 0x00;

            if (!(Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte == null) && (Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte.Length == 5))
            {
                Status = Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte[Initial.Laser_Operation_00.Resolve_Rec.Rec_Byte.Length - 1];
            }

            //PowerOn
            if (Bit_Value.GetBitValue(Status, 0))
            {
                ChangeKeyColor("PowerOn", Color.Green);
            }
            else
            {
                ChangeKeyColor("PowerOn", Color.Red);
            }
            //Shuter Enabled
            if (Bit_Value.GetBitValue(Status, 1))
            {
                ChangeKeyColor("Shutter Enabled", Color.Green);
            }
            else
            {
                ChangeKeyColor("Shutter Enabled", Color.Red);
            }
            //Key Switch
            if (Bit_Value.GetBitValue(Status, 2))
            {
                ChangeKeyColor("Key Switch On", Color.Green);
            }
            else
            {
                ChangeKeyColor("Key Switch On", Color.Red);
            }
            //LDD On
            if (Bit_Value.GetBitValue(Status, 3))
            {
                ChangeKeyColor("LDD On", Color.Green);
            }
            else
            {
                ChangeKeyColor("LDD On", Color.Red);
            }
            //QSW On
            if (Bit_Value.GetBitValue(Status, 4))
            {
                ChangeKeyColor("QSW On", Color.Green);
            }
            else
            {
                ChangeKeyColor("QSW On", Color.Red);
            }
            //Shutter Interlock
            if (Bit_Value.GetBitValue(Status, 5))
            {
                ChangeKeyColor("Shutter Interlock", Color.Green);
            }
            else
            {
                ChangeKeyColor("Shutter Interlock", Color.Red);
            }
            //LDD Interlock
            if (Bit_Value.GetBitValue(Status, 6))
            {
                ChangeKeyColor("LDD Interlock", Color.Green);
            }
            else
            {
                ChangeKeyColor("LDD Interlock", Color.Red);
            }
        }