//使配方读取按钮接通1S
        private void TimerCloseRead_Tick(object sender, EventArgs e)
        {
            //配方读取
            int rsno = CS7TCP.WriteBool(Z通讯设置.plcHandle, 0x84, device.address, 63, 1, 0);

            if (rsno == 0)
            {
                //配方读取后要刷新数据到界面
                refreshPeifang();
                btn_Recipe_Read.BackColor = Color.Red;
            }
            //配方保存
            int rsno1 = CS7TCP.WriteBool(Z通讯设置.plcHandle, 0x84, device.address, 63, 0, 0);

            if (rsno1 == 0)
            {
                btn_Recipe_Save.BackColor = Color.Red;
            }
            //配方确认
            int rsno2 = CS7TCP.WriteBool(Z通讯设置.plcHandle, 0x84, device.address, 63, 2, 0);

            if (rsno2 == 0)
            {
                btn_Recipe_OK.BackColor = Color.Red;
            }
            TimerCloseRead.Enabled = false;
        }
        //对3个按钮进行判断,判断哪一个按钮被按下
        public void btn_MouseDown(object sender)
        {
            A0开机画面 parent = (A0开机画面)Parent.FindForm();

            System.Windows.Forms.Button button = (System.Windows.Forms.Button)sender;
            int rsno = 0;

            switch (button.Name)
            {
            case "btn_Recipe_Save":
                rsno = CS7TCP.WriteBool(Z通讯设置.plcHandle, 0x84, device.address, 63, 0, 1);
                if (rsno == 0)
                {
                    btn_Recipe_Save.BackColor = Color.LightGreen;
                    parent.showLog(device.typeName + device.index + "配方保存操作执行成功");
                    //插入数据到数据库数据表进行记录
                    saveToDatabaseTable();
                }
                else
                {
                    parent.showLog(device.typeName + device.index + "配方保存操作执行失败");
                    MessageBox.Show("配方保存操作执行失败");
                }
                break;

            case "btn_Recipe_Read":
                rsno = CS7TCP.WriteBool(Z通讯设置.plcHandle, 0x84, device.address, 63, 1, 1);
                if (rsno == 0)
                {
                    btn_Recipe_Read.BackColor = Color.LightGreen;
                    parent.showLog(device.typeName + device.index + "配方读取操作执行成功");
                }
                else
                {
                    parent.showLog(device.typeName + device.index + "配方读取操作执行失败");
                    MessageBox.Show("配方读取操作执行失败");
                }
                break;

            case "btn_Recipe_OK":
                rsno = CS7TCP.WriteBool(Z通讯设置.plcHandle, 0x84, device.address, 63, 2, 1);
                if (rsno == 0)
                {
                    btn_Recipe_OK.BackColor = Color.LightGreen;
                    parent.showLog(device.typeName + device.index + "配方确认操作执行成功");
                    //插入数据到数据库数据表进行记录
                    saveToDatabaseTable();
                }
                else
                {
                    parent.showLog(device.typeName + device.index + "配方确认操作执行失败");
                    MessageBox.Show("配方确认操作执行失败");
                }
                break;
            }
            //按下按钮后自动开始计时
            TimerCloseRead.Enabled = true;
        }
        //除尘机风扇启动停止
        private void Chb_Fans_CheckedChanged(object sender, EventArgs e)
        {
            UInt32 FansSet = 0;

            if (Chb_Fans.Checked == true)
            {
                FansSet            = 1;
                Chb_Fans.BackColor = Color.LightGreen;
                Chb_Fans.Text      = "启动";
            }
            else
            {
                FansSet            = 0;
                Chb_Fans.BackColor = Color.Red;
                Chb_Fans.Text      = "停止";
            }

            int resno = CS7TCP.WriteWord(Z通讯设置.plcHandle, 0x84, device.address, 6, FansSet);
        }
        //除尘机毛刷反转
        private void Chb_Brush_R_CheckedChanged(object sender, EventArgs e)
        {
            UInt32 BrushsSet = 0;

            if (Chb_Brush_R.Checked == true)
            {
                Chb_Brush.Checked     = false;
                Chb_Brush.BackColor   = Color.Red;
                BrushsSet             = 2;
                Chb_Brush_R.BackColor = Color.LightGreen;
                Chb_Brush_R.Text      = "反转";
            }
            else
            {
                BrushsSet             = 0;
                Chb_Brush_R.BackColor = Color.Red;
                //Chb_Brush.Text = "反转";
            }

            int resno = CS7TCP.WriteWord(Z通讯设置.plcHandle, 0x84, device.address, 8, BrushsSet);
        }
 //从本地ini文件读取物料编码和配方编号
 public void RecipeNO_Input()
 {
     Int32[]  value = new Int32[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, };
     string[] way   = new string[] { @"\Default-product1.ini", @"\Default-product2.ini", @"\Default-product3.ini", @"\Default-product4.ini", @"\Default-product5.ini", @"\Default-product6.ini",
                                     @"\Default-product7.ini", @"\Default-product8.ini", @"\Default-product9.ini", @"\Default-product10.ini",
                                     @"\Default-product11.ini", @"\Default-product12.ini", @"\Default-product13.ini", @"\Default-product14.ini", @"\Default-product15.ini", @"\Default-product16.ini",
                                     @"\Default-product17.ini", @"\Default-product18.ini", @"\Default-product19.ini", @"\Default-product20.ini" };
     //如果输入为空时自动返回之前的值
     if (txb_Recipe_NO.Text.Trim() == "")
     {
         UInt32 ReadBack = 0;
         CS7TCP.ReadWord(Z通讯设置.plcHandle, 0x84, device.address, 52, ref ReadBack);
         txb_Recipe_NO.Text = Convert.ToString(ReadBack);
         MessageBox.Show("输入无效,配方区间在1-20之间,请输入适当的配方编号");
     }
     else
     {
         for (int i = 0; i < value.Length; i++)
         {
             //把中间转存的Default - code.ini内容路径找到然后读取出内容存储在txb_tiaoma.Text中
             if (Convert.ToUInt32(txb_Recipe_NO.Text) == value[i])
             {
                 string thispath = Application.StartupPath + way[i];                 //定义变量thisPath,获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称+路径
                 if (!System.IO.File.Exists(thispath))
                 {
                     return;                                                                         //确定指定的文件是否存在(文件的路径);如果不存在则执行return
                 }
                 try
                 {
                     lab_Prt_NO.Text = System.IO.File.ReadAllText(thispath);                         //打开一个文本文件,读取文件的所有行,然后关闭该文件
                 }
                 catch { }
             }
         }
     }
 }
        //判定离开后开始执行写入指令
        //配方参数输入,,,,,,对话框中参数输入
        public void handleInputComplete(object sender)
        {
            System.Windows.Forms.TextBox _textbox = (System.Windows.Forms.TextBox)sender;
            switch (_textbox.Name)
            {
            //主输送线速度写入
            case "txb_Control_Conveyor_Main":
                UInt32 Write_Conveyor_Main = 0;                                                     //定义读取变量
                if (txb_Control_Conveyor_Main.Text.Trim() == "")
                {
                    UInt32 ReadBack_Write_Conveyor_Main = 0;
                    CS7TCP.ReadWord(Z通讯设置.plcHandle, 0x84, device.address, 0, ref ReadBack_Write_Conveyor_Main);
                    txb_Control_Conveyor_Main.Text = Convert.ToString(Convert.ToDecimal(ReadBack_Write_Conveyor_Main) / 10);
                    MessageBox.Show("参数区间在1-20之间,请输入适当的参数");
                }
                else
                {
                    Write_Conveyor_Main = Convert.ToUInt32(Convert.ToDecimal(txb_Control_Conveyor_Main.Text.ToString()) * 10);              //转换成String格式然后显示在textbox里面
                    if (Convert.ToUInt32(Convert.ToDecimal(txb_Control_Conveyor_Main.Text) * 10) <= 200 && Convert.ToUInt32(Convert.ToDecimal(txb_Control_Conveyor_Main.Text) * 10) >= 0)
                    {
                        int resno = CS7TCP.WriteWord(Z通讯设置.plcHandle, 0x84, device.address, 0, Write_Conveyor_Main);             //写入配方编号
                        if (resno == 0)
                        {
                            A0开机画面 parent = (A0开机画面)Parent.FindForm();
                            parent.showLog("     输送线速度写入成功!");
                        }
                        else
                        {
                            MessageBox.Show("输送线速度写入失败,请重新输入");
                        }
                    }
                    else
                    {
                        UInt32 ReadBack_Write_Conveyor_Main = 0;
                        CS7TCP.ReadWord(Z通讯设置.plcHandle, 0x84, device.address, 0, ref ReadBack_Write_Conveyor_Main);
                        txb_Control_Conveyor_Main.Text = Convert.ToString(Convert.ToDecimal(ReadBack_Write_Conveyor_Main) / 10);
                        MessageBox.Show("参数区间在1-20之间,请输入适当的参数");
                    }
                }
                break;

            //第一组高度设定写入
            case "txb_Control_Brush_Height":
                UInt32 Write_App1_Height = 0;                                                     //定义读取变量
                if (txb_Control_Brush_Height.Text.Trim() == "")
                {
                    UInt32 ReadBack_Write_App1_Height = 0;
                    CS7TCP.ReadWord(Z通讯设置.plcHandle, 0x84, device.address, 2, ref ReadBack_Write_App1_Height);
                    txb_Control_Brush_Height.Text = Convert.ToString(Convert.ToDecimal(ReadBack_Write_App1_Height) / 100);
                    MessageBox.Show("参数区间在1-200之间,请输入适当的参数");
                }
                else
                {
                    Write_App1_Height = Convert.ToUInt32(Convert.ToDecimal(txb_Control_Brush_Height.Text.ToString()) * 100);              //转换成String格式然后显示在textbox里面
                    if (Convert.ToUInt32(Convert.ToDecimal(txb_Control_Brush_Height.Text) * 100) <= 20000 && Convert.ToUInt32(Convert.ToDecimal(txb_Control_Brush_Height.Text) * 100) > 0)
                    {
                        int resno = CS7TCP.WriteWord(Z通讯设置.plcHandle, 0x84, device.address, 2, Write_App1_Height);             //写入配方编号
                        if (resno == 0)
                        {
                            A0开机画面 parent = (A0开机画面)Parent.FindForm();
                            parent.showLog("     第一组高度参数写入成功!");
                        }
                        else
                        {
                            MessageBox.Show("第一组高度参数写入失败,请重新输入");
                        }
                    }
                    else
                    {
                        UInt32 ReadBack_Write_App1_Height = 0;
                        CS7TCP.ReadWord(Z通讯设置.plcHandle, 0x84, device.address, 2, ref ReadBack_Write_App1_Height);
                        txb_Control_Brush_Height.Text = Convert.ToString(Convert.ToDecimal(ReadBack_Write_App1_Height) / 100);
                        MessageBox.Show("参数区间在1-200之间,请输入适当的参数");
                    }
                }
                break;

            //第一组高度误差补偿设定写入
            case "txb_Control_Brush_buchang":
                UInt32 Write_App1_buchang = 0;                                                     //定义读取变量
                if (txb_Control_Brush_buchang.Text.Trim() == "")
                {
                    UInt32 ReadBack_Write_App1_buchang = 0;
                    CS7TCP.ReadWord(Z通讯设置.plcHandle, 0x84, device.address, 4, ref ReadBack_Write_App1_buchang);
                    txb_Control_Brush_buchang.Text = Convert.ToString(Convert.ToDecimal(ReadBack_Write_App1_buchang) / 100);
                    MessageBox.Show("参数区间在1-20之间,请输入适当的参数");
                }
                else
                {
                    Write_App1_buchang = Convert.ToUInt32(Convert.ToDecimal(txb_Control_Brush_buchang.Text.ToString()) * 100);              //转换成String格式然后显示在textbox里面
                    if (Convert.ToUInt32(Convert.ToDecimal(txb_Control_Brush_buchang.Text) * 100) <= 10000 && Convert.ToUInt32(Convert.ToDecimal(txb_Control_Brush_buchang.Text) * 100) >= 0)
                    {
                        int resno = CS7TCP.WriteWord(Z通讯设置.plcHandle, 0x84, device.address, 4, Write_App1_buchang);             //写入配方编号
                        if (resno == 0)
                        {
                            A0开机画面 parent = (A0开机画面)Parent.FindForm();
                            parent.showLog("     第一组高度误差补偿参数写入成功!");
                        }
                        else
                        {
                            MessageBox.Show("第一组高度误差补偿写入失败,请重新输入");
                        }
                    }
                    else
                    {
                        UInt32 ReadBack_Write_App1_buchang = 0;
                        CS7TCP.ReadWord(Z通讯设置.plcHandle, 0x84, device.address, 4, ref ReadBack_Write_App1_buchang);
                        txb_Control_Brush_buchang.Text = Convert.ToString(Convert.ToDecimal(ReadBack_Write_App1_buchang) / 100);
                        MessageBox.Show("参数区间在1-20之间,请输入适当的参数");
                    }
                }
                break;

            //配方编号写入
            case "txb_Recipe_NO":
                UInt32 Write_Recipe_NO = 0;                                                     //定义读取变量
                if (txb_Recipe_NO.Text.Trim() == "")
                {
                    UInt32 ReadBack = 0;
                    CS7TCP.ReadWord(Z通讯设置.plcHandle, 0x84, device.address, 52, ref ReadBack);
                    txb_Recipe_NO.Text = Convert.ToString(ReadBack);
                    MessageBox.Show("输入无效,配方区间在1-20之间,请输入适当的配方编号");
                }
                else
                {
                    Write_Recipe_NO = Convert.ToUInt32(txb_Recipe_NO.Text.ToString());              //转换成String格式然后显示在textbox里面
                    if (Convert.ToUInt32(txb_Recipe_NO.Text) <= 20 && Convert.ToUInt32(txb_Recipe_NO.Text) >= 0)
                    {
                        int resno = CS7TCP.WriteWord(Z通讯设置.plcHandle, 0x84, device.address, 52, Write_Recipe_NO);            //写入配方编号
                        if (resno == 0)
                        {
                            A0开机画面 parent = (A0开机画面)Parent.FindForm();
                            parent.showLog("     配方编号写入成功!");
                        }
                        else
                        {
                            MessageBox.Show("配方编号写入失败,请重新输入");
                        }
                    }
                    else
                    {
                        UInt32 ReadBack = 0;
                        CS7TCP.ReadWord(Z通讯设置.plcHandle, 0x84, device.address, 52, ref ReadBack);
                        txb_Recipe_NO.Text = Convert.ToString(ReadBack);
                        MessageBox.Show("输入无效,配方区间在1-20之间,请输入适当的配方编号");
                    }
                }
                break;
            }
        }
示例#7
0
        //把通讯读取出来的数据进行分析,采用字节连读的方式,把数据一次读出
        public override void analyseDatasRecyle(int DBaddress)
        {
            lock (this)
            {
                //通讯读取参数
                int resno = CS7TCP.ReadBlockAsByte(Z通讯设置.plcHandle, 0x84, address, 0, 220, datas);
                //当返回值为0时表示通讯成功,
                if (resno == 0)
                {
                    ////获取设备内部已经有的数据
                    ControlAppSpeed1       = getIntFromBytes(datas, 0, 2);
                    ControlDocSpeed1       = getIntFromBytes(datas, 2, 2);
                    ControlZhengpingSpeed1 = getIntFromBytes(datas, 4, 2);
                    ControlAppSpeed2       = getIntFromBytes(datas, 6, 2);
                    ControlDocSpeed2       = getIntFromBytes(datas, 8, 2);
                    ControlConveyorSpeed   = getIntFromBytes(datas, 10, 2);

                    ControlAppSpeed3 = getIntFromBytes(datas, 12, 2);
                    ControlDocSpeed3 = getIntFromBytes(datas, 14, 2);

                    ControlAppHeight1       = getIntFromBytes(datas, 16, 2);
                    ControlZhengpingHeight1 = getIntFromBytes(datas, 18, 2);
                    ControlAppHeight2       = getIntFromBytes(datas, 20, 2);
                    ControlAppHeight3       = getIntFromBytes(datas, 22, 2);

                    ControlAppHeight11       = getIntFromBytes(datas, 24, 2);
                    ControlZhengpingHeight11 = getIntFromBytes(datas, 26, 2);
                    ControlAppHeight22       = getIntFromBytes(datas, 28, 2);
                    ControlAppHeight33       = getIntFromBytes(datas, 30, 2);

                    ControlAppTemp1 = getIntFromBytes(datas, 32, 2);
                    ControlAppTemp2 = getIntFromBytes(datas, 34, 2);
                    ControlAppTemp3 = getIntFromBytes(datas, 36, 2);
                    //配方编号读回
                    bianhao = getIntFromBytes(datas, 52, 2);


                    //输送线速度监控,滚轮参数功率监控
                    MonitorAppSpeed1       = getIntFromBytes(datas, 66, 2);
                    MonitorDocSpeed1       = getIntFromBytes(datas, 68, 2);
                    MonitorZhengpingSpeed1 = getIntFromBytes(datas, 70, 2);
                    MonitorAppSpeed2       = getIntFromBytes(datas, 72, 2);
                    MonitorDocSpeed2       = getIntFromBytes(datas, 74, 2);
                    //主次输送线的速度
                    MonitorConveyorSpeed1 = getIntFromBytes(datas, 76, 2);
                    MonitorConveyorSpeed2 = getIntFromBytes(datas, 78, 2);
                    //3#涂布轮和均布轮的速度
                    MonitorAppSpeed3 = getIntFromBytes(datas, 80, 2);
                    MonitorDocSpeed3 = getIntFromBytes(datas, 82, 2);
                    //1#2#3#涂布轮的高度
                    MonitorAppHeight1 = getIntFromBytes(datas, 84, 2);
                    MonitorAppHeight2 = getIntFromBytes(datas, 86, 2);
                    MonitorAppHeight3 = getIntFromBytes(datas, 88, 2);
                    //1#2#3#涂布轮油漆的温度
                    MonitorAppTemp1 = getIntFromBytes(datas, 92, 2);
                    MonitorAppTemp2 = getIntFromBytes(datas, 94, 2);
                    MonitorAppTemp3 = getIntFromBytes(datas, 96, 2);
                    //输送线运行时间和轮子运行时间
                    MonitorAppRunTime1       = getDoubleFromBytes(datas, 120, 4);
                    MonitorDocRunTime1       = getDoubleFromBytes(datas, 124, 4);
                    MonitorZhengpingRunTime1 = getDoubleFromBytes(datas, 128, 4);
                    MonitorAppRunTime2       = getDoubleFromBytes(datas, 132, 4);
                    MonitorDocRunTime2       = getDoubleFromBytes(datas, 136, 4);
                    MonitorConveyorRunTime1  = getDoubleFromBytes(datas, 140, 4);
                    MonitorConveyorRunTime2  = getDoubleFromBytes(datas, 144, 4);
                    MonitorAppRunTime3       = getDoubleFromBytes(datas, 148, 4);
                    MonitorDocRunTime3       = getDoubleFromBytes(datas, 152, 4);
                    //1#2#3#涂布轮的剩余声明周期
                    MonitorAppLeftTime1 = getDoubleFromBytes(datas, 156, 4);
                    MonitorAppLeftTime2 = getDoubleFromBytes(datas, 160, 4);
                    MonitorAppLeftTime3 = getDoubleFromBytes(datas, 164, 4);

                    //IO数据的解析
                    BitArray array = getBitArrayFromBytes(datas, 210, 4);
                    Q00 = array[0];
                    Q01 = array[1];
                    Q02 = array[2];
                    Q03 = array[3];
                    Q04 = array[4];
                    Q05 = array[5];
                    Q06 = array[6];
                    Q07 = array[7];

                    Q10 = array[8];
                    Q11 = array[9];

                    I00 = array[10];
                    I01 = array[11];
                    I02 = array[12];
                    I03 = array[13];
                    I04 = array[14];
                    I05 = array[15];
                    I06 = array[16];
                    I07 = array[17];

                    I10 = array[18];
                    I11 = array[19];
                    I12 = array[20];
                    I13 = array[21];
                    I14 = array[22];
                    I15 = array[23];

                    //shangWeiJiLiangTiaoZhong = array[24];
                    //quanZiDongYunXingZhong = array[25];
                    //shouDongYunXingZhong = array[26];
                    //baoJingTingJiZhong = array[27];
                    //shuSongxianYunXingZhong = array[28];
                    //UV1YungXingZhong = array[29];
                    //UV2YungXingZhong = array[30];
                    //UV3YungXingZhong = array[31];

                    //shuSongDaiStatusCode = getIntFromBytes(datas, 136, 2);
                    //UV1StatusCode = getIntFromBytes(datas, 138, 1);
                    //UV2StatusCode = getIntFromBytes(datas, 139, 1);
                    //UV3StatusCode = getIntFromBytes(datas, 140, 1);
                    //UV4StatusCode = getIntFromBytes(datas, 141, 1);
                    //UV5StatusCode = getIntFromBytes(datas, 142, 1);
                    //UV6StatusCode = getIntFromBytes(datas, 143, 1);
                    //UV7StatusCode = getIntFromBytes(datas, 144, 1);
                    //UV8StatusCode = getIntFromBytes(datas, 145, 1);
                }
            }
        }