Beispiel #1
0
        //ArraySegment

        public static ArraySegment <byte> GetResAckMessage(MQDataInfo mQDataInfo)
        {
            byte[] msg = new byte[16];
            MQTools.CharToByte(mQDataInfo.Head, msg);
            msg[2] = mQDataInfo.PID;
            msg[3] = (byte)MessageType.ResAck;
            MQTools.ConvertIntToByteArray(mQDataInfo.MID, msg, 4);
            MQTools.ConvertUShortToByteArray(mQDataInfo.Code, msg, 8);
            MQTools.ConvertUShortToByteArray(mQDataInfo.Reserved, msg, 10);

            MQTools.CharToByte(mQDataInfo.End, msg, 14);

            return(new ArraySegment <byte>(msg));
        }
Beispiel #2
0
        public static byte[] GetSendMessageByte(MQDataInfo mQDataInfo)
        {
            byte[] msg = new byte[14 + mQDataInfo.Length + 2];
            MQTools.CharToByte(mQDataInfo.Head, msg);
            msg[2] = mQDataInfo.PID;
            msg[3] = mQDataInfo.Type;
            MQTools.ConvertIntToByteArray(mQDataInfo.MID, msg, 4);
            MQTools.ConvertUShortToByteArray(mQDataInfo.Code, msg, 8);
            MQTools.ConvertUShortToByteArray(mQDataInfo.Reserved, msg, 10);
            MQTools.ConvertUShortToByteArray((ushort)mQDataInfo.Length, msg, 12);
            Array.Copy(mQDataInfo.Body, 0, msg, 14, mQDataInfo.Length);

            MQTools.CharToByte(mQDataInfo.End, msg, mQDataInfo.Length + 14);

            return(msg);
        }
Beispiel #3
0
        public static byte[] GetSendMessageByte(ushort mqCode, byte[] data, int mqId, byte sendPid, byte mqType, ushort Reserved, char head, char end)
        {
            byte[] msg = new byte[14 + data.Length + 2];
            MQTools.CharToByte(head, msg);
            msg[2] = sendPid;
            msg[3] = mqType;
            MQTools.ConvertIntToByteArray(mqId, msg, 4);
            MQTools.ConvertUShortToByteArray(mqCode, msg, 8);
            MQTools.ConvertUShortToByteArray(Reserved, msg, 10);
            MQTools.ConvertUShortToByteArray((ushort)data.Length, msg, 12);
            Array.Copy(data, 0, msg, 14, data.Length);
            //校验
            //msg[data.Length + 14] = 0;

            MQTools.CharToByte(end, msg, data.Length + 14);

            return(msg);
        }
Beispiel #4
0
        public bool GetSendByte(out byte[] buffer)
        {
            buffer = new byte[14 + Length + 2];
            MQTools.CharToByte(Head, buffer);
            buffer[2] = PID;
            buffer[3] = Type;
            MQTools.ConvertIntToByteArray(MID, buffer, 4);
            MQTools.ConvertUShortToByteArray(Code, buffer, 8);
            MQTools.ConvertUShortToByteArray(Reserved, buffer, 10);
            MQTools.ConvertUShortToByteArray((ushort)Length, buffer, 12);

            if (Length > 0)
            {
                Array.Copy(Body, 0, buffer, 14, Length);
            }
            MQTools.CharToByte(End, buffer, Length + 14);

            return(true);
        }