Example #1
0
        //一行中获取地址和区域 /根据一行的数据 返回固定的 plc单元格参数 这个函数 是返回绝对地址的
        private bool  getAddrAndArea(DataRow row, ref int mAddr, ref int mArea, ref string DSmode)
        {
            DSmode = row["mode"].ToString().Trim();

            string area     = "";///地址区域
            string valueStr = row["addr"].ToString().Trim();
            int    count    = 0;

            ConstantMethod.getAddrAndAreaByStr(valueStr, ref mAddr, ref area, DeviceId);

            //地址超了 无效 暂且定XDM 最大69999
            if ((mAddr < 0) || (mAddr > Constant.DTTCPMAXAddr))
            {
                return(false);
            }
            if (!int.TryParse(row["count"].ToString().Trim(), out count))
            {
                return(false);
            }
            if (DeviceId == Constant.xzjDeivceId)
            {
                mArea = XJPLCPackCmdAndDataUnpack.AreaGetFromStr(area);
                mAddr = XJPLCPackCmdAndDataUnpack.RelAbsGet(mAddr, mArea, DeviceId);
            }
            else
            {
                mArea = DTTcpCmdPackAndDataUnpack.GetIntAreaFromStr(area);

                mAddr = DTTcpCmdPackAndDataUnpack.GetAbsAddrFromStr(mAddr, area);
            }

            return(true);
        }
Example #2
0
        public DTTcpPlcInfo(int addr, string areaIn, string Mode)
        {
            this.relativeaddr = addr;

            this.StrArea = areaIn;

            absAddr   = DTTcpCmdPackAndDataUnpack.GetAbsAddrFromStr(relativeaddr, StrArea);
            intArea   = DTTcpCmdPackAndDataUnpack.GetIntAreaFromStr(StrArea);
            ValueMode = Mode;
        }
Example #3
0
        public DTTcpPlcInfo(int addr, string areaIn, string Mode, int plcId)
        {
            this.relativeaddr = addr;

            this.StrArea = areaIn;
            //区分 dvp15mc 和 As PLC
            if (plcId == Constant.xzjDeivceId)
            {
                intArea = XJPLCPackCmdAndDataUnpack.AreaGetFromStr(areaIn);
                absAddr = XJPLCPackCmdAndDataUnpack.RelAbsGet(addr, intArea, 0);
            }
            else
            {
                absAddr = DTTcpCmdPackAndDataUnpack.GetAbsAddrFromStr(relativeaddr, StrArea);
                intArea = DTTcpCmdPackAndDataUnpack.GetIntAreaFromStr(StrArea);
            }

            ValueMode = Mode;
        }
Example #4
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;

        }