コード例 #1
0
        MFD(int id)
        {
            this.Id = id;
            var loader = new HidDeviceLoader();

            if (id == 1)
            {
                _device = loader.GetDevices(THRUSTMASTER_VENDOR_ID, MFD1_PRODUCT_ID).First();
                if (_device == null)
                {
                    throw new Exception("MFD1 Device not found");
                }
            }
            else
            if (id == 2)
            {
                _device = loader.GetDevices(THRUSTMASTER_VENDOR_ID, MFD2_PRODUCT_ID).First();
                if (_device == null)
                {
                    throw new Exception("MFD2 Device not found");
                }
            }
            else
            {
                throw new InvalidOperationException("Invalid MFD ID selected");
            }
        }
コード例 #2
0
        public Form1()
        {
            InitializeComponent();
            //USB\VID_16C0 & PID_05DA\6 & F5178C3 & 0 & 3
            HidDeviceLoader hidDeviceLoader = new HidDeviceLoader();
            int?            nullable        = null;
            HidDevice       hidDevice       = hidDeviceLoader.GetDevices(5824, 1498, nullable, null).FirstOrDefault(d => d.MaxInputReportLength == 63);

            if (hidDevice != null)
            {
                object[]  maxInputReportLength = new object[] { hidDevice.MaxInputReportLength, hidDevice.MaxOutputReportLength, hidDevice.MaxFeatureReportLength, hidDevice.DevicePath };
                HidStream hidStream;
                if (hidDevice.TryOpen(out hidStream))
                {
                    byte[] numArray = new byte[hidDevice.MaxInputReportLength];
                    try
                    {
                        var num = hidStream.Read(numArray, 0, (int)numArray.Length);
                    }
                    catch (TimeoutException timeoutException)
                    {
                        Console.WriteLine("Read timed out.");
                    }
                }
            }
        }
コード例 #3
0
        public override bool Open(string devicePath)
        {
            short vid, pid;

            GetHardwareId(devicePath, out vid, out pid);

            var loader = new HidDeviceLoader();

            // search for HID
            _currentHidDevice = loader.GetDevices(vid, pid).FirstOrDefault();

            if (_currentHidDevice == null)
            {
                Log.ErrorFormat("Couldn't find device with VID: {0}, PID: {1}",
                                vid, pid);
                return(false);
            }

            // open HID
            if (!_currentHidDevice.TryOpen(out _currentHidStream))
            {
                Log.ErrorFormat("Couldn't open device {0}", _currentHidDevice);
                return(false);
            }

            // since these devices have no MAC address, generate one
            DeviceAddress = PhysicalAddress.Parse(MacAddressGenerator.NewMacAddress);

            IsActive = true;
            Path     = devicePath;

            return(IsActive);
        }
コード例 #4
0
ファイル: Class1.cs プロジェクト: markspan/EventExchanger
        public string Attached()
        {
            if (LOADED)
            {
                throw new Exception("Cannot list devices when Started");
            }

            _loader = new HidDeviceLoader();

            deviceList = _loader.GetDevices(-1, -1, -1, "");

            // List Multiple Devices connected
            string ListOfSerialNumbers = "";

            for (int i = 0; i < deviceList.Count(); i++)
            {
                Dev = deviceList.ElementAt(i);
                if (i > 0)
                {
                    ListOfSerialNumbers += "/";
                }
                ListOfSerialNumbers += Dev.ProductName;
            }
            return(ListOfSerialNumbers);
        }
コード例 #5
0
ファイル: DTSCard.cs プロジェクト: BlueFinBima/Helios14
        /// <summary>
        /// Initializes communication with the DTS Card
        /// </summary>
        /// <returns>True if update is sucessful, false if there was a problem.</returns>
        public bool initialize()
        {
            if (_device == null)
            {
                dispose();
            }

            HidDeviceLoader deviceLoader = new HidDeviceLoader();

            foreach (HidDevice device in deviceLoader.GetDevices(0x04d8, 0xf64e))
            {
                if (device.SerialNumber.Equals(SerialNumber))
                {
                    _device = device;
                    break;
                }
            }

            if (_device != null)
            {
                _device.TryOpen(out _stream);
            }

            return(_stream != null);
        }
コード例 #6
0
ファイル: DTSCard.cs プロジェクト: appsou/Helios
        /// <summary>
        /// Initializes communication with the DTS Card
        /// </summary>
        /// <returns>True if update is sucessful, false if there was a problem.</returns>
        public bool initialize()
        {
            if (_device == null)
            {
                dispose();
            }

            HidDeviceLoader deviceLoader = new HidDeviceLoader();

            foreach (HidDevice device in deviceLoader.GetDevices(0x04d8, 0xf64e))
            {
                if (device.SerialNumber.Equals(SerialNumber))
                {
                    _device = device;
                    break;
                }
#pragma warning restore CS0612 // Type or member is obsolete
            }

            if (_device != null)
            {
                _device.TryOpen(out _stream);
            }

            return(_stream != null);
        }
コード例 #7
0
        static void Main(string[] args)
        {
            var loader = new HidDeviceLoader();
            //var devices = loader.GetDevices(THRUSTMASTER_VENDOR_ID, MFD_PRODUCT_ID);
            var devices = loader.GetDevices(THRUSTMASTER_VENDOR_ID);

            var deviceMFD1 = loader.GetDevices(THRUSTMASTER_VENDOR_ID, MFD1_PRODUCT_ID).First();
            var deviceMFD2 = loader.GetDevices(THRUSTMASTER_VENDOR_ID, MFD2_PRODUCT_ID).First();

            if (deviceMFD1 != null)
            {
                byte brightness = 0x09;
                byte ledStatus  = 0;

                var device = deviceMFD1;

                SetBrightness(brightness, device);
                brightness = GetBrightness(device);

                //SetLEDStatus(device, false, true);    // left light off, right light on
                //SetLEDStatus(device, true, false);   // left light on, right light on
                //SetLEDStatus(device, true, true);   // left light on, right light on
                SetLEDStatus(device, false, false);   // left light on, right light on
                ledStatus = GetLEDStatus(device);
            }

            Console.Write("Devices: ");
            Console.WriteLine(devices.Count());
            Console.WriteLine("Done!");
        }
コード例 #8
0
        public HidManager()
        {
            HidDeviceLoader = new HidDeviceLoader();
            FoundDevices    = new ObservableCollection <HidDeviceRepresentation>();

            _hidScanThread = new Thread(() =>
            {
                while (true)
                {
                    var currentDevices = HidDeviceLoader.GetDevices().Select(hidDevice => new HidDeviceRepresentation(hidDevice)).ToList();

                    if (!Thread.CurrentThread.IsAlive)
                    {
                        break;
                    }

                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        foreach (var newDevice in currentDevices.Where(device => !FoundDevices.Contains(device)))
                        {
                            FoundDevices.Add(newDevice);
                        }
                    });


                    Thread.Sleep(TimeSpan.FromSeconds(10));
                }
                // ReSharper disable once FunctionNeverReturns
            });
            _hidScanThread.Start();
        }
コード例 #9
0
        public void ConnectToMicrocontroller()
        {
            HidDeviceLoader device_loader = new HidDeviceLoader();
            HidDevice       device        = device_loader.GetDeviceOrDefault(VendorID, ProductID);

            if (device != null)
            {
                bool success = device.TryOpen(out MicrocontrollerStream);
                if (!success)
                {
                    MMazeMessaging.GetInstance().AddMessage("Unable to connect to microcontroller!");
                }
                else
                {
                    //Disable the read and write timeouts
                    //MicrocontrollerStream.ReadTimeout = System.Threading.Timeout.Infinite;
                    //MicrocontrollerStream.WriteTimeout = System.Threading.Timeout.Infinite;
                    MicrocontrollerStream.ReadTimeout  = 30;
                    MicrocontrollerStream.WriteTimeout = 30;
                }
            }
            else
            {
                MMazeMessaging.GetInstance().AddMessage("Unable to find microcontroller device!");
            }
        }
コード例 #10
0
        public GamepadManager()
        {
            _hidDeviceLoader = new HidDeviceLoader();
            FoundDevices     = new ObservableCollection <HidDeviceRepresentation>();

            SelectedDevice = JsonConvert.DeserializeObject <HidDeviceRepresentation>(Settings.Default.SelectedHidDevice);
            if (SelectedDevice != null && !FoundDevices.Contains(SelectedDevice))
            {
                FoundDevices.Add(SelectedDevice);
            }

            _currentDeviceUpdateThread = new Thread(() =>
            {
                while (true)
                {
                    var hidDevices     = _hidDeviceLoader.GetDevices();
                    var currentDevices =
                        hidDevices.Select(hidDevice => new HidDeviceRepresentation(hidDevice)).ToList();

                    foreach (var newDevice in currentDevices.Where(device => !FoundDevices.Contains(device)))
                    {
                        Application.Current.Dispatcher.Invoke(() => FoundDevices.Add(newDevice));
                    }

                    Thread.Sleep(TimeSpan.FromSeconds(10));
                }
            });
            _currentDeviceUpdateThread.Start();
        }
コード例 #11
0
        public override bool Open(string devicePath)
        {
            var loader = new HidDeviceLoader();

            // search for HID
            _currentHidDevice = loader.GetDevices(VendorId, ProductId).FirstOrDefault();

            if (_currentHidDevice == null)
            {
                Log.ErrorFormat("Couldn't find device with VID: {0}, PID: {1}",
                                VendorId, ProductId);
                return(false);
            }

            // open HID
            if (!_currentHidDevice.TryOpen(out _currentHidStream))
            {
                Log.ErrorFormat("Couldn't open device {0}", _currentHidDevice);
                return(false);
            }

            // since these devices have no MAC address, generate one
            m_Mac = MacAddressGenerator.NewMacAddress;

            IsActive = true;
            Path     = devicePath;

            return(IsActive);
        }
コード例 #12
0
        public static HidDevice Find(int vid, int pid, string vendor, string device, int featureSize)
        {
            HidDeviceLoader ldr = new HidDeviceLoader();

            foreach (HidDevice dev in ldr.GetDevices())
            {
                if (vid != 0 && dev.VendorID != vid)
                {
                    continue;
                }
                if (pid != 0 && dev.ProductID != pid)
                {
                    continue;
                }
                if (vendor != null && dev.Manufacturer != vendor)
                {
                    continue;
                }
                if (device != null && dev.ProductName != device)
                {
                    continue;
                }
                if (featureSize != 0 && dev.MaxFeatureReportLength != featureSize)
                {
                    continue;
                }
                return(dev);
            }
            return(null);
        }
コード例 #13
0
ファイル: Class1.cs プロジェクト: markspan/EventExchanger
        public string GetProductNames()
        {
            int EVTXCHCount = 0;

            if (LOADED)
            {
                throw new Exception("Cannot list devices when Started");
            }

            _loader = new HidDeviceLoader();

            deviceList = _loader.GetDevices(-1, -1, -1, "");

            // List Multiple Devices connected
            string ListOfProductNumbers = "";

            for (int i = 0; i < deviceList.Count(); i++)
            {
                Dev = deviceList.ElementAt(i);
                if (Dev.ProductName.Contains("EventExchanger"))
                {
                    if (EVTXCHCount++ > 1)
                    {
                        ListOfProductNumbers += "/";
                    }
                    ListOfProductNumbers += Dev.ProductName;
                }
            }
            return(ListOfProductNumbers);
        }
コード例 #14
0
        public static HidDevice GetConfigInterface()
        {
            var loader = new HidDeviceLoader();

            // todo: use foreach/window instead of firstordefault
            return(loader.GetDevices(0x04d8, 0x0058).FirstOrDefault(device => device.ProductName == "NinHID CFG" ||
                                                                    (device.MaxInputReportLength == device.MaxOutputReportLength && device.MaxInputReportLength == 9)));
        }
コード例 #15
0
        public static IEnumerable <MusiaConfigInterface> GetMusiaConfigInterfaces()
        {
            var ldr = new HidDeviceLoader();

            foreach (HidDevice dev in ldr.GetDevices(0x1209, 0x8844).Where(d => d.ProductName.Contains("config")))
            {
                yield return(new MusiaConfigInterface(dev));
            }
        }
コード例 #16
0
 public override void Stop()
 {
     SF = null;
     SetAllLeds(false);
     stream.Close();
     buffer    = null;
     HidDevice = null;
     loader    = null;
 }
コード例 #17
0
ファイル: BuzzBuzzer.cs プロジェクト: IxelBox/UbuconQuiz
        public void LoadDevice()
        {
            var loader = new HidDeviceLoader();

            Thread.Sleep(2000);  // Give a bit of time so our timing below is more valid as a benchmark.
            Device = loader.GetDevices(1356, 2).FirstOrDefault();
            if (Device == null)
            {
                throw new ApplicationException("Failed to open device.");
            }
        }
コード例 #18
0
        public void Open()
        {
            HidDeviceLoader loader = new HidDeviceLoader();

            _device = loader.GetDeviceOrDefault(Constants.VendorId, Constants.ProductId);
            if (_device == null)
            {
                throw new DeviceNotFoundException();
            }

            _device.Open();
        }
コード例 #19
0
        public static IEnumerable <MuniaConfigInterface> GetMuniaConfigInterfaces()
        {
            var ldr        = new HidDeviceLoader();
            var candidates = ldr.GetDevices(0x04d8, 0x0058)
                             .Union(ldr.GetDevices(0x1209));

            foreach (HidDevice dev in candidates.Where(device => device.ProductName == "NinHID CFG" ||
                                                       device.GetMaxInputReportLength() == device.GetMaxOutputReportLength() &&
                                                       device.GetMaxOutputReportLength() == 9))
            {
                yield return(new MuniaConfigInterface(dev));
            }
        }
コード例 #20
0
        private static HidDevice FindUSBDevice()
        {
            HidDeviceLoader loader = new HidDeviceLoader();
            HidDevice       device = loader.GetDeviceOrDefault(vendorId, productId);

            if (device != null)
            {
                Logger.Log("StreamDeck", "Found StreamDeck USB device!");
                return(device);
            }

            Logger.Log("StreamDeck", "Could not find StreamDeck USB device!", LoggerVerbosity.Error);
            return(null);
        }
        /// <summary>
        /// Find all BlinkStick devices.
        /// </summary>
        /// <returns>An array of BlinkStick devices</returns>
        public static BlinkStick[] FindAll()
        {
            List <BlinkStick> result = new List <BlinkStick>();

            HidDeviceLoader loader = new HidDeviceLoader();

            foreach (HidDevice adevice in loader.GetDevices(VendorId, ProductId).ToArray())
            {
                BlinkStick hid = new BlinkStick();
                hid.device = adevice;
                result.Add(hid);
            }

            return(result.ToArray());
        }
コード例 #22
0
 public HidManager()
 {
     try
     {
         var loader = new HidDeviceLoader();
         var device = loader.GetDevices(0x1770, 0xff00).First();
         device.TryOpen(out _stream);
     }
     catch
     {
         MessageBox.Show("Error while loading the USB device, the program will now quit.", "Error !",
                         MessageBoxButton.OK, MessageBoxImage.Warning);
         Environment.Exit(1);
     }
 }
コード例 #23
0
        public static IEnumerable <MuniaController> ListDevices()
        {
            var ldr = new HidDeviceLoader();

            // MUNIA devices with 0x1209 VID
            foreach (var device in ldr.GetDevices(0x1209))
            {
                if (device.ProductName == "NinHID NGC")
                {
                    yield return(new MuniaNgc(device));
                }
                else if (device.ProductName == "NinHID N64")
                {
                    yield return(new MuniaN64(device));
                }
                else if (device.ProductName == "NinHID SNES")
                {
                    yield return(new MuniaSnes(device));
                }
            }

            // MUSIA devices
            foreach (var device in ldr.GetDevices(0x1209, 0x8844))
            {
                if (device.ProductName == "MUSIA PS2 controller")
                {
                    yield return(new MusiaPS2(device));
                }
            }


            // legacy VID/PID combo from microchip
            foreach (var device in ldr.GetDevices(0x04d8, 0x0058))
            {
                if (device.ProductName == "NinHID NGC" || device.GetMaxInputReportLength() == 9 && device.GetMaxOutputReportLength() == 0)
                {
                    yield return(new MuniaNgc(device));
                }
                else if (device.ProductName == "NinHID N64" || device.GetMaxInputReportLength() == 5)
                {
                    yield return(new MuniaN64(device));
                }
                else if (device.ProductName == "NinHID SNES" || device.GetMaxInputReportLength() == 3)
                {
                    yield return(new MuniaSnes(device));
                }
            }
        }
コード例 #24
0
        /// <summary>
        /// Create object using VendorID and ProductID. Will throw exception if no USBLED is found.
        /// </summary>
        /// <param name="vendorID">Example to 0x1D34</param>
        /// <param name="productID">Example to 0x0008</param>
        /// <param name="deviceIndex">Zero based device index if you have multiple devices plugged in.</param>
        public DreamCheekyBTN(int vendorID, int productID, int deviceIndex = 0)
        {
            var loader  = new HidDeviceLoader();
            var devices = new List <HidDevice>(loader.GetDevices(vendorID, productID));

            if (deviceIndex >= devices.Count)
            {
                throw new ArgumentOutOfRangeException("deviceIndex", String.Format("VID={0},PID={1},DeviceIndex={2} is invalid. There are only {3} devices connected.", vendorID, productID, deviceIndex, devices.Count));
            }
            HidBTN = devices[deviceIndex];
            if (!init())
            {
                throw new Exception(String.Format("Cannot find USB HID Device with VendorID=0x{0:X4} and ProductID=0x{1:X4}", vendorID, productID));
            }
            ActivatedMessage = Messages.BUTTON_PRESSED;
        }
コード例 #25
0
        public void init_hid_device()
        {
            //var device_list = (from x in hid.enumerate(this.VENDOR_ID, this.PRODUCT_ID)
            //                   where x["interface_number"] == this.IFACE_NUM
            //                   select x).ToList();
            //if (device_list.Count == 0)
            //{
            //    throw Exception("No devices found. See: https://github.com/gfduszynski/cm-rgb/issues/9");
            //}
            //this.device = hid.device();
            //try
            //{
            //    this.device.open_path(device_list[0]["path"]);
            //}
            //catch (OSError)
            //{
            //    Console.WriteLine("Failed to access usb device. See: https://github.com/gfduszynski/cm-rgb/wiki/1.-Installation-&-Configuration#3-configuration");
            //    Console.WriteLine("Also check if other process is not using the device.\n");
            //    throw;
            //}



            var terp = new OpenConfiguration();

            terp.SetOption(OpenOption.Exclusive, true);

            var loader = new HidDeviceLoader();

            var devices = loader.GetDevices(VENDOR_ID, PRODUCT_ID).ToArray();

            foreach (var tdevice in devices)
            {
                try
                {
                    stream = tdevice.Open(terp);
                    this.init_controller();
                    Debug.WriteLine("Well, that seemed to work");
                    break;
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                }
            }
        }
コード例 #26
0
ファイル: Gamepad.cs プロジェクト: nowyouare/MFIGamepadFeeder
        public Gamepad(GamepadConfiguration config, VGenWrapper vGenWrapper, HidDeviceLoader hidDeviceLoader)
        {
            _config          = config;
            _vGenWrapper     = vGenWrapper;
            _hidDeviceLoader = hidDeviceLoader;
            _virtualMappings = new Dictionary <XInputGamepadButtons, XInputGamepadButtons>();

            foreach (var virtualMapping in _config.Mapping.VirtualKeysItems.Where(item => item.DestinationItem != null))
            {
                var virtualPattern = virtualMapping.SourceKeys
                                     .Where(sourceKey => sourceKey != null)
                                     .Aggregate((XInputGamepadButtons)0, (current, sourceKey) => current | sourceKey.Value);

                // ReSharper disable once PossibleInvalidOperationException
                _virtualMappings[virtualPattern] = (XInputGamepadButtons)virtualMapping.DestinationItem;
            }
        }
コード例 #27
0
        /// <summary>
        /// Create object using Device path. Example: DreamCheekyBTN(@"\\?\hid#vid_1d34&pid_0008#6&1067c3dc&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}").
        /// </summary>
        /// <param name="devicePath">Example: @"\\?\hid#vid_1d34&pid_0008#6&1067c3dc&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}"</param>
        public DreamCheekyBTN(string devicePath)
        {
            var loader  = new HidDeviceLoader();
            var devices = loader.GetDevices();

            foreach (var device in devices)
            {
                if (device.DevicePath == devicePath)
                {
                    HidBTN = device;
                }
            }
            if (!init())
            {
                throw new Exception(String.Format("Cannot find USB HID Device with DevicePath={0}", devicePath));
            }
            ActivatedMessage = Messages.BUTTON_PRESSED;
        }
コード例 #28
0
        public bool Connect()
        {
            var loader = new HidDeviceLoader();

            if (loader.GetDevices(VID, PID).Count() != 1)
            {
                return(false);
            }
            try
            {
                HidDevice tempDevice = new HidDeviceLoader().GetDevices(VID, PID).First();
                device = tempDevice;
                return(isConnected);
            }
            catch
            {
                return(false);
            }
        }
コード例 #29
0
        /// <summary>
        /// Create object using VendorID and ProductID. Will throw exception if no USBLED is found.
        /// </summary>
        /// <param name="vendorID">Example to 0x1D34</param>
        /// <param name="productID">Example to 0x0004</param>
        /// <param name="deviceIndex">Zero based device index if you have multiple devices plugged in.</param>
        public DreamCheekyLED(int vendorID, int productID, int deviceIndex = 0)
        {
            Trace.WriteLine("Instantiating HidDeviceLoader...");
            Loader = new HidDeviceLoader();

            Trace.WriteLine(String.Format("Enumerating HID USB Devices (VendorID {0}, ProductID {1})...", vendorID, productID));
            var devices = new List <HidDevice>(Loader.GetDevices(vendorID, productID));

            if (deviceIndex >= devices.Count)
            {
                throw new ArgumentOutOfRangeException("deviceIndex", String.Format("deviceIndex={0} is invalid. There are only {1} devices connected.", deviceIndex, devices.Count));
            }

            HidLED = devices[deviceIndex];
            if (!init())
            {
                throw new Exception(String.Format("Cannot find USB HID Device with VendorID=0x{0:X4} and ProductID=0x{1:X4}", vendorID, productID));
            }
        }
コード例 #30
0
        public WindowsHIDSensorGroup(ISettings settings)
        {
            // No implementation for WindowsHIDSensor on Unix systems
            int p = (int)Environment.OSVersion.Platform;

            if ((p == 4) || (p == 128))
            {
                return;
            }

            HidDeviceLoader loader     = new HidDeviceLoader();
            var             deviceList = loader.GetDevices().ToArray();

            HidDevice selected = loader.GetDevices(1155, 22288).FirstOrDefault();//VID 1155, PID 22288,

            if (selected != null)
            {
                hardware.Add(new WindowsHIDSensor(selected, settings));
            }
        }
コード例 #31
0
ファイル: Program.cs プロジェクト: njmube/hidsharp
        static void Main(string[] args)
        {
            HidDeviceLoader loader = new HidDeviceLoader();
            Thread.Sleep(2000); // Give a bit of time so our timing below is more valid as a benchmark.

            var stopwatch = new Stopwatch();
            stopwatch.Start();
            var deviceList = loader.GetDevices().ToArray();
            stopwatch.Stop();
            long deviceListTotalTime = stopwatch.ElapsedMilliseconds;

			Console.WriteLine("Complete device list (took {0} ms to get {1} devices):",
                              deviceListTotalTime, deviceList.Length);
            foreach (HidDevice dev in deviceList)
            {
                Console.WriteLine(dev);
            }
            Console.WriteLine();

			Console.WriteLine("Opening HID class device...");

#if SAMPLE_OPEN_AND_READ
			var device = loader.GetDevices(0x1b1c, 0x0c04).First();
            if (device == null) { Console.WriteLine("Failed to open device."); Environment.Exit(1); }

            Console.Write(@"
Max Lengths:
  Input:   {0}
  Output:  {1}
  Feature: {2}

The operating system name for this device is:
  {3}

"
, device.MaxInputReportLength
, device.MaxOutputReportLength
, device.MaxFeatureReportLength
, device.DevicePath
);

            HidStream stream;
            if (!device.TryOpen(out stream)) { Console.WriteLine("Failed to open device."); Environment.Exit(2); }

            using (stream)
            {
			    int n = 0;
                while (true)
			    {
                    var bytes = new byte[device.MaxInputReportLength];
                    int count;

                    try
                    {
                        count = stream.Read(bytes, 0, bytes.Length);
                    }
                    catch (TimeoutException)
                    {
                        Console.WriteLine("Read timed out.");
                        continue;
                    }
					
                    if (count > 0)
                    {
                        Console.Write("* {0} : ", count);

                        for (int i = 0; i < count && i < 62; i++)
                        {
                            Console.Write("{0:X} ", bytes[i]);
                        }

                        Console.WriteLine();
					    if (++n == 100) { break; }
                    }
                }
            }
#elif SAMPLE_DYMO_SCALE
            HidDevice scale = loader.GetDeviceOrDefault(24726, 344);
            if (scale == null) { Console.WriteLine("Failed to find scale device."); Environment.Exit(1); }

            HidStream stream;
            if (!scale.TryOpen(out stream)) { Console.WriteLine("Failed to open scale device."); Environment.Exit(2); }

            using (stream)
            {
                int n = 0; DymoScale scaleReader = new DeviceHelpers.DymoScale(stream);
                while (true)
                {
                    int value, exponent;
                    DymoScaleUnit unit; string unitName;
                    DymoScaleStatus status; string statusName;
                    bool buffered;

                    scaleReader.ReadSample(out value, out exponent, out unit, out status, out buffered);
                    unitName = DymoScale.GetNameFromUnit(unit);
                    statusName = DymoScale.GetNameFromStatus(status);

                    Console.WriteLine("{4}  {0}: {1}x10^{2} {3} ", statusName, value, exponent, unitName, buffered ? "b" : " ");
                    if (!buffered) { if (++n == 100) { break; } }
                }
            }
#else
#error "No sample selected."
#endif
			
			Console.WriteLine("Press a key to exit...");
            Console.ReadKey();
        }