Ejemplo n.º 1
0
        public int PackSetCmdReadDDataOut(List <DTPlcInfo> addrLst)
        {
            List <byte> byteLst    = new List <byte>();
            List <byte> byteLstIn  = new List <byte>();
            List <byte> byteLstOut = new List <byte>();

            byte[] DTCmdSetReadDDataOutTemp;
            byte[] DTCmdReadDDataOutTemp;

            DTCmdSetReadDDataOutTemp = Constant.DTCmdSetReadDDataOut232;
            DTCmdReadDDataOutTemp    = Constant.DTCmdReadDDataOut232;
            if (ConnectMode == Constant.TaiDaConnectMode485)
            {
                DTCmdSetReadDDataOutTemp = Constant.DTCmdSetReadDDataOut485;
                DTCmdReadDDataOutTemp    = Constant.DTCmdReadDDataOut485;
            }
            if (!(addrLst.Count > 0))
            {
                CmdSetReadDDataOut = null;
                CmdSetReadDDataIn  = null;
                CmdReadDDataOut    = null;

                return(-1);
            }

            List <byte> cmdByte = new List <byte>();

            for (int i = 0; i < addrLst.Count; i++)
            {
                int addr_high = (addrLst[i].AbsAddr & 0xFF00) >> 8;
                int addr_low  = addrLst[i].AbsAddr & 0xFF;

                cmdByte.Add((byte)addr_high);
                cmdByte.Add((byte)addr_low);
            }

            int addrcount_high = ((addrLst.Count + 1) & 0xFF00) >> 8;
            int addrcount_low  = (addrLst.Count + 1) & 0xFF;

            int count = (addrLst.Count + 1) * 2;

            //发送设置读取D区命令
            byteLst.Add(0x01);
            byteLst.Add(0x10);
            byteLst.AddRange(DTCmdSetReadDDataOutTemp);


            byteLstIn.Add(0x01);
            byteLstIn.Add(0x10);
            byteLstIn.AddRange(DTCmdSetReadDDataOutTemp);


            byteLstOut.Add(0x01);
            byteLstOut.Add(0x03);
            byteLstOut.AddRange(DTCmdReadDDataOutTemp);

            int addrcount_high0 = ((addrLst.Count) & 0xFF00) >> 8;
            int addrcount_low0  = (addrLst.Count) & 0xFF;

            byteLstOut.Add((byte)addrcount_high0);
            byteLstOut.Add((byte)addrcount_low0);

            byteLst.Add((byte)addrcount_high);
            byteLst.Add((byte)addrcount_low);
            byteLstIn.Add((byte)addrcount_high);
            byteLstIn.Add((byte)addrcount_low);
            byteLst.Add((byte)((addrLst.Count + 1) * 2));

            addrcount_high = ((addrLst.Count) & 0xFF00) >> 8;
            addrcount_low  = (addrLst.Count) & 0xFF;

            byteLst.Add((byte)addrcount_high);
            byteLst.Add((byte)addrcount_low);
            byteLst.AddRange(cmdByte);


            //根据232 还是485来选择
            byteLst.Add(DTPLCPackCmdAndDataUnpack.LRC16_C(byteLst.ToArray()));
            byteLstIn.Add(DTPLCPackCmdAndDataUnpack.LRC16_C(byteLstIn.ToArray()));
            byteLstOut.Add(DTPLCPackCmdAndDataUnpack.LRC16_C(byteLstOut.ToArray()));
            //开始拼接 台达设置读取D区命令
            CmdSetReadDDataOut = byteLst.ToArray();

            CmdSetReadDDataIn = byteLstIn.ToArray();

            CmdReadDDataOut = byteLstOut.ToArray();

            return(0);
        }
Ejemplo n.º 2
0
        public int PackSetCmdReadMDataOut(List <List <DTPlcInfo> > addrLst)
        {
            List <DTPlcInfo> mplcLst = new List <DTPlcInfo>();

            byte[] DTCmdSetReadMDataOutTemp;
            byte[] DTCmdReadMDataOutTemp;
            DTCmdSetReadMDataOutTemp = Constant.DTCmdSetReadMDataOut232;
            DTCmdReadMDataOutTemp    = Constant.DTCmdReadMDataOut232;

            if (ConnectMode == Constant.TaiDaConnectMode485)
            {
                DTCmdSetReadMDataOutTemp = Constant.DTCmdSetReadMDataOut485;
                DTCmdReadMDataOutTemp    = Constant.DTCmdReadMDataOut485;
            }


            for (int i = 0; i < addrLst.Count; i++)
            {
                mplcLst.AddRange(addrLst[i]);
            }

            if (!(mplcLst.Count > 0))
            {
                CmdSetReadMDataOut = null;
                CmdSetReadMDataIn  = null;
                CmdReadMDataOut    = null;

                return(-1);
            }

            List <byte> cmdByte = new List <byte>();

            for (int i = 0; i < mplcLst.Count; i++)
            {
                int addr_high = (mplcLst[i].AbsAddr & 0xFF00) >> 8;
                int addr_low  = mplcLst[i].AbsAddr & 0xFF;
                cmdByte.Add((byte)addr_high);
                cmdByte.Add((byte)addr_low);
            }

            List <byte> byteLst    = new List <byte>();
            List <byte> byteLstIn  = new List <byte>();
            List <byte> byteLstOut = new List <byte>();

            byteLst.Add(0x01);
            byteLst.Add(0x10);

            byteLst.AddRange(DTCmdSetReadMDataOutTemp);

            byteLstIn.Add(0x01);
            byteLstIn.Add(0x10);
            byteLstIn.AddRange(DTCmdSetReadMDataOutTemp);

            byteLstOut.Add(0x01);
            byteLstOut.Add(0x03);

            byteLstOut.AddRange(DTCmdReadMDataOutTemp);


            int addrcount_high = ((mplcLst.Count + 1) & 0xFF00) >> 8;
            int addrcount_low  = (mplcLst.Count + 1) & 0xFF;

            int c = (int)Math.Ceiling((double)mplcLst.Count / 16); //多少个16位的数据 至少是16位
            int addrcount_high0 = ((c) & 0xFF00) >> 8;
            int addrcount_low0  = (c) & 0xFF;

            int count = (mplcLst.Count + 1) * 2;

            byteLst.Add((byte)addrcount_high);
            byteLst.Add((byte)addrcount_low);
            byteLstIn.Add((byte)addrcount_high);
            byteLstIn.Add((byte)addrcount_low);

            byteLstOut.Add((byte)addrcount_high0);
            byteLstOut.Add((byte)addrcount_low0);
            byteLst.Add((byte)((mplcLst.Count + 1) * 2));

            addrcount_high = ((mplcLst.Count) & 0xFF00) >> 8;
            addrcount_low  = (mplcLst.Count) & 0xFF;

            byteLst.Add((byte)addrcount_high);
            byteLst.Add((byte)addrcount_low);

            byteLst.AddRange(cmdByte);

            byteLst.Add(DTPLCPackCmdAndDataUnpack.LRC16_C(byteLst.ToArray()));
            byteLstIn.Add(DTPLCPackCmdAndDataUnpack.LRC16_C(byteLstIn.ToArray()));
            byteLstOut.Add(DTPLCPackCmdAndDataUnpack.LRC16_C(byteLstOut.ToArray()));
            //开始拼接 台达设置读取D区命令
            CmdSetReadMDataOut = byteLst.ToArray();

            CmdSetReadMDataIn = byteLstIn.ToArray();

            CmdReadMDataOut = byteLstOut.ToArray();
            return(0);
        }