Exemplo n.º 1
0
        private void btnPLCRun_Click(object sender, EventArgs e)
        {
            //plc地址不是 02,验证失败

            PPIReadWritePara para = new PPIReadWritePara();

            para.PlcAddress = int.Parse(txtPLC.Text);

            if (PPIHelper.PLCRun(para))
            {
                btnStop.Enabled   = true;
                btnPLCRun.Enabled = false;
            }
        }
Exemplo n.º 2
0
        private void btnRead_Click(object sender, EventArgs e)
        {
            PPIReadWritePara readResult = new PPIReadWritePara();

            //ZLB_PPIHelper zlbPPI = new ZLB_PPIHelper();

            if (tcpClient.Connected)
            {
                PPIReadWritePara para = new PPIReadWritePara();
                para.StorageType = (Enums.StorageType)Enum.Parse(typeof(Enums.StorageType), comStore.Text);
                para.TcpClient   = tcpClient;
                para.ByteAddress = Int32.Parse(txtAddress.Text);
                para.Bitnumber   = int.Parse(txtBit.Text);
                para.PlcAddress  = int.Parse(txtPLC.Text);
                para.ComNum      = int.Parse(txtComNum.Text);

                para.ReadCount  = int.Parse(txtReadCount.Text) > 0 ? int.Parse(txtReadCount.Text) : 1;
                para.WriteValue = int.Parse(txtWriteValue.Text);
                if (para.StorageType == Enums.StorageType.T)
                {
                    MeiCloud.ZLB.ZlbDrive.PPI.PPIAddress ppiAddress = new MeiCloud.ZLB.ZlbDrive.PPI.PPIAddress();

                    drive.WriteCom(para.ComNum, ppiHelper.GetTReadDword(para, out ppiAddress));
                    //线程 对队列操作,这里就不能ReadCom

                    byte[] receivesAffirm = drive?.receiceData[para.ComNum];
                    if (receivesAffirm != null && receivesAffirm.Length > 0)
                    {
                        if (receivesAffirm[5] == Convert.ToByte(para.ComNum) && receivesAffirm[6] == ppiAddress.confirm)
                        {
                            drive.WriteCom(para.ComNum, ppiAddress.Affirm);
                        }
                        drive.receiceData[para.ComNum] = null;
                    }
                    else
                    {
                        Thread.Sleep(50);
                        if (receivesAffirm != null && receivesAffirm.Length > 0)
                        {
                            if (receivesAffirm[5] == Convert.ToByte(para.ComNum) && receivesAffirm[6] == ppiAddress.confirm)
                            {
                                drive.WriteCom(para.ComNum, ppiAddress.Affirm);
                            }
                            drive.receiceData[para.ComNum] = null;
                        }
                        else
                        {
                        }
                    }
                }
                else
                {
                    #region switch
                    switch (comRead.Text)
                    {
                    case "Bit":

                        readResult = ppiHelper.Readbit(para);

                        txtSendCmd.Text = ZLB_PPIHelper.sendCmd;
                        break;

                    case "Byte":
                        readResult      = ppiHelper.Readbytes(para);
                        txtSendCmd.Text = (ZLB_PPIHelper.sendCmd);
                        break;

                    case "Word":
                        readResult      = ppiHelper.ReadWords(para);
                        txtSendCmd.Text = (ZLB_PPIHelper.sendCmd);

                        txtSendCmd.Text = ZLB_PPIHelper.sendCmd;
                        break;

                    case "DWord":

                        readResult      = ppiHelper.ReadDoubleWord(para);
                        txtSendCmd.Text = (ZLB_PPIHelper.sendCmd);

                        txtSendCmd.Text = ZLB_PPIHelper.sendCmd;
                        break;

                    default:

                        break;
                    }
                    #endregion
                }
            }
            else
            {
                MessageBox.Show("连接断开");
            }

            if (readResult.IsSuceess)
            {
                txtReceive1.Text = ZLB_PPIHelper.receiveByte;
                txtValue.Text    = ByteHelper.ByteToString(readResult.ReadValue);
            }
            else
            {
                txtReceive1.Text = "读取失败";
            }
        }
Exemplo n.º 3
0
        private void btnWrite_Click(object sender, EventArgs e)
        {
            int wValue = 0;

            bool          flag   = false;
            ZLB_PPIHelper zlbPPI = new ZLB_PPIHelper();

            if (txtWriteValue.Text.Length == 0)
            {
                MessageBox.Show("请输数值");
            }
            else
            {
                if ((Enums.StorageType)Enum.Parse(typeof(Enums.StorageType), comStore.Text) == Enums.StorageType.C || (Enums.StorageType)Enum.Parse(typeof(Enums.StorageType), comStore.Text) == Enums.StorageType.T)
                {
                    MessageBox.Show("T,C寄存器等不能用写命令写入");
                    return;
                }

                if (client.Connected)
                {
                    PPIReadWritePara para = new PPIReadWritePara();
                    para.StorageType = (Enums.StorageType)Enum.Parse(typeof(Enums.StorageType), comStore.Text);
                    para.TcpClient   = tcpClient;
                    para.ByteAddress = Int32.Parse(txtAddress.Text);
                    para.Bitnumber   = int.Parse(txtBit.Text);
                    para.PlcAddress  = int.Parse(txtPLC.Text);
                    para.ComNum      = int.Parse(txtComNum.Text);

                    para.ReadCount  = int.Parse(txtReadCount.Text) > 0 ? int.Parse(txtReadCount.Text) : 1;
                    para.WriteValue = int.Parse(txtWriteValue.Text);



                    if (int.TryParse(txtWriteValue.Text, out wValue))
                    {
                        if ((Enums.StorageType)Enum.Parse(typeof(Enums.StorageType), comStore.Text) == Enums.StorageType.T)
                        {
                            if (zlbPPI.TwriteDWord(para))
                            {
                                txtSendCmd.Text = (ZLB_PPIHelper.sendCmd);
                                flag            = true;
                            }
                        }
                        else if ((Enums.StorageType)Enum.Parse(typeof(Enums.StorageType), comStore.Text) == Enums.StorageType.C)
                        {
                            if (zlbPPI.CWriteWord(para))
                            {
                                flag            = true;
                                txtSendCmd.Text = (ZLB_PPIHelper.sendCmd);
                            }
                        }
                        else
                        {
                            #region switch
                            switch (comWrite.Text)
                            {
                            case "Bit":

                                if (ppiHelper.WriteBit(para))
                                {
                                    flag = true;

                                    txtSendCmd.Text = (ZLB_PPIHelper.sendCmd);
                                }
                                break;

                            case "Byte":

                                if (ppiHelper.Writebyte(para))

                                {
                                    flag            = true;
                                    txtSendCmd.Text = (ZLB_PPIHelper.sendCmd);
                                }
                                break;

                            case "Word":
                                if (ppiHelper.WriteWord(para))
                                {
                                    txtSendCmd.Text = (ZLB_PPIHelper.sendCmd);
                                    flag            = true;
                                }
                                break;

                            case "DWord":
                                if (ppiHelper.WriteDoubleWord(para))

                                {
                                    flag = true;

                                    txtSendCmd.Text = (ZLB_PPIHelper.sendCmd);
                                }
                                break;

                            default:

                                break;
                            }

                            #endregion
                        }
                        if (flag)
                        {
                            txtReceive1.Text = (ZLB_PPIHelper.receiveByte);
                        }
                        else
                        {
                            txtReceive1.Text = "写入失败";
                        }
                    }
                    else
                    {
                        MessageBox.Show("请输入正确数值");
                    }
                }
                else
                {
                    MessageBox.Show("连接失败");
                }
            }
        }
Exemplo n.º 4
0
        private void btnWrite_Click(object sender, EventArgs e)
        {
            if (!PPIHelper.serialPort1.IsOpen)
            {
                MessageBox.Show("请设置串口参数后打开", "警告");
                return;
            }

            int wValue = 0;

            if (txtWriteValue.Text.Length == 0)
            {
                MessageBox.Show("请输数值");
            }
            else
            {
                //if ((Enums.StorageType)Enum.Parse(typeof(Enums.StorageType), comStore.Text)==Enums.StorageType.C|| (Enums.StorageType)Enum.Parse(typeof(Enums.StorageType), comStore.Text)==Enums.StorageType.T)
                //{
                //    MessageBox.Show("T,C寄存器等不能用写命令写入");
                //    return;

                //}

                PPIReadWritePara para = new PPIReadWritePara();
                bool             flag = false;

                para.ByteAddress = int.Parse(txtAddress.Text);
                para.Bitnumber   = Int32.Parse(txtBit.Text);
                para.StorageType = (Enums.StorageType)
                                   Enum.Parse(typeof(Enums.StorageType), comStore.Text);
                para.PlcAddress = int.Parse(txtPLC.Text);



                if (int.TryParse(txtWriteValue.Text, out wValue))
                {
                    para.WriteValue = int.Parse(txtWriteValue.Text);
                    if ((Enums.StorageType)Enum.Parse(typeof(Enums.StorageType), comStore.Text) == Enums.StorageType.T)
                    {
                        if (PPIHelper.TwriteDWord(para))
                        {
                            txtSendCmd.Text = (PPIHelper.sendCmd);
                            flag            = true;
                        }
                    }
                    else if ((Enums.StorageType)Enum.Parse(typeof(Enums.StorageType), comStore.Text) == Enums.StorageType.C)
                    {
                        if (PPIHelper.CWriteWord(para))
                        {
                            txtSendCmd.Text = PPIHelper.sendCmd;
                            flag            = true;
                        }
                    }
                    else
                    {
                        #region switch
                        switch (comWrite.Text)
                        {
                        case "Bit":

                            if (PPIHelper.WriteBit(para))
                            {
                                txtSendCmd.Text = (PPIHelper.sendCmd);
                                flag            = true;
                            }
                            break;

                        case "Byte":

                            if (PPIHelper.Writebyte(para))
                            {
                                txtSendCmd.Text = PPIHelper.sendCmd;
                                flag            = true;
                            }
                            break;

                        case "Word":

                            if (PPIHelper.WriteWord(para))
                            {
                                txtSendCmd.Text = (PPIHelper.sendCmd);
                                flag            = true;
                            }


                            break;

                        case "DWord":

                            if (PPIHelper.WriteDWord(para))
                            {
                                txtSendCmd.Text = PPIHelper.sendCmd;
                                flag            = true;
                            }
                            break;

                        default:

                            break;
                        }

                        #endregion
                    }



                    if (flag)
                    {
                        txtReceive.Text = PPIHelper.receiveByte;
                    }
                    else
                    {
                        txtReceive.Text = "写入失败";
                    }
                }
                else
                {
                    MessageBox.Show("请输入正确数值");
                }
            }
        }
Exemplo n.º 5
0
        private void btnRead_Click(object sender, EventArgs e)
        {
            if (!PPIHelper.serialPort1.IsOpen)
            {
                MessageBox.Show("请设置串口参数后打开", "警告");
                return;
            }



            PPIReadWritePara para       = new PPIReadWritePara();
            PPIReadWritePara readResult = new PPIReadWritePara();

            para.ByteAddress = int.Parse(txtAddress.Text);
            para.Bitnumber   = Int32.Parse(txtBit.Text);
            para.StorageType = (Enums.StorageType)
                               Enum.Parse(typeof(Enums.StorageType), comStore.Text);
            para.PlcAddress = int.Parse(txtPLC.Text);


            if (para.StorageType == Enums.StorageType.T)
            {
                readResult = PPIHelper.TReadDword(para);

                txtSendCmd.Text = (PPIHelper.sendCmd);
            }
            else
            {
                #region switch
                switch (comRead.Text)
                {
                case "Bit":

                    readResult = PPIHelper.Readbit(para);

                    txtSendCmd.Text = (PPIHelper.sendCmd);

                    break;

                case "Byte":

                    readResult      = PPIHelper.Readbytes(para);
                    txtSendCmd.Text = (PPIHelper.sendCmd);
                    break;

                case "Word":

                    readResult      = PPIHelper.ReadWords(para);
                    txtSendCmd.Text = (PPIHelper.sendCmd);
                    break;

                case "DWord":
                    readResult = PPIHelper.ReadDWord(para);

                    txtSendCmd.Text = (PPIHelper.sendCmd);

                    break;

                default:

                    break;
                }
                #endregion
            }
            if (readResult.IsSuceess)
            {
                txtReceive.Text = (PPIHelper.receiveByte);

                txtValue.Text = ByteToString(readResult.ReadValue);
            }
            else
            {
                txtReceive.Text = "读取失败";
            }
        }