Beispiel #1
0
 public int Write(Packet packet, byte[] payload)
 {
     byte[] header_bytes = Protocol.StructureToByteArray<Packet>(packet);
     byte[] packet_bytes = new byte[header_bytes.Length + payload.Length];
     Array.Copy(header_bytes,packet_bytes, header_bytes.Length);
     Array.Copy(payload,0,packet_bytes,header_bytes.Length,payload.Length);
     return Write(packet_bytes);
 }
Beispiel #2
0
 public int Write(Packet packet)
 {
     byte[] buffer = Protocol.StructureToByteArray<Packet>(packet);
     return Write(buffer);
 }
Beispiel #3
0
        public int Read(out Packet packet, out byte[] packet_data)
        {
            int packet_header_size = Marshal.SizeOf(typeof(Packet));
            int packet_size = packet_header_size+1024;
            byte[] buffer = new byte[packet_size];
            ErrorCode error_code;
            int bytes_read;

            error_code = Reader.Read(buffer,0,buffer.Length,100,out bytes_read);

            if ( error_code != ErrorCode.None )
                throw new Exception(UsbDevice.LastErrorString);

            if ( bytes_read == 0 )
                throw new Exception(UsbDevice.LastErrorString);

            byte[] packet_header_bytes = new byte[packet_header_size];

            Array.Copy(buffer,packet_header_bytes,packet_header_size);

            packet = Protocol.ByteArrayToStructure<Packet>(packet_header_bytes);

            packet_data = new byte[packet.size];

            Array.Copy(buffer,packet_header_size,packet_data,0,packet.size);

            return bytes_read;
        }