Пример #1
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            weight_lpf     = (GenericOp.weight * 2 + weight_lpf * 8) / 10;
            labelPosX.Text = "X位置:" + GenericOp.xPos.ToString() + "[" + GenericOp.xPos_servo.ToString() + "] ,Z位置:" + GenericOp.zPos.ToString() + "[" + GenericOp.zPos_servo.ToString() + "] ,重量:" + weight_lpf.ToString() + "公斤";
            if (SerialWireless.GetGtryState(SerialWireless.GTRY_STATE_CLAMP))
            {
                labelPosX.Text += ",夹爪合";
            }
            if (SerialWireless.GetGtryState(SerialWireless.GTRY_STATE_CLAMP_RELAX))
            {
                labelPosX.Text += ",夹爪开";
            }

            label1.Text = "";
            for (int i = 0; i < 6; i++)
            {
                if (SerialManual.stoveLidState[i] == SerialManual.STOVE_LID_STATE.CLOSED)
                {
                    label1.Text += (i + 1).ToString() + "#关;      ";
                }
                else if (SerialManual.stoveLidState[i] == SerialManual.STOVE_LID_STATE.OPENED)
                {
                    label1.Text += (i + 1).ToString() + "#开;      ";
                }
                else
                {
                    label1.Text += (i + 1).ToString() + "#未知;    ";
                }
            }

            // 手动、自动按钮的 button 样式改变。
            if (GenericOp.AutoMode)
            {
                buttonAuto.BackColor   = systemBlue;
                buttonManual.BackColor = Color.LightGray;
            }
            else
            {
                buttonAuto.BackColor   = Color.LightGray;
                buttonManual.BackColor = systemBlue;
            }
            //
            if (GenericOp.EStop_Soft)
            {
                pictureBoxEStop.Image = HY_PIP.Properties.Resources.estop_down;
            }
            else
            {
                pictureBoxEStop.Image = HY_PIP.Properties.Resources.estop_up;
            }
        }
Пример #2
0
        public static bool CLAMP_DO()
        {
            if (GenericOp.EStop)
            {
                return(false);
            }
            // 重要步骤:上升到最高点(H点)
            SerialWireless.gtryCmd = SerialWireless.GTYRY_CMD.CLAMP;
            if (!SerialWireless.GetGtryState(SerialWireless.GTRY_STATE_CLAMP))
            {
                // 等待,直到命令结束
                return(false);
            }

            return(true);
        }
Пример #3
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            this.BackColor = MainForm.sysBackColor;

            // Layout 设置
            LayoutInit();

            timerLoadData.Start(); // 加载日志文件

            //
            serialWireless = new SerialWireless("COM3", 19200);
            try
            {
                serialWireless.Open();// 打开串口
            }
            catch (Exception e1)
            {
                MessageBox.Show("无线通信串口打开失败");
            }
            finally { }

            //
            serialManual = new SerialManual("COM5", 19200);
            try
            {
                serialManual.Open();// 打开串口
            }
            catch (Exception e1)
            {
                MessageBox.Show("手动操作台串口打开失败");
            }
            finally { }
            serialTemp = new SerialTemp("COM8", 9600);
            try
            {
                serialTemp.Open();// 打开串口
            }
            catch (Exception e1)
            {
                MessageBox.Show("温度串口打开失败");
            }
            finally { }
        }
Пример #4
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            this.BackColor = MainForm.sysBackColor;

            // Layout 设置
            LayoutInit();

            timerLoadData.Start(); // 加载日志文件

            //
            serialWireless = new SerialWireless("COM5", 19200);
            try
            {
                serialWireless.Open();// 打开串口
            }
            catch (Exception e1)
            {
                MessageBox.Show("无线通信串口打开失败");
            }
            finally { }

            //
            serialManual = new SerialManual("COM6", 19200);
            try
            {
                serialManual.Open();// 打开串口
            }
            catch (Exception e1)
            {
                MessageBox.Show("手动操作台串口打开失败");
            }
            finally { }
            modbus_TCP = new modbus_TCP("192.168.1.10", 3000);
            try
            {
                modbus_TCP.Connect();// 打开串口
            }
            catch (Exception e1)
            {
                MessageBox.Show("手动操作台串口打开失败");
            }
            finally { }
        }
Пример #5
0
        public static bool CLAMP_RELAX_DO()
        {
            if (GenericOp.EStop || !GenericOp.AutoMode)
            {
                return(false);
            }

            // ---------------------------------------
            //  TODO:   松开夹爪时,一定要判定有无夹具。最好是显示屏给出提示,确认操作。
            //

            // 重要步骤:上升到最高点(H点)
            SerialWireless.gtryCmd = SerialWireless.GTYRY_CMD.CLAMP_RELAX;
            if (!SerialWireless.GetGtryState(SerialWireless.GTRY_STATE_CLAMP_RELAX))
            {
                // 等待,直到命令结束
                return(false);
            }
            return(true);
        }
Пример #6
0
        private void RecvDataDecode(Byte inData)
        {
            // 逐个字节进行解析
            switch (recvStatus)
            {
            case RECV_STATUS.STATE_IDLE:
                if (inData == 0xAA)
                {
                    recvStatus = RECV_STATUS.STATE_GOT_HEAD1; // 获得了 HEAD1
                    commState  = COMM_STATE.RECVING;          // 状态转变为正在接收
                }
                break;

            case RECV_STATUS.STATE_GOT_HEAD1:
                if (inData == 0x55)
                {
                    recvStatus    = RECV_STATUS.STATE_GOT_HEAD2; // 获得了 HEAD2
                    RecvDataIndex = 0;
                }
                else
                {
                    recvStatus = RECV_STATUS.STATE_IDLE;    // 错误,返回初始状态
                }
                break;

            case RECV_STATUS.STATE_GOT_HEAD2:
                recvBuff[RecvDataIndex + 2] = inData;
                RecvDataIndex++;
                if (RecvDataIndex >= PayloadDataNum)
                {
                    recvStatus    = RECV_STATUS.STATE_GOT_DATA; // 获得了 数据
                    RecvDataIndex = 0;
                }
                break;

            case RECV_STATUS.STATE_GOT_DATA:
                if (inData == 0xA5)
                {
                    recvStatus = RECV_STATUS.STATE_GOT_END1;    // 获得了 END1
                }
                else
                {
                    recvStatus = RECV_STATUS.STATE_IDLE;    // 错误,返回初始状态
                }
                break;

            case RECV_STATUS.STATE_GOT_END1:
                if (inData == 0x5A)
                {
                    recvStatus = RECV_STATUS.STATE_IDLE;    // 重新恢复到IDLE状态
                    // 成功获得了所有数据
                    //recvBuff[0]
                    commState = COMM_STATE.IDLE;                                    // 成功收到数据,切换为通信空闲状态
                    //
                    GenericOp.xPos       = 5 * BitConverter.ToInt16(recvBuff, 4);   // 转化为 mm 单位
                    GenericOp.zPos       = 5 * BitConverter.ToInt16(recvBuff, 6);   // 转化为 mm 单位
                    GenericOp.xPos_servo = -5 * BitConverter.ToInt16(recvBuff, 8);  // 转化为 mm 单位
                    GenericOp.zPos_servo = -5 * BitConverter.ToInt16(recvBuff, 10); // 转化为 mm 单位
                    gtryState            = BitConverter.ToUInt32(recvBuff, 12);     // 龙门机构状态
                    GenericOp.weight     = (int)BitConverter.ToInt16(recvBuff, 16); // 载重量

                    // 龙门机构的急停状态的获取
                    if (SerialWireless.GetGtryState(SerialWireless.GTRY_STATE_ESTOP_STATE))
                    {
                        gtry_estop_state_cntr++;
                        if (gtry_estop_state_cntr % 20 == 0) // 每20包数据,检查一下PLC的急停状态
                        {
                            GenericOp.EStop_Soft = true;     // 根据 龙门急停状态 给  软急停标识  赋值,只赋值10次就不重复赋值。为了避免反复被刷新。
                        }
                    }
                    else
                    {
                        //gtry_estop_state_cntr = 0;
                    }

                    // 龙门原点回归请求
                    if (SerialWireless.GetGtryState(SerialWireless.GTRY_STATE_REQUEST_ZRN))
                    {
                        gtry_request_zrn_cntr++;
                        if (gtry_request_zrn_cntr > 5)
                        {
                            gtry_request_zrn_cntr = 5;
                            GenericOp.RequestZRN  = true;   // 请求原点回归标识  置位
                        }
                    }
                    else
                    {
                        gtry_request_zrn_cntr = 0;
                        GenericOp.RequestZRN  = false;
                    }
                }
                else
                {
                    recvStatus = RECV_STATUS.STATE_IDLE;    // 错误,返回初始状态
                }
                break;
            }
        }