Ejemplo n.º 1
0
        //开始分割
        public void splitLstGetLst(List <int> splitLst,
                                   List <DTTcpPlcInfo> pLst,
                                   List <List <byte> > ReadCmdOutLst,
                                   List <List <byte> > ReadCmdInLst,
                                   int id
                                   )
        {
            //开始分割
            for (int i = 0; i < splitLst.Count; i++)
            {
                DTTcpPlcInfo[] temp;
                List <byte>    tempOut   = new List <byte>();
                List <byte>    tempIn    = new List <byte>();
                int            skipCount = ConstantMethod.getSum(splitLst, i);
                temp = pLst.Skip(skipCount).Take(splitLst[i]).ToArray();
                if (id == Constant.D_ID)
                {
                    DTTcpCmdPackAndDataUnpack.ASPLCPackReadDCmd(temp, tempOut, tempIn);
                }

                if (id == Constant.M_ID)
                {
                    DTTcpCmdPackAndDataUnpack.ASPLCPackReadMCmd(temp, tempOut, tempIn);
                }

                if (tempOut.Count > 0)
                {
                    ReadCmdOutLst.Add(tempOut);
                }
                if (tempIn.Count > 0)
                {
                    ReadCmdInLst.Add(tempIn);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 本函数的思路:
        /// 1.根据需要读取的表格 进行分解成单个地址的单元下发指令
        /// 2.信捷PLC 发送一条读取指令会包含D区起始地址和M区地址 并跟着相应的读取个数
        /// 3.相邻地址相差7以内的 可以一次性读完
        /// </summary>
        void PackCmdReadDMDataOut(DataTable dataForm0)
        {
            List <DTTcpPlcInfo> plcInfoLst = new List <DTTcpPlcInfo>();

            DPlcInfo.Clear();
            MPlcInfo.Clear();
            //分段的参数 初始化
            tcpClientManager.ReadDCmdOutLst.Clear();
            tcpClientManager.ReadDCmdInLst.Clear();
            tcpClientManager.ReadMCmdOutLst.Clear();
            tcpClientManager.ReadMCmdInLst.Clear();
            splitDLst.Clear();
            splitMLst.Clear();

            foreach (DataRow row in dataForm0.Rows)
            {
                int    mAddr     = -1;
                int    count     = -1;
                int    mArea     = -1;
                string strSplit2 = "";
                string DSmode    = ""; //单字还是双字
                #region 获取地址个数区域 创建plcinfo类 并添加到集合
                if (row == null)
                {
                    return;
                }

                if (!getAddrAndArea(row, ref mAddr, ref mArea, ref DSmode, ref strSplit2, ref count))
                {
                    continue;
                }
                //这里数组进行统计
                //传入数据起始地址 个数 区域 模式
                DTTcpPlcInfo[] tmpInfoLst = DTTcpCmdPackAndDataUnpack.GetPlcInfo(mAddr, count, strSplit2, DSmode, DeviceId);

                if (tmpInfoLst.Count() > 0)
                {
                    plcInfoLst.AddRange(tmpInfoLst);
                }
                #endregion
            }
            #region 排序 去重复 统计DM 起始点
            //排序 按照绝对地址
            plcInfoLst = plcInfoLst.OrderBy(x => x.AbsAddr).ToList();
            //去重复
            plcInfoLst = plcInfoLst.Distinct(new ModelComparerDTTcpInfo()).ToList();

            //分离D 区 M区
            if (DeviceId == Constant.xzjDeivceId)
            {
                DPlcInfo = plcInfoLst.FindAll(t => t.IntArea < (Constant.HSD_ID));
                MPlcInfo = plcInfoLst.FindAll(t => t.IntArea > (Constant.HSD_ID));
            }
            else
            {
                DPlcInfo = plcInfoLst.FindAll(t => t.IntArea > (Constant.MXAddrId));
                MPlcInfo = plcInfoLst.FindAll(t => t.IntArea < (Constant.QWAddrId));
            }

            #endregion
            #region  根据断点 建立命令的表格缓冲lst 然后创建读取DM区域的命令

            tcpClientManager.ClearCmd();

            if (DeviceId == Constant.xzjDeivceId)
            {
                //针对Dplc进行拆分 按照数据数量 进行拆分 逐渐加1
                if (DPlcInfo.Count > Constant.maxplcInfoCount)
                {
                    splitDLst =
                        splitLstGet(DPlcInfo.Count, Constant.maxplcInfoCount);

                    splitLstGetLst(splitDLst, DPlcInfo,
                                   tcpClientManager.ReadDCmdOutLst,
                                   tcpClientManager.ReadDCmdInLst, Constant.D_ID);
                }
                else
                {
                    if (DPlcInfo.Count > 0)
                    {
                        DTTcpCmdPackAndDataUnpack.ASPLCPackReadDCmd
                            (DPlcInfo.ToArray(), tcpClientManager.ReadDCmdOut, tcpClientManager.ReadDCmdIn);
                    }
                }
                //针对Dplc进行拆分 按照数据数量 进行拆分 逐渐加1
                if (MPlcInfo.Count > Constant.maxplcInfoCount)
                {
                    splitMLst =
                        splitLstGet(MPlcInfo.Count, Constant.maxplcInfoCount);
                    splitLstGetLst(splitMLst, MPlcInfo,
                                   tcpClientManager.ReadMCmdOutLst,
                                   tcpClientManager.ReadMCmdInLst, Constant.M_ID);
                }
                else
                if (MPlcInfo.Count > 0)
                {
                    DTTcpCmdPackAndDataUnpack.ASPLCPackReadMCmd
                        (MPlcInfo.ToArray(), tcpClientManager.ReadMCmdOut, tcpClientManager.ReadMCmdIn);
                }

                //dataform表格里面地址对应dplcinfo和mplcinfo的数据对应起来
                AsPlcFindIndexInPlcInfo(dataForm0, DPlcInfo, MPlcInfo);
            }
            else
            {
                DTTcpCmdPackAndDataUnpack.
                PackReadDCmd(DPlcInfo.ToArray(), tcpClientManager.ReadDCmdOut, tcpClientManager.ReadDCmdIn);


                DTTcpCmdPackAndDataUnpack.
                PackReadMCmd(MPlcInfo.ToArray(), tcpClientManager.ReadMCmdOut, tcpClientManager.ReadMCmdIn);

                //dataform表格里面地址对应dplcinfo和mplcinfo的数据对应起来
                FindIndexInPlcInfo(dataForm0, DPlcInfo, MPlcInfo);
            }
        }