Пример #1
0
        private async Task WriteRequestAsync(byte[] message)
        {
            var packetIndex = 0;

            byte[] data = null;
            using (var memory = new MemoryStream(message))
            {
                do
                {
                    data = GetRequestDataPacket(memory, packetIndex);
                    packetIndex++;
                    await HIDDevice.WriteAsync(data);
                } while (memory.Position != memory.Length);
            }
        }
Пример #2
0
        private async Task WriteRequestAsync(object request)
        {
            var byteArray = Helpers.ProtoBufSerialize(request);
            var size      = byteArray.Length;

            //await HIDDevice.WriteAsync(new byte[1]);

            var id   = (int)GetEnumValue("MessageType" + request.GetType().Name);
            var data = new byte[size + 1024]; // 32768);

            data[0] = (byte)'#';
            data[1] = (byte)'#';
            data[2] = (byte)((id >> 8) & 0xFF);
            data[3] = (byte)(id & 0xFF);
            data[4] = (byte)((size >> 24) & 0xFF);
            data[5] = (byte)((size >> 16) & 0xFF);
            data[6] = (byte)((size >> 8) & 0xFF);
            data[7] = (byte)(size & 0xFF);
            byteArray.CopyTo(data, 8);

            var position = size + 8;

            while (position % 63 > 0)
            {
                data[position] = 0;
                position++;
            }

            for (var i = 0; i < (position / 63); i++)
            {
                var chunk = new byte[64];
                chunk[0] = (byte)'?';

                for (var x = 0; x < 63; x++)
                {
                    chunk[x + 1] = data[(i * 63) + x];
                }

                await HIDDevice.WriteAsync(chunk);
            }

            lastRequest = request;
        }