Пример #1
0
        /// <summary>
        /// 封装好完整的发送数据帧
        /// </summary>
        /// <param name="node">从机地址</param>
        /// <param name="cmd">指令信息</param>
        /// <returns></returns>
        private static byte[] SendPduPack(int node, MBCmd cmd)
        {
            byte[] res = null;
            switch (cmd.func)
            {
            case MB_READ_COILS:
            case MB_READ_DISCRETE:
            case MB_READ_HOLD_REG:
            case MB_READ_INPUT_REG:
            case MB_WRITE_SINGLE_COIL:
            case MB_WRITE_SINGLE_REG:
                res = SendTrainCyclostyle(node, null, cmd.addr, cmd.len, (byte)cmd.func); break;

            case MB_WRITE_MULTIPLE_COILS:
            case MB_WRITE_MULTIPLE_REGS:
                byte[] data = GetAddressValues(cmd.addr, (byte)cmd.func, cmd.len);
                res = SendTrainCyclostyle(node, data, cmd.addr, cmd.len, (byte)cmd.func); break;
            }
            return(res);
        }
Пример #2
0
        /// <summary>
        /// 封装发送数据帧
        /// </summary>
        /// <param name="node">从机地址</param>
        /// <param name="cmd">指令信息</param>
        /// <returns></returns>
        private static byte[] SendPduPack(int node, MBCmd cmd)
        {
            byte[] res = null;
            switch (cmd.stat)
            {
                case MB_READ_COILS:
                case MB_READ_DISCRETE:
                case MB_READ_HOLD_REG:
                case MB_READ_INPUT_REG:
                case MB_WRITE_SINGLE_COIL:
                case MB_WRITE_SINGLE_REG:
                    res = SendTrainCyclostyle(node, null, cmd.addr, cmd.len, (byte)cmd.stat); break;

                case MB_WRITE_MULTIPLE_COILS:
                case MB_WRITE_MULTIPLE_REGS:
                    byte[] data = GetAddressValues(cmd.addr, (byte)cmd.stat, cmd.len);
                    res = SendTrainCyclostyle(node, data, cmd.addr, cmd.len, (byte)cmd.stat); break;
            }
            return res;
        }