コード例 #1
1
        public BigRedButtonState? QueryState()
        {
            var statusQuery = new HidReport(1) {Data = StatusReport};

            var isQueryWritten = device.WriteReport(statusQuery);

            if (!isQueryWritten)
            {
                return null;
            }

            var readReport = device.ReadReport(100);

            var readData = readReport.Data;

            if (readReport.ReadStatus != HidDeviceData.ReadStatus.Success)
            {
                return null;
            }

            var statusByte = readData[0];

            Debug.WriteLine(Convert.ToString(readData[0],2));

            var buttonIsPressed = (statusByte & (1 << 0)) == 0;
            var lidIsOpen = (statusByte & (1 << 1)) != 0;

            return new BigRedButtonState(buttonIsPressed, lidIsOpen);
        }
コード例 #2
0
ファイル: HidDevice.cs プロジェクト: wdatkinson/KFDtool
        public void WriteReport(HidReport report, WriteCallback callback)
        {
            WriteReportDelegate writeReportDelegate = WriteReport;
            HidAsyncState       @object             = new HidAsyncState(writeReportDelegate, callback);

            writeReportDelegate.BeginInvoke(report, EndWriteReport, @object);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: Erguotou/HidLibrary
        private static void OnReport(HidReport report)
        {
            if (_attached == false) { return; }

            if (report.Data.Length >= 4)
            {
                var message = MessageFactory.CreateMessage(_currentProductId, report.Data);
                if (message.Depress) { KeyDepressed(); }
                else if (message.MultiplePressed == false)
                {
                    if (message.UpPressed) { KeyPressed(1); }
                    if (message.DownPressed) { KeyPressed(2); }
                    if (message.LeftPressed) { KeyPressed(3); }
                    if (message.RightPressed) { KeyPressed(4); }
                    if (message.Button1Pressed) { KeyPressed(5); }
                    if (message.Button2Pressed) { KeyPressed(6); }
                    if (message.Button3Pressed) { KeyPressed(7); }
                    if (message.Button4Pressed) { KeyPressed(8); }
                    if (message.Button5Pressed) { KeyPressed(9); }
                    if (message.Button6Pressed) { KeyPressed(10); }
                    if (message.Button7Pressed) { KeyPressed(11); }
                    if (message.Button8Pressed) { KeyPressed(12); }
                    if (message.Button9Pressed) { KeyPressed(13); }
                    if (message.Button10Pressed) { KeyPressed(14); }
                }
            }

            _device.ReadReport(OnReport);
        }
コード例 #4
0
        private void OnReport(HidReport report)
        {
            if (_attached == false) { return; }

            if (report.Data.Length >= 4)
            {
                var message = MessageFactory.CreateMessage(_currentProductId, report.Data);
                OnButtonEvent.Invoke(message);
                //if (message.Depress) { KeyDepressed(); }
                //else
                //{
                //    OnButtonEvent.Invoke(message);

                //    //if (message.UpPressed) { KeyPressed("Up"); }
                //    //if (message.DownPressed) { KeyPressed("Down"); }
                //    //if (message.LeftPressed) { KeyPressed("Left"); }
                //    //if (message.RightPressed) { KeyPressed("Right"); }
                //    //if (message.Button1Pressed) { KeyPressed("1"); }
                //    //if (message.Button2Pressed) { KeyPressed("2"); }
                //    //if (message.ButtonAPressed) { KeyPressed("A"); }
                //    //if (message.ButtonBPressed) { KeyPressed("B"); }
                //    //if (message.ButtonPlusPressed) { KeyPressed("Plus"); }
                //    //if (message.ButtonMinusPressed) { KeyPressed("Minus"); }
                //    //if (message.ButtonRedPressed) { KeyPressed("Red"); }
                //    //if (message.ButtonYellowPressed) { KeyPressed("Yellow"); }
                //    //if (message.ButtonBluePressed) { KeyPressed("Blue"); }
                //    //if (message.ButtonGreenPressed) { KeyPressed("Green"); }
                //    //if (message.ButtonPedalPressed) { KeyPressed("Pedal"); }
                //    //_press = true;
                //}
            }

            _device.ReadReport(OnReport);
        }
コード例 #5
0
ファイル: HidDevice.cs プロジェクト: biletnam/homeControl
        public void WriteReport(HidReport report, WriteCallback callback, int timeout)
        {
            var writeReportDelegate = new WriteReportDelegate(WriteReport);
            var asyncState          = new HidAsyncState(writeReportDelegate, callback);

            writeReportDelegate.BeginInvoke(report, timeout, EndWriteReport, asyncState);
        }
コード例 #6
0
ファイル: HidDevice.cs プロジェクト: wdatkinson/KFDtool
        protected static void EndReadReport(IAsyncResult ar)
        {
            HidAsyncState      hidAsyncState      = (HidAsyncState)ar.AsyncState;
            ReadReportDelegate readReportDelegate = (ReadReportDelegate)hidAsyncState.CallerDelegate;
            ReadReportCallback readReportCallback = (ReadReportCallback)hidAsyncState.CallbackDelegate;
            HidReport          report             = readReportDelegate.EndInvoke(ar);

            readReportCallback?.Invoke(report);
        }
コード例 #7
0
ファイル: AdapterManager.cs プロジェクト: hawku/G25Adapter
 public void OnReport(HidReport report)
 {
     if (report.ReportId == 4) {
         WriteLog("Report! " + report.Data[1] + ", " + report.Data[2] + ",  " + report.Data[5] + ", " + report.Data[10]);
     }
     if (_running) {
         _device.ReadReport(OnReport);
     }
 }
コード例 #8
0
ファイル: Program.cs プロジェクト: Erguotou/HidLibrary
        private static void OnReport(HidReport report)
        {
            if (!_device.IsConnected) { return; }

            var cardData = new Data(report.Data);

            Console.WriteLine(!cardData.Error ? Encoding.ASCII.GetString(cardData.CardData) : cardData.ErrorMessage);

            _device.ReadReport(OnReport);
        }
コード例 #9
0
        public async Task <bool> WriteReportAsync(HidReport report, int timeout = 0)
        {
            var writeReportDelegate = new WriteReportDelegate(WriteReport);

#if NET20 || NET35
            return(await Task <bool> .Factory.StartNew(() => writeReportDelegate.Invoke(report, timeout)));
#else
            return(await Task <bool> .Factory.FromAsync(writeReportDelegate.BeginInvoke, writeReportDelegate.EndInvoke, report, timeout, null));
#endif
        }
コード例 #10
0
 private void ReadReport(HidReport report)
 {
     if (onDataReceived != null && report.ReadStatus == HidDeviceData.ReadStatus.Success)
     {
         int length = report.Data[0];
         byte[] data = new byte[length];
         Array.Copy(report.Data, 1, data, 0, length);
         onDataReceived(data);
     }
     dev.ReadReport(ReadReport);
 }
コード例 #11
0
 /// <summary>
 /// Handle data transfers on the control channel.  This method places data on the control channel for devices
 /// that do not support the interupt transfers
 /// </summary>
 /// <param name="report">The outbound HID report</param>
 /// <returns>The result of the tranfer request: true if successful otherwise false</returns>
 ///
 public bool WriteReportSync(HidReport report)
 {
     if (null != report)
     {
         byte[] buffer = report.GetBytes();
         return(NativeMethods.HidD_SetOutputReport(WriteHandle, buffer, buffer.Length));
     }
     else
     {
         throw new ArgumentException("The output report is null, it must be allocated before you call this method", "report");
     }
 }
コード例 #12
0
ファイル: ChronManager.cs プロジェクト: bangonkali/Chron
 public void ChronOverride(byte deviceId, byte deviceState)
 {
     if (connectedToDriver)
     {
         byte[] data = new byte[63];
         data[0] = (byte)0x00;
         data[1] = (byte)12; // mao ni ang 0 sa PIC
         data[2] = deviceId; // 1
         data[3] = deviceState; // 2
         HidReport report = new HidReport(63, new HidDeviceData(data, HidDeviceData.ReadStatus.Success)); //7
         device.WriteReport(report);
         //ReceiveReport(report);
     }
 }
コード例 #13
0
        private void OnReportReceived(HidReport report)
        {
            if (Device.IsConnected == false)
            {
                return;
            }

            if (report.Data.Length == JoystickDataParser.DataSize)
            {
                ReportReceived(JoystickDataParser.Parse(report.Data));
            }

            Device.ReadReport(OnReportReceived);
        }
コード例 #14
0
ファイル: HidDevice.cs プロジェクト: trigrass2/bbauv
 public void WriteFeatureReport(HidReport report)
 {
     if (dev.OpenDeviceForWrite())
     {
         if (report.Length == GetReportLength(HidReportType.Feature))
         {
             if (!NativeApi.HidD_SetFeature(dev.Handle, report.Bytes, report.Length))
             {
                 throw new Exception("SetFeatureReport: " + Marshal.GetLastWin32Error().ToString());
             }
         }
     }
     else
     {
         throw new Exception("Unable to open device for Write");
     }
 }
コード例 #15
0
        public bool write(byte[] data)
        {
            int count = 0; int size = data.Length;
            if (!dev.IsConnected)
                return false;

            while (size > 0)
            {
                int byteToWrite = Math.Min(maxSize - 2, size); 
                HidReport rp = new HidReport(byteToWrite + 2);
                rp.ReportId = 2;
                Array.Copy(data, count, rp.Data, 1, byteToWrite);
                rp.Data[0] = (byte)byteToWrite;
                size -= byteToWrite;
                count += byteToWrite;
                bool rv;
                rv = dev.WriteReport(rp);
            }
            
            return true;
        }
コード例 #16
0
ファイル: Report.cs プロジェクト: Erguotou/HidLibrary
        public Report(HidReport hidReport)
        {
            _status = hidReport.ReadStatus;
            ReportId = hidReport.ReportId;
            Exists = hidReport.Exists;

            if (hidReport.Data.Length > 0) Length = hidReport.Data[0];
            if (hidReport.Data.Length > 1) AimSymbologyId0 = hidReport.Data[1];
            if (hidReport.Data.Length > 2) AimSymbologyId1 = hidReport.Data[2];
            if (hidReport.Data.Length > 3) AimSymbologyId2 = hidReport.Data[3];

            if (hidReport.Data.Length > Length + 3)
            {
                Array.Resize(ref _data, Length);
                Array.Copy(hidReport.Data, 4, _data, 0, Length);
            }

            if (hidReport.Data.Length > 60) HhpSymbologyId = hidReport.Data[60];
            if (hidReport.Data.Length > 61) Reserved = hidReport.Data[61];
            if (hidReport.Data.Length > 62) MoreData = hidReport.Data[62] == 1;
        }
コード例 #17
0
ファイル: ChronManager.cs プロジェクト: bangonkali/Chron
        public void GetCronData()
        {
            if (connectedToDriver)
            {
                byte[] data = new byte[2];
                data[0] = 0x00;
                data[1] = 0x01;
                HidReport report = new HidReport(2, new HidDeviceData(data, HidDeviceData.ReadStatus.Success));
                device.WriteReport(report);
                ChronState state = new ChronState();
                if (report.Data.Length > 2)
                {
                    if (report.Data[0] == 0 && report.Data[1] == 2)
                    {
                        state.Diagnostics = "Received Chron Entry " + cron_entries_received + ": ";
                        state.Read_MoreToParse = true;
                        cron_entries_received++;
                        //this.GetCronDataContinuation();
                    }

                    if (report.Data[0] == 0 && report.Data[1] == 3)
                    {
                        state.Diagnostics = "Chron Entry Comms Ended: ";
                        cron_entries_received = 0;
                    }

                    if (debugPrintRawMessages)
                    {
                        for (int i = 0; i < report.Data.Length; i++)
                        {
                            state.Diagnostics += report.Data[i] + ", ";
                        }

                        System.Diagnostics.Debug.WriteLine(state.Diagnostics);
                    }

                    this.OnEntryReceived(state);
                }
            }
        }
コード例 #18
0
ファイル: Form1.cs プロジェクト: bdurrani/HidLibrary
        private void OnReport(HidReport report)
        {
            if (!_isAttached)
             {
            return;
             }

             var data = report.Data;
             PrintOutputLine(string.Format("recv {0} bytes:", data.Length));

             string outputString = string.Empty;
             for (int i = 0; i < data.Length; i++)
             {
            outputString += string.Format("{0:X2} ", data[i]);
            if (i % 16 == 15 && i < data.Length)
            {
               PrintOutputLine(outputString);
               outputString = string.Empty;
            }
             }
             PrintOutputLine("\n");

             _device.ReadReport(OnReport);
        }
コード例 #19
0
ファイル: HidDevice.cs プロジェクト: trigrass2/bbauv
 public void WriteOutPipeReport(HidReport report)
 {
     if (dev.OpenDeviceForWrite())
     {
         if (report.Length == GetReportLength(HidReportType.Output))
         {
             using (FileStream stream = new FileStream(dev.Handle, FileAccess.Write))
             {
                 try
                 {
                     stream.Write(report.Bytes, 0, report.Bytes.Length);
                 }
                 catch (Exception e)
                 {
                     throw new Exception("Write to outpipe failed: " + e.Message);
                 }
             }
         }
     }
     else
     {
         throw new Exception("Unable to open device for Write");
     }
 }
コード例 #20
0
ファイル: ChronManager.cs プロジェクト: bangonkali/Chron
        private void OnReport(HidReport report)
        {
            ChronState state = new ChronState();

            if (attached == false) { return; }

            if (report.Data.Length > 2)
            {
                if (report.Data[0] == 0 && report.Data[1] == 0)
                {
                    state.Diagnostics = "Received Time and Data Reset " + cron_entries_received + ": ";
                    state.Read_MoreToParse = true;
                    cron_entries_received++;
                }

                if (report.Data[0] == 0 && report.Data[1] == 2)
                {
                    state.Diagnostics = "Received Chron Entry " + cron_entries_received + ": ";
                    state.Read_MoreToParse = true;
                    cron_entries_received++;
                    this.GetCronDataContinuation();
                }

                if (report.Data[0] == 0 && report.Data[1] == 3)
                {
                    state.Diagnostics = "Chron Entry Comms Ended: ";
                    cron_entries_received = 0;
                }

                if (report.Data[0] == 0 && report.Data[1] == 6)
                {
                    state.Diagnostics = "Written Chron Entry " + cron_entries_written + ": ";
                    state.Read_MoreToParse = true;
                    cron_entries_written++;
                    this.WriteCronDataContinuation();
                }

                if (report.Data[0] == 0 && report.Data[1] == 5)
                {
                    state.Diagnostics = "Chron Write Comms Ended: ";
                    cron_entries_written = 0;
                }

                // Override Control Reply
                if (report.Data[0] == 0 && report.Data[1] == 13)
                {
                    state.Diagnostics = "Override Control Response: ";
                }

                if (debugPrintRawMessages)
                {
                    for (int i = 0; i < report.Data.Length; i++)
                    {
                        state.Diagnostics += report.Data[i] + ", ";
                    }

                    byte[] data = new byte[9];
                    //for (int i = 4; i < 11; i++)
                    //{
                    //	data[i] = report.Data[i];
                    //}

                    state.SetData(data);

                    System.Diagnostics.Debug.WriteLine(state.Diagnostics);
                }

                this.OnEntryReceived(state);
            }

            device.ReadReport(OnReport);
        }
コード例 #21
0
ファイル: Main.cs プロジェクト: ArturoGurrola/HidLibrary
 private void ReadProcess(HidReport report)
 {
     BeginInvoke(new ReadHandlerDelegate(ReadHandler), new object[] { report });
 }
コード例 #22
0
ファイル: ChronManager.cs プロジェクト: bangonkali/Chron
        private void ReceiveReport(HidReport report)
        {
            ChronState state = new ChronState();
            if (report.Data.Length > 2)
            {
                if (report.Data[0] == 0 && report.Data[1] == 2)
                {
                    state.Diagnostics = "Received Chron Entry " + cron_entries_received + ": ";
                    state.Read_MoreToParse = true;
                    cron_entries_received++;
                    //this.GetCronDataContinuation();
                }

                if (report.Data[0] == 0 && report.Data[1] == 3)
                {
                    state.Diagnostics = "Chron Entry Comms Ended: ";
                    cron_entries_received = 0;
                }

                if (debugPrintRawMessages)
                {
                    for (int i = 0; i < report.Data.Length; i++)
                    {
                        state.Diagnostics += report.Data[i] + ", ";
                    }

                    System.Diagnostics.Debug.WriteLine(state.Diagnostics);
                }

                this.OnEntryReceived(state);
            }
        }
コード例 #23
0
ファイル: SharpUploader.cs プロジェクト: macaba/TeensySharp
        private static HidReport PrepareReport(int addr, byte[] data, BoardDefinition BoardDef)
        {
            var report = new HidReport(BoardDef.BlockSize + BoardDef.DataOffset + 1);
            report.ReportId = 0;

            // Copy address bytes into report. Use function stored in board definition
            BoardDef.AddrCopy(report.Data, BitConverter.GetBytes(addr));

            // Copy datablock into report
            data.CopyTo(report.Data, BoardDef.DataOffset);

            return report;
        }
コード例 #24
0
ファイル: Main.cs プロジェクト: ArturoGurrola/HidLibrary
 private void ReadHandler(HidReport report)
 {
     Output.Clear();
     Output.AppendText(System.Text.Encoding.ASCII.GetString(report.Data));
 }
コード例 #25
0
		public override Boolean GetInfoBlock (byte id, out byte[] data)
		{
			if (id == 2 || id == 3) {
				if (connectedToDriver && device.ReadFeatureData (id, out data))
				{
                    HidReport report = new HidReport(33, new HidDeviceData(data, HidDeviceData.ReadStatus.Success));
                    data = report.Data;
					return true;
				}
				else
				{
					data = new byte[0];
					return false;
				}
			} else {
				throw new Exception("Invalid info block id");
			}
		}
コード例 #26
0
ファイル: Form1.cs プロジェクト: bdurrani/HidLibrary
        private void sendButton_Click(object sender, EventArgs e)
        {
            const int size = 64;
             var data = new byte[size];
             byte result;
             if (byte.TryParse(valueTextBox.Text, out result))
             {
            data[1] = result;
             }
             else
             {
            PrintOutputLine("Invalid value, expecting byte value");
            return;
             }

             var report = new HidReport(64, new HidDeviceData(data, HidDeviceData.ReadStatus.Success));
             var status = _device.WriteReport(report);
             return;
        }
コード例 #27
0
ファイル: HidDevice.cs プロジェクト: GotenXiao/blink1
 public void WriteReport(HidReport report, WriteCallback callback)
 {
     var writeReportDelegate = new WriteReportDelegate(WriteReport);
     var asyncState = new HidAsyncState(writeReportDelegate, callback);
     writeReportDelegate.BeginInvoke(report, EndWriteReport, asyncState);
 }
コード例 #28
0
ファイル: HidDevice.cs プロジェクト: GotenXiao/blink1
 public bool WriteReport(HidReport report, int timeout)
 {
     return Write(report.GetBytes(), timeout);
 }
コード例 #29
0
        private void ReadReportCallback(HidReport report)
        {
            Log.Debug("Got a ReadReportCallback of length {0}", report.Data.Length);

            _device.ReadReport(ReadReportCallback);

            if (DataReceived == null)
                return;

            var data = report.GetBytes();
            var dataString = _parser.CurrentParser.InterpretPacket(data);
            var args = new DataReceivedEventArgs(dataString);
            DataReceived(this, args);
        }
コード例 #30
0
ファイル: Scanner.cs プロジェクト: Erguotou/HidLibrary
	    private void ReadReport(HidReport report)
	    {
		    var scannerReport = new Report(report);
            var data = new byte[] { };
		    var currentPosition = 0;
		    var readRequired = false;

		    if (scannerReport.Length > 0 & scannerReport.ReadStatus == HidDeviceData.ReadStatus.Success) 
            {
			    do 
                {
				    if (scannerReport.MoreData && readRequired) scannerReport = new Report(_scanner.ReadReport());
				    else readRequired = true;

                    if (!scannerReport.Exists) continue;

                    Array.Resize(ref data, data.GetUpperBound(0) + scannerReport.Data.Length + 1);
                    Array.Copy(scannerReport.Data, 0, data, currentPosition, scannerReport.Data.Length);
                    currentPosition += scannerReport.Data.Length;

                } while (scannerReport.MoreData && scannerReport.Exists);

			    if (IsListening && data.Length > 0 && DataRecieved != null) DataRecieved(data);
		    }

		    if (scannerReport.ReadStatus != HidDeviceData.ReadStatus.NotConnected) _scanner.ReadReport(ReadReport);
            else _isReading = 0;
	    }
コード例 #31
0
        private void OnReport(HidReport report)
        {
            if (attached == false) { return; }

				/*
            if (report.Data.Length >= 6)
            {
                PowerMateState state = ParseState(report.Data);
                if (!state.IsValid)
                {
                    System.Diagnostics.Debug.WriteLine("Invalid PowerMate state");
                }
                else
                {
                    GenerateEvents(state);

                    if (debugPrintRawMessages)
                    {
                        System.Diagnostics.Debug.Write("PowerMate raw data: ");
                        for (int i = 0; i < report.Data.Length; i++)
                        {
                            System.Diagnostics.Debug.Write(String.Format("{0:000} ", report.Data[i]));
                        }
                        System.Diagnostics.Debug.WriteLine("");
                    }
                }
            }
*/

            //device.ReadReport(OnReport);
        }
コード例 #32
0
ファイル: HidDevice.cs プロジェクト: biletnam/homeControl
 public bool WriteReport(HidReport report, int timeout)
 {
     return(Write(report.GetBytes(), timeout));
 }
コード例 #33
0
        public override void SetLedColor(byte r, byte g, byte b)
        {
            if (connectedToDriver)
            {
                byte [] data = new byte[4];
                data[0] = 1;
                data[1] = r;
                data[2] = g;
                data[3] = b;

                HidReport report = new HidReport(4, new HidDeviceData(data, HidDeviceData.ReadStatus.Success));
                device.WriteFeatureData(data);
            }
        }
コード例 #34
0
ファイル: HidDevice.cs プロジェクト: GotenXiao/blink1
 public bool WriteReport(HidReport report)
 {
     return WriteReport(report, 0);
 }
コード例 #35
0
ファイル: Main.cs プロジェクト: mabe-at/PowerMateMIDI
        private void ReadHandler(HidReport report)
        {
            Output.Clear();
            Output.AppendText(String.Join(" ", report.Data.Select(d => d.ToString("X2"))));

            _deviceList[Devices.SelectedIndex].ReadReport(ReadProcess);
        }
コード例 #36
0
ファイル: HidDevice.cs プロジェクト: biletnam/homeControl
 public bool WriteReport(HidReport report)
 {
     return(WriteReport(report, 0));
 }
コード例 #37
0
		protected override void SetInfoBlock (byte id, byte[] data)
		{
			if (id == 2 || id == 3) {
				if (data.Length > 32)
				{
		            Array.Resize(ref data, 32);
				}
				else if (data.Length < 32)
				{
					int size = data.Length;

		            Array.Resize(ref data, 32);

					//pad with zeros
					for (int i = size; i < 32; i++)
					{
						data[i] = 0;
					}
				}

                Array.Resize(ref data, 33);


                for (int i = 32; i >0; i--)
                {
                    data[i] = data[i-1];
				}

                data[0] = id;

                HidReport report = new HidReport(33, new HidDeviceData(data, HidDeviceData.ReadStatus.Success));
                device.WriteFeatureData(data);
			} else {
				throw new Exception("Invalid info block id");
			}
		}
コード例 #38
0
ファイル: HidDevice.cs プロジェクト: biletnam/homeControl
 public void WriteReport(HidReport report, WriteCallback callback)
 {
     WriteReport(report, callback, 0);
 }
コード例 #39
0
ファイル: HidDevice.cs プロジェクト: macaba/HidLibrary
 public void WriteReport(HidReport report, WriteCallback callback)
 {
     WriteReport(report, callback, 0);
 }
コード例 #40
0
ファイル: HidDevice.cs プロジェクト: biletnam/homeControl
        public async Task <bool> WriteReportAsync(HidReport report, int timeout = 0)
        {
            var writeReportDelegate = new WriteReportDelegate(WriteReport);

            return(await Task <bool> .Factory.FromAsync(writeReportDelegate.BeginInvoke, writeReportDelegate.EndInvoke, report, timeout, null));
        }
コード例 #41
0
ファイル: HidDevice.cs プロジェクト: macaba/HidLibrary
 public async Task<bool> WriteReportAsync(HidReport report, int timeout = 0)
 {
     var writeReportDelegate = new WriteReportDelegate(WriteReport);
     return await Task<bool>.Factory.FromAsync(writeReportDelegate.BeginInvoke, writeReportDelegate.EndInvoke, report, timeout, null);
 }