示例#1
0
        private LCDPacket Send(byte type, byte dataLength, byte[] data)
        {
            ushort crc;

            if ((null == data && dataLength != 0) || dataLength > data.Length)
            {
                throw new ArgumentException("bad data sent to Send");
            }

            packetXMitBuffer[0] = type;
            packetXMitBuffer[1] = dataLength;
            if (0 != dataLength)
            {
                Array.Copy(data, 0, packetXMitBuffer, 2, dataLength);
            }

            crc = CRCGenerator.GenerateCRC(packetXMitBuffer, dataLength + 2, CRC_SEED);
            packetXMitBuffer[2 + dataLength + 1] = (byte)(crc >> 8);
            packetXMitBuffer[2 + dataLength]     = (byte)crc;
            lock (responseSignal)
            {
                responsePacket = null;
                // comPort
                com.Write(packetXMitBuffer, 0, dataLength + 4);
                if (Monitor.Wait(responseSignal, MAX_RESPONSE_TIME))
                {
                    return(responsePacket);
                }
            }

            return(null);
        }
示例#2
0
        private bool SendReturnBool(byte type, byte dataLength, byte[] data)
        {
            LCDPacket packet = Send(type, dataLength, data);

            if (null != packet)
            {
                return(type == (packet.Type & 0x0F) && LCDPacket.LCDPacketType.NORMAL_RESPONSE == responsePacket.PacketType);
            }
            else
            {
                return(false);
            }
        }
示例#3
0
        private byte[] SendReturnData(byte type, byte dataLength, byte[] data)
        {
            LCDPacket packet = Send(type, dataLength, data);

            if (null != packet)
            {
                return(packet.Data);
            }
            else
            {
                return(null);
            }
        }