Наследование: System.ApplicationException
        /// <summary>
        /// Parse data returned from a read report
        /// </summary>
        /// <param name="buff">Data buffer</param>
        private void ParseReadData(byte[] buff)
        {
            if ((buff[3] & 0x08) != 0)
            {
                Exception ex = new WiimoteException("Error reading data from Wiimote: Bytes do not exist.");
                WiimoteException?.Invoke(this, new WiimoteExceptionEventArgs(ex));
                return;
            }

            if ((buff[3] & 0x07) != 0)
            {
                Debug.WriteLine("*** read from write-only");
                LastReadStatus = LastReadStatus.ReadFromWriteOnlyMemory;
                mReadDone.Set();
                return;
            }

            // get our size and offset from the report
            int size   = (buff[3] >> 4) + 1;
            int offset = (buff[4] << 8 | buff[5]);

            // add it to the buffer
            Array.Copy(buff, 6, mReadBuff, offset - mAddress, size);

            // if we've read it all, set the event
            if (mAddress + mSize == offset + size)
            {
                mReadDone.Set();
            }

            LastReadStatus = LastReadStatus.Success;
        }
Пример #2
0
        /// <summary>Parse data returned from a read report.</summary>
        /// <param name="buff">Data buffer</param>
        private void ParseReadData(byte[] buff)
        {
            if ((buff[3] & 0x08) != 0)
            {
                Exception ex = new WiimoteException(this, "Error reading data from Wiimote: Bytes do not exist.");
                RaiseWiimoteException(ex);
                return;
            }

            if ((buff[3] & 0x07) != 0)
            {
                Debug.WriteLine("*** read from write-only: " + readAddress.ToString("X8"));
                //LastReadStatus = LastReadStatus.ReadFromWriteOnlyMemory;
                //mReadDone.Set();
                //Respond(OutputReport.ReadMemory, null);
                return;
            }
            else if ((buff[3] & 0x0F) != 0)
            {
                int       error = buff[3] & 0x0F;
                Exception ex    = new WiimoteException(this, $"{this} Read Error: {error:X1}");
                RaiseWiimoteException(ex);
                return;
            }

            // get our size and offset from the report
            int size   = (buff[3] >> 4) + 1;
            int offset = (buff[4] << 8 | buff[5]);

            /*int readAddress = request.ReadAddress;
             * int readSize = request.ReadSize;
             * byte[] readBuffer = request.ReadBuffer;*/

            if (readAddress > offset)
            {
                Exception ex = new WiimoteException(this, $"Out of range address or offset: {readAddress:X4} {offset:X4}");
                RaiseWiimoteException(ex);
                return;
            }
            // add it to the buffer
            Array.Copy(buff, 6, readBuff, offset - readAddress, size);

            // if we've read it all, set the event
            if (readAddress + readSize == offset + size)
            {
                readDone.Set();
            }
            //Respond(OutputReport.ReadMemory, readBuffer);

            //LastReadStatus = LastReadStatus.Success;
        }
Пример #3
0
 /// <summary>
 /// </summary>
 private void ThrowException(Exception ex)
 {
     Disconnect();
     WiimoteException?.Invoke(this, new WiimoteExceptionEventArgs(ex));
 }
        // Called by Wiimote

        private void RaiseWiimoteException(Exception ex)
        {
            WiimoteManager.RaiseWiimoteException(this, ex);
            WiimoteException?.Invoke(this, new WiimoteExceptionEventArgs(this, ex));
        }
Пример #5
0
        // Called by Wiimote

        internal static void RaiseWiimoteException(Wiimote wiimote, Exception ex)
        {
            Debug.WriteLine($"{wiimote} Exception: {ex}");
            WiimoteException?.Invoke(null, new WiimoteExceptionEventArgs(wiimote, ex));
        }