Exemplo n.º 1
0
        //----- ISendReceive Implementation -----

        //
        // Summary:
        //     Writes numBytes from the data buffer starting at the specified offset.
        //
        // Parameters:
        //   data:
        //     The output data buffer.
        //
        //   offset:
        //     The zero-based offset in the data buffer to start copying data.
        //
        //   numBytes:
        //     The number of bytes to be written.
        //
        // Returns:
        //     The send status, IO_SUCCESS if all bytes were sent
        //
        public SendReceiveStatus sendBytes(byte[] data, int offset, int numBytes)
        {
            SendReceiveStatus status = SendReceiveStatus.IO_SUCCESS;
            int numSent = 0;

            try
            {
                // Exceptions:
                //   System.ArgumentNullException:
                //     The buffer passed is null.
                //
                //   System.InvalidOperationException:
                //     The port is not open.
                //
                //   System.ArgumentOutOfRangeException:
                //     The offset or numBytes parameters are outside a valid region of the buffer being
                //     passed. Either offset or numBytes is less than zero.
                //
                //   System.ArgumentException:
                //     offset plus numBytes is greater than the length of the buffer.
                //
                //   System.ServiceProcess.TimeoutException:
                //     The operation did not complete before the time-out period ended.

                outPipe.Write(data, offset, numBytes);
                numSent = numBytes; // the entire numBytes is sent. If it cannot be sent an exception is thrown.
            }
            catch (System.ArgumentNullException)
            {
                status = SendReceiveStatus.IO_NULL_BUFFER;
            }
            catch (System.InvalidOperationException)
            {
                status = SendReceiveStatus.IO_PORT_ERROR;
            }
            catch (System.ArgumentOutOfRangeException)
            {
                status = SendReceiveStatus.IO_OUT_OF_RANGE;
            }
            catch (System.ArgumentException)
            {
                status = SendReceiveStatus.IO_OUT_OF_RANGE;
            }
            catch (System.TimeoutException)
            {
                status = SendReceiveStatus.IO_TIMEOUT;
            }
            catch (USBException)
            {
                status = SendReceiveStatus.IO_PIPE_ERROR;
            }
            catch (Exception)
            {
                status = SendReceiveStatus.IO_OTHER_EXCEPTION;
            }

            return(status);
        }
Exemplo n.º 2
0
 //
 //         write data on the OUT endpoint associated to the HID interface
 //
 public void write(List <byte> data)
 {
     foreach (var _ in Enumerable.Range(0, (int)this.packet_size - data.Count))
     {
         data.Add(0);
     }
     Debug.Assert(data.Count == 0x200);
     deviceOut.Write(data.ToArray());
 }
Exemplo n.º 3
0
 /// <summary>
 /// Запись буфера
 /// </summary>
 /// <param name="Buffer">Данные для записи</param>
 protected override void WriteBufferImplement(byte[] Buffer)
 {
     try
     {
         WritePipe.Write(Buffer);
     }
     catch (USBException usbExc)
     {
         OnDisconnected();
         throw new AppiConnectoinException("Ошибка при записи буфера АППИ в USB", usbExc);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Refreshes the LED buffer/state on the controller
 /// </summary>
 public void RefreshLEDState()
 {
     writer.Write(rawLEDData);
 }