예제 #1
0
파일: FormTest.cs 프로젝트: w7789475/EVOK
        public void WriteBitTest()
        {
            List <byte[]> value = new List <byte[]>();

            byte[] value0 = { 0x00, 0x00 };
            byte[] value1 = { 0 };
            byte[] value2 = { 0 };
            value.Add(value0);
            value.Add(value1);
            value.Add(value2);

            int[] addr  = { 45, 20, 0 };
            int[] id    = { Constant.MXAddrId, Constant.MXAddrId, Constant.MXAddrId };
            int[] count = { 15, 1, 1 };

            List <byte> cmdInLst = new List <byte>(); //反馈可变

            dtClient.CmdOut = DTTcpCmdPackAndDataUnpack.PackWriteBitCmd(addr, id, count, value, cmdInLst);
            dtClient.sendTestData();

            ConstantMethod.ShowInfo(richTextBox1, ConstantMethod.byteToHexStr(dtClient.CmdOut));

            ConstantMethod.ShowInfo(richTextBox1, ConstantMethod.byteToHexStr(cmdInLst.ToArray()));
        }
예제 #2
0
        public event socDataProcess EventDataProcess;//利用委托来声明事件

        #region 数据写操作       

        public bool SetMultipleDMArea(int Addr, int count, List<byte[]> value, string Area)
        {
            if (isDeviceReady)
            {
              
                List<int> addr = new List<int>();
                List<int> addressid = new List<int>();
                List<int> count0 = new List<int>();
                int addrid = DTTcpCmdPackAndDataUnpack.GetIntAreaFromStr(Area);
                if (DeviceId == Constant.xzjDeivceId)
                {
                    addrid = XJPLCPackCmdAndDataUnpack.AreaGetFromStr(Area);
                    for (int i = 0; i < count; i++)
                    {
                        if(value.Count>0)
                        addr.Add(Addr + i*(value[0].Count()/2));
                        addressid.Add(addrid);
                        count0.Add(1);
                    }
                }
                else                          
                for (int i = 0; i < count; i++)
                {                    
                    addr.Add(Addr+i);
                    addressid.Add(addrid);
                    count0.Add(1);
                }

                SetDMCmdOut.Clear();
                SetDMCmdIn.Clear();
                if (DeviceId == Constant.xzjDeivceId)
                {
                    if (addrid < Constant.HSD_ID)
                        SetDMCmdOut.AddRange(DTTcpCmdPackAndDataUnpack.AsPlcPackWriteByteCmd(addr.ToArray(), addressid.ToArray(), count0.ToArray(), value, SetDMCmdIn));
                    else
                        SetDMCmdOut.AddRange(DTTcpCmdPackAndDataUnpack.AsPlcPackWriteBitCmd(addr.ToArray(), addressid.ToArray(), count0.ToArray(), value, SetDMCmdIn));

                }
                else
                {
                    if (addrid > Constant.MXAddrId)
                        SetDMCmdOut.AddRange(DTTcpCmdPackAndDataUnpack.PackWriteByteCmd(addr.ToArray(), addressid.ToArray(), count0.ToArray(), value, SetDMCmdIn));
                    else
                        SetDMCmdOut.AddRange(DTTcpCmdPackAndDataUnpack.PackWriteBitCmd(addr.ToArray(), addressid.ToArray(), count0.ToArray(), value, SetDMCmdIn));
                }
                ConstantMethod.Delay(200); //延时一下 防止数据发太快 监控上看不到
                //防止前面在写数据 
                while (isWriteCmd)
                {
                    Application.DoEvents();
                }

                isWriteCmd = true;
               
                ConstantMethod.DelayWriteCmd(Constant.WriteCommTimeOut, ref isWriteCmd);

                return (!isWriteCmd);
            }
            return false;

        }