<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[James's Programming Page — Discussion]]></title>
	<link rel="self" href="https://swforum.seekye.com/feed/atom/forum/2/" />
	<updated>2026-03-21T22:49:30Z</updated>
	<generator>PunBB</generator>
	<id>https://swforum.seekye.com/</id>
		<entry>
			<title type="html"><![CDATA[HidSharp Feature request: HID device in write-only or read-only mode]]></title>
			<link rel="alternate" href="https://swforum.seekye.com/topic/10170/new/posts/" />
			<summary type="html"><![CDATA[<p>Hi James,</p><p>I have one use-case where the current API is quite painful to work around, and I think adding support for write-only or read-only opening would help a lot of people.</p><p>My scenario:<br />I need to send Feature Reports to a HID mouse (mostly to control RGB lighting, DPI stages, polling rate, etc. on gaming mice).</p><p>On Windows:<br />The mouse is opened successfully with GENERIC_WRITE access<br />Writing Feature Reports (via HidD_SetFeature) works perfectly<br />But Windows refuses to open the same device with GENERIC_READ access.<br />When I do device.TryOpen(out var stream) in HidSharp, it requests both read and write access and fails.</p><p>Feature request / suggestion<br />An OpenMode / Access option in TryOpen(OpenConfiguration)</p><p>Something like:<br />var config = new OpenConfiguration();<br />config.SetOption(OpenOption.ReadAccess, true);<br />config.SetOption(OpenOption.WriteAccess, true);<br />device.TryOpen(config, out var stream);</p><p>This would allow clean write-only usage for exactly the kind of devices that Windows protects from being read (mice, some keyboards, touchpads, etc.) while still letting us send output/feature reports.</p><p>Thanks for considering this.</p>]]></summary>
			<author>
				<name><![CDATA[vondollie]]></name>
				<uri>https://swforum.seekye.com/user/17176/</uri>
			</author>
			<updated>2026-03-21T22:49:30Z</updated>
			<id>https://swforum.seekye.com/topic/10170/new/posts/</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Signed Axis Minimum values are forced to 0]]></title>
			<link rel="alternate" href="https://swforum.seekye.com/topic/10166/new/posts/" />
			<summary type="html"><![CDATA[<p>Hi,</p><p>Thanks for this library. There&#039;s a problem in the report descriptor parsing with signed values for axis (PhysicalMinimum and LogicalMinimum).</p><p>When a negative value is found, it is forced to 0 in Reports/Encoding/EncodedItems, line 160 and 162 :</p><p>Changing the following two lines fixes the bug:</p><p>EncodedItem.cs : L160 change<br />{ DataValue = (uint)(sbyte)value; if (value &lt; 0) { Data.Add(0); } }<br />to<br />{ DataValue = (uint)(sbyte)value; }</p><p>and EncodedItem:L162 change<br />{ DataValue = (uint)(short)value; if (value &lt; 0) { Data.Add(0); Data.Add(0); } }<br />to<br />{ DataValue = (uint)(short)value; }</p><p>I don&#039;t understand what is the purpose of these 2 tests, and if it is a correct fix. Currently I&#039;m stuck in the development of a plugin for a software that uses this library in a dll because of this bug.</p>]]></summary>
			<author>
				<name><![CDATA[Etienne]]></name>
				<uri>https://swforum.seekye.com/user/17070/</uri>
			</author>
			<updated>2025-10-08T09:03:47Z</updated>
			<id>https://swforum.seekye.com/topic/10166/new/posts/</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Shift key not working]]></title>
			<link rel="alternate" href="https://swforum.seekye.com/topic/10159/new/posts/" />
			<summary type="html"><![CDATA[<p>Hi, I find that using the remoteviewing client then keys such as shift key are not sent to server. Other clients with same server the key functionality works as expected</p>]]></summary>
			<author>
				<name><![CDATA[mike10]]></name>
				<uri>https://swforum.seekye.com/user/15423/</uri>
			</author>
			<updated>2025-08-20T08:29:52Z</updated>
			<id>https://swforum.seekye.com/topic/10159/new/posts/</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[HidSharp mocking]]></title>
			<link rel="alternate" href="https://swforum.seekye.com/topic/10158/new/posts/" />
			<summary type="html"><![CDATA[<p>Hi,</p><p>Thanks for the great HidSharp library, I find it very useful. I am using it in one C# project to communicate with a specific device and want to be able to write unit tests for it. Unfortunately, the library currently makes use of concrete types with no interfaces. This makes it hard to mock/fake for testing.</p><p>Is there any chance an `IHidDevice` interface could be added to the NuGet package please? I would be happy to contribute it myself, if you are accepting outside contributions and can tell me how best to share my code with you, as it isn&#039;t hosted on GitHub.</p><p>I envisage something like this:</p><p>```<br />public interface IHidDevice<br />{<br />&nbsp; &nbsp; Stream Open();<br />&nbsp; &nbsp; int ProductID { get; }<br />&nbsp; &nbsp; int VendorID { get; }<br />}<br />```</p>]]></summary>
			<author>
				<name><![CDATA[kingkeith+zer7]]></name>
				<uri>https://swforum.seekye.com/user/15690/</uri>
			</author>
			<updated>2025-01-11T20:06:35Z</updated>
			<id>https://swforum.seekye.com/topic/10158/new/posts/</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Screen sizing / mouse movement in RemoteViewing]]></title>
			<link rel="alternate" href="https://swforum.seekye.com/topic/10157/new/posts/" />
			<summary type="html"><![CDATA[<p>Hi, hoping this board is still monitored?</p><p>Thanks for your effort in developing this. </p><p>I am currently trying to implement a VNC client in a C# form using this. I tried VNCSharp previously but found the performance to be poor. RemoteViewing seems much better in that respect. However I find that if I use any sizemode other than AutoSize then the mouse scaling seems incorrect - i.e. I cannot reach the bottom X amount of the screen, depending on how much the size of the control differs from that used by autosize. </p><p>If I use Autosize the problem I have is that the control is then bigger than the form in which I need to display it. I added a panel and made this the parent of the control so I at least get scrollbars and everything works but not userfriendly! Anyideas on a better solution?</p><p>TIA</p><p>Mike</p>]]></summary>
			<author>
				<name><![CDATA[mike10]]></name>
				<uri>https://swforum.seekye.com/user/15423/</uri>
			</author>
			<updated>2024-11-06T11:34:29Z</updated>
			<id>https://swforum.seekye.com/topic/10157/new/posts/</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[HidSharp write: 'Operation failed early: The parameter is incorrect']]></title>
			<link rel="alternate" href="https://swforum.seekye.com/topic/10156/new/posts/" />
			<summary type="html"><![CDATA[<p>Hello,</p><p>I have a USB scanner for bar codes/QR codes/MRZ.<br />I have a user manual from the manufacturer, which contains a set of QR codes that allow me to configure the device.<br />For example by scanning the following values:</p><p>$&gt;:S01010F.&lt;$ (Enter Setup)<br />$&gt;: S0F0516.&lt;$ (USB HID POS)<br />$&gt;:S01000F.&lt;$ (Exit Setup)</p><p>I was able to switch the device to &quot;USB HID POS&quot; mode. (default mode being &quot;USB HID-KBW&quot; in which the scanner behaves like a keyboard)<br />In this mode I am able to read scanned data using the HidSharp library.</p><p>However I also need to be able to change the settings of the device programmatically. But when I call stream.Write, I always get the following exception:</p><p>System.IO.IOException: &#039;Operation failed early: The parameter is incorrect&#039;</p><p>Stack trace:<br />at HidSharp.Platform.Windows.NativeMethods.OverlappedOperation(IntPtr ioHandle, IntPtr eventHandle, Int32 eventTimeout, IntPtr closeEventHandle, Boolean overlapResult, NativeOverlapped* overlapped, UInt32&amp; bytesTransferred)</p><p>There&#039;s an inner exception that just says Win32Exception: &#039;The parameter is incorrect&#039; (no stack trace)</p><p><strong>Info about the device:</strong></p><p>// hdev.ToString() + &quot; | &quot; + hdev.DevicePath<br />Linux 3.10.14 with dwc2-gadget hidpos 00000000 (VID 4619, PID 33287, version 3.10) | \\?\hid#vid_120b&amp;pid_8207#7&amp;52366e0&amp;0&amp;0000#{4d1e55b2-f16f-11cf-88cb-001111000030}</p><p>(the device itself has &quot;Linux&quot; in the name, I&#039;m currently running Windows 10)</p><p>The following is an enumeration over the device&#039;s Reports:</p><p>Max Lengths: Input 64, Output 64, Feature 0<br />Serial Ports:<br />1 device items found.<br />Usage: 8C0001 9175041<br />Input: ReportID=2, Length=64, Items=1<br />63 Elements x 8 Bits, Units: None, Expected Usage Type: 0, Flags: Variable, BufferedBytes, Usages: 8C00FE 9175294<br />Output: ReportID=4, Length=64, Items=1<br />63 Elements x 8 Bits, Units: None, Expected Usage Type: 0, Flags: Variable, Relative, Nonlinear, Volatile, Usages: 8C0000 9175040</p><p><strong>What I&#039;m trying to do:</strong></p><p>Assuming the device supports receiving setup commands, and that these are the same as the commands from the QR codes, I&#039;ve been trying to send the following commands to the device (one at a time):</p><p>01010F (Enter Setup)<br />0C0814 (Set external illumination to &quot;Always on&quot;)<br />01000F (Exit Setup)</p><p>NOTE: I&#039;ve tried sending it in the format $&gt;:S01010F.&lt;$ and S01010F, but I suspect those are just some tags telling the QR parser it&#039;s a command, and the actual command is the 6 digit hex string.</p><p>I&#039;ve tried creating the input buffer diretly:<br />var enterSetupBuffer = Encoding.ASCII.GetBytes(&quot;01010F&quot;);</p><p>I&#039;ve tried creating a byte array of size 64 and setting the first few bytes in the array:<br />var someBuffer = new byte[64];<br />someBuffer[0] = 0x01;<br />someBuffer[1] = 0x01;<br />someBuffer[2] = 0x0F;<br />(and some variations on this)</p><p>no matter what I do, I get the same error: Operation failed early: The parameter is incorrect.<br />Some more details: I try to write using the HidStream.Write(buffer). I attempt the write before I start reading from the device. stream.CanWrite is returning true.</p><p>As you&#039;ve probably guessed, I&#039;m not good with hardware. I&#039;m primarily a business application developer. All my attempts so far have been pretty much guesswork. I don&#039;t even know if it&#039;s the device rejecting my attempts at communication, or if there&#039;s something else I don&#039;t even know about tripping me up before the data is even sent to the device.</p><p>Any help would be greatly appreciated.</p>]]></summary>
			<author>
				<name><![CDATA[green.airplane]]></name>
				<uri>https://swforum.seekye.com/user/14991/</uri>
			</author>
			<updated>2024-05-29T13:30:32Z</updated>
			<id>https://swforum.seekye.com/topic/10156/new/posts/</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Have issues trying to get 16-bit joystick inputs consistently]]></title>
			<link rel="alternate" href="https://swforum.seekye.com/topic/10155/new/posts/" />
			<summary type="html"><![CDATA[<p>Hello. As the title says, I&#039;m having trouble trying to run a 16-bit joystick/hardware. Sometimes, it works when I run the code. Sometimes it doesn&#039;t. It&#039;s inconsistent and I need help.</p><p>I have no troubles with 8-bit. Just with 16-bit joystick I&#039;m having troubles with.</p><p>Here&#039;s the code:</p><div class="codebox"><pre><code>static void Main()
{
    var list = DeviceList.Local;
    
    var joystick = list.GetHidDeviceOrNull(productID: 12345);

    if (joystick != null)
    {
        using (var stream = joystick.Open())
        {
            var inputReportBuffer = new byte[joystick.GetMaxInputReportLength()];
            while (true)
            {
                try
                {
                    int length = stream.Read(inputReportBuffer, 0, inputReportBuffer.Length);
                    Console.Write($&quot;Worked!\n&quot;);
                    Thread.Sleep(1000);
                }
                catch (Exception ex)
                {
                    Console.Write($&quot;Crashed!\n&quot;);
                    Console.WriteLine($&quot;Exception: {ex.Message}\n{ex.StackTrace}&quot;);
                }

            }
        }
    }
    else
    {
        Console.WriteLine(&quot;Joystick not found.&quot;);
    }
}</code></pre></div><p>Please help me. I really appreciate any kind of help.</p>]]></summary>
			<author>
				<name><![CDATA[zamarloveub]]></name>
				<uri>https://swforum.seekye.com/user/14985/</uri>
			</author>
			<updated>2024-03-11T08:09:50Z</updated>
			<id>https://swforum.seekye.com/topic/10155/new/posts/</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[HidSharp HidManager thread spinning on Linux]]></title>
			<link rel="alternate" href="https://swforum.seekye.com/topic/10153/new/posts/" />
			<summary type="html"><![CDATA[<p>Hi,</p><p>I&#039;ve noticed that after some random time the HidManager thread starts looping rapidly on Linux. The loop pins one core to 100% usage.<br />I&#039;ve tried to profile the code a bit, and it seems that the NativeMethods.poll returns immediately (Platform/Linux/LinuxHidManager.cs, row 63, &quot;ret = NativeMethods.retry(() =&gt; NativeMethods.poll(fds, (IntPtr)1, -1));&quot;).</p><p>My usage of the library is just opening a device, sending a report to the HID stream and reading a response report, then closing the stream. I&#039;m doing this every 5 minutes or so, and at some random time the HidManager thread starts to eat up the CPU. The program seems to continue working despite this.</p>]]></summary>
			<author>
				<name><![CDATA[zini]]></name>
				<uri>https://swforum.seekye.com/user/14970/</uri>
			</author>
			<updated>2023-07-03T11:48:25Z</updated>
			<id>https://swforum.seekye.com/topic/10153/new/posts/</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[WinHidDevice OutputReportByteLength is wrongly read]]></title>
			<link rel="alternate" href="https://swforum.seekye.com/topic/10152/new/posts/" />
			<summary type="html"><![CDATA[<p>Hi,</p><p>We have a custom HID device that has OutputReportByteLength set to 4 bytes in firmware, but when we open it in Windows, the value is equal to the InputReportByteLength, i.e. 31.</p><p>Is it Windows error ? <br />Linux reports correct value - HidSharp was not used there to test.</p>]]></summary>
			<author>
				<name><![CDATA[szamil]]></name>
				<uri>https://swforum.seekye.com/user/14464/</uri>
			</author>
			<updated>2022-05-31T08:45:44Z</updated>
			<id>https://swforum.seekye.com/topic/10152/new/posts/</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Potential issue with HIDSharp with USB 2.0 Devices on USB 3.0 ports?]]></title>
			<link rel="alternate" href="https://swforum.seekye.com/topic/10151/new/posts/" />
			<summary type="html"><![CDATA[<p>I&#039;m having a very strange issue trying to interface with a USB FullSpeed Generic 64-byte HID via HIDSharp, but the problem *only* appears when connected to USB 3.0 ports.&nbsp; It&#039;s entirely possible (and I would say, likely) that the issue lies on the device end rather than the PC/HIDSharp end, but I wanted to at least check and see if there was anything on the Host PC end I could check?</p><p>What I&#039;m seeing is that I&#039;m writing data to EP2 (64 Bytes, 10ms, INT) with a hidStream.Write() call, I can see on my USB analyzer (a Beagle USB 12) that the bytes are making it out to the device but on the device firmware side the endpoint status never reports an Event Pending (Out Buffer Full), which is how my firmware knows that data has been received on the endpoint.&nbsp; Like I said, it seems more likely to be an issue on the device side, but wanted to at least see if there&#039;s any funny business I could check for on the host PC side.</p><p>Is anyone aware of any known issues with HIDSharp interfacing with 2.0 devices on 3.0 ports?&nbsp; Any gotchas I should be aware of maybe?</p>]]></summary>
			<author>
				<name><![CDATA[KTrenholm]]></name>
				<uri>https://swforum.seekye.com/user/14273/</uri>
			</author>
			<updated>2022-02-07T20:54:45Z</updated>
			<id>https://swforum.seekye.com/topic/10151/new/posts/</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Write to device example?]]></title>
			<link rel="alternate" href="https://swforum.seekye.com/topic/10150/new/posts/" />
			<summary type="html"><![CDATA[<p>Hey,</p><p>Im working on a project, and have been having some success with HidSharp. I can read from my device just fine, and can access the data i need from the IN reports.</p><p>However I totally cannot see how i can write OUT reports back to the device. I&#039;ve trawled the internet, but no examples.</p><p>Ive found I can get the OUT report I need using the GetReport() method but i dont know how to write my values into it, or send it.</p><p>Any advice/help much appreciated.</p>]]></summary>
			<author>
				<name><![CDATA[samsamm777]]></name>
				<uri>https://swforum.seekye.com/user/14379/</uri>
			</author>
			<updated>2021-11-21T00:02:06Z</updated>
			<id>https://swforum.seekye.com/topic/10150/new/posts/</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Problems writing to Skylander RFID portal]]></title>
			<link rel="alternate" href="https://swforum.seekye.com/topic/10149/new/posts/" />
			<summary type="html"><![CDATA[<p>For fun I wanted to to play around with the skylander rfid portal. This is an USB Hid device and the &quot;protocol&quot; is quite simple or so it appears from SKyDumper project (<a href="http://h**ps://github.com/capull0/SkyDumper">h**ps://github.com/capull0/SkyDumper</a>). This tool SkyDumper works on my linux computer, but when I try to convert it to hidsharp it won&#039;t work.</p><p>To be more specific.<br />* I can detect the portal just fine and get the device. <br />* I can open a HidStream<br />* I then try to send the &quot;restart&quot; message. Basically report Zero and the letter R, the rest all zeros.<br />* As soon as this is send out the portal starts sending status messages which I receive continuously. So the message did wake up something.<br />* However the write errors out with an exception. On my linux laptop its and I/O exception hardcoded in the output source code of hidsharp and on windows its a timeout exception.</p><p>I&#039;m no usb export and have little clue why this happens. </p><p>I converted portalIO.cpp to the C# code below. I must be missing something silly I think. No reason for it to work using the original cpp code and not thru HidSharp. The first write failure occurs on the call to restartportal. After that I am buried in status output from the portal but nothing else. Any further write messages give the same result</p><p>If anyone has a clue or suggestion on what to try next? That would be appreciated.</p><p>using System;<br />using System.Text;<br />using HidSharp;<br />using System.Linq;<br />using System.Collections.Generic;<br />using System.Threading;<br />using System.Threading.Tasks;<br />using HidSharp.Reports;<br />using HidSharp.Reports.Input;</p><p>namespace SkyReaderLib<br />{<br />&nbsp; &nbsp; public class PortalIO<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; public const int rw_buffer_size = 0x21;<br />&nbsp; &nbsp; &nbsp; &nbsp; public const int TIMEOUT = 30000;<br />&nbsp; &nbsp; &nbsp; &nbsp; public const int SKYLANDER_SIZE = 1024;<br />&nbsp; &nbsp; &nbsp; &nbsp; public const int MAX_STR = 255;<br />&nbsp; &nbsp; &nbsp; &nbsp; private HidDevice portal;<br />&nbsp; &nbsp; &nbsp; &nbsp; private HidStream portalStream;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; private bool initialized = false;</p><br /><p>&nbsp; &nbsp; &nbsp; &nbsp; public event EventHandler&lt;StatusChangedEventArgs&gt; StatusEvent;</p><br /><p>&nbsp; &nbsp; &nbsp; &nbsp; public static IEnumerable&lt;HidDevice&gt; ListPortals()<br />&nbsp; &nbsp; &nbsp; &nbsp; {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IEnumerable&lt;HidDevice&gt; devices = DeviceList.Local.GetHidDevices()<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .Where(x =&gt; (x.VendorID == 0x12ba || x.VendorID == 0x54c || x.VendorID == 0x1430)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &amp;&amp; (x.ProductID == 0x150 || x.ProductID == 0x967));</p><p>#if DEBUG<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (devices.Any())<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Found portal usb devices:&quot;);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; foreach (HidDevice device in devices)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine($&quot;\t{device.GetFriendlyName()}&quot;);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />#endif<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return devices;<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><br /><br /><br /><p>&nbsp; &nbsp; &nbsp; &nbsp; // Send a command to the portal<br />&nbsp; &nbsp; &nbsp; &nbsp; private void Write(byte[] message)<br />&nbsp; &nbsp; &nbsp; &nbsp; {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; byte[] buffer = new byte[portal.GetMaxOutputReportLength()];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; message.CopyTo(buffer, 0);<br />#if DEBUG<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Issued report out:&quot;);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine(string.Join(&quot; &quot;, buffer));<br />#endif<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; portalStream.Write(buffer);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; catch (Exception e)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine($&quot;Exception while issuing a report occured: {e}&quot;);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; </p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; private bool CheckResponse(out RWBlock response, byte expect)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; response = new RWBlock();<br />#if DEBUG<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;&gt;&gt;&gt; CheckResponse\n&quot;);<br />#endif</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int result = portalStream.Read(response.buffer, 0, rw_buffer_size);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (result &lt; 0)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw new Exception(&quot;Could not read response&quot;);</p><p>#if DEBUG<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;CheckResponse read = {0} bytes\n&quot;, result);<br />#endif</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; response.dwBytesTransferred = result;</p><p>&nbsp; &nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // found wireless USB but portal is not connected<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (response.buffer[0] == &#039;Z&#039;)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw new Exception(&quot;Found portal dongle, but portal not connected&quot;);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Status says no skylander on portal<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // if (response-&gt;buffer[0] == &#039;Q&#039; &amp;&amp; response-&gt;buffer[1] == 0)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //&nbsp; &nbsp; &nbsp;throw 11;</p><br /><p>#if DEBUG<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;&lt;&lt;&lt; CheckResponse\n&quot;);<br />#endif<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return (response.buffer[0] != expect);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; // <br />&nbsp; &nbsp; &nbsp; &nbsp; public void PortalStatus()<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; byte[] buffer = new byte[portal.GetMaxOutputReportLength()];</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; buffer[0] = 0;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; buffer[1] = (byte)&#039;S&#039;;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Write(buffer);<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><br /><p>&nbsp; &nbsp; &nbsp; &nbsp; // Start portal<br />&nbsp; &nbsp; &nbsp; &nbsp; public void RestartPortal()<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; byte[] buffer = new byte[portal.GetMaxOutputReportLength()];</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; buffer[0] = 0;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; buffer[1] = (byte)&#039;R&#039;;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Write(buffer);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; // Antenna up / activate<br />&nbsp; &nbsp; &nbsp; &nbsp; public void ActivatePortal(int active)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; byte[] buffer = new byte[portal.GetMaxOutputReportLength()];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; buffer[0] = 0;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; buffer[1] = (byte)&#039;A&#039;;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; buffer[2] = (byte)active;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Write(buffer);<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; // Set the portal color<br />&nbsp; &nbsp; &nbsp; &nbsp; public void SetPortalColor(byte r, byte g, byte b)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; byte[] buffer = new byte[portal.GetMaxOutputReportLength()];</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; buffer[0] = 0;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; buffer[1] = (byte)&#039;C&#039;;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; buffer[2] = r; // R<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; buffer[3] = g; // G<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; buffer[4] = b; // B</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Write(buffer);<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; // Release hPortalInstance<br />&nbsp; &nbsp; &nbsp; &nbsp; ~PortalIO()<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ActivatePortal(0);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; portalStream.Close();<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; public void Flash()<br />&nbsp; &nbsp; &nbsp; &nbsp; {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (; ; )<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ActivatePortal(1);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ActivatePortal(0);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><br /><br /><p>&nbsp; &nbsp; &nbsp; &nbsp; public PortalIO(HidDevice portal)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Connecting to portal.\n&quot;);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.portal = portal;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initialized = OpenPortal(portal);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (initialized)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RestartPortal();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ActivatePortal(1);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetPortalColor(0xC8, 0xC8, 0xC8);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Error initializing portal.&quot;);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; private bool OpenPortal(HidDevice portal)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine(portal.GetMaxInputReportLength());<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ReportDescriptor descriptor = portal.GetReportDescriptor();</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HidDeviceInputReceiver reciever = descriptor.CreateHidDeviceInputReceiver();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bool opened = portal.TryOpen(out portalStream);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var x = portal.GetReportDescriptor();</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; reciever.Start(portalStream);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; reciever.Received += OnReceiverReceived;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; portalStream.Closed += PortalStreamOnClosed;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return opened;<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; private void PortalStreamOnClosed(object? sender, EventArgs e)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Closed!&quot;);<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; private void OnReceiverReceived(object sender, EventArgs args)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var receiver = (HidDeviceInputReceiver)sender;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (receiver.Stream?.Device == null)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var length = receiver.Stream.Device.GetMaxInputReportLength();</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var buffer = new byte[length];</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (receiver.TryRead(buffer, 0, out Report report))<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Console.WriteLine($&quot;Received report with id: {report.ReportID}, type: {report.ReportType}&quot;);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; report.Read(buffer, 0, (bytes, offset, item, dataItem) =&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Console.WriteLine(string.Join(&quot; &quot;, bytes));<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; switch((char)buffer[1])<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case &#039;S&#039;:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StatusEvent?.Invoke(this, new StatusChangedEventArgs(buffer));<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; default:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine(&quot;Failed to read report.&quot;);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; catch (Exception e)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine($&quot;Exception while reading report occured: {e}&quot;);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><br /><br /><br /><p>&nbsp; &nbsp; }<br />}</p>]]></summary>
			<author>
				<name><![CDATA[bzuidgeest]]></name>
				<uri>https://swforum.seekye.com/user/14378/</uri>
			</author>
			<updated>2021-11-15T16:43:39Z</updated>
			<id>https://swforum.seekye.com/topic/10149/new/posts/</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[HidSharp Read Timeout]]></title>
			<link rel="alternate" href="https://swforum.seekye.com/topic/10148/new/posts/" />
			<summary type="html"><![CDATA[<p>I have been using HidSharp on a RPi and it is been running fine.<br />I allow up to 4 streams and poll each of the 4 devices/streams (if used and not null) every 50mS.<br />Up until now I have used with multiple Hid devices successfully. Mostly card reader devices (but with keyboards/mice that I ignore).<br />I now have a numeric keypad but every few times my app runs, it enumerates and identifies the device but no data is received until I restart the unit. The same keypad when using a text editor is working, just not on my reads in my app.<br />If polling, what Read Timeout would I use? The same or less than the polling rate, or set it high and do not worry?</p>]]></summary>
			<author>
				<name><![CDATA[geoff.atkinson]]></name>
				<uri>https://swforum.seekye.com/user/14354/</uri>
			</author>
			<updated>2021-07-14T22:56:49Z</updated>
			<id>https://swforum.seekye.com/topic/10148/new/posts/</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[HidSharp Freezed In Unity Edito for mac sometimes]]></title>
			<link rel="alternate" href="https://swforum.seekye.com/topic/10147/new/posts/" />
			<summary type="html"><![CDATA[<p>It works well in Unity2020.3.12f when I play in editor first time. <br />If I stop play and restart play or change some script in unity to make it recompile, it freeze unity editor forever.<br />And when device list changed, this freeze can be recovered and unity will run normally.</p><p>When I build into a mac application, if I call application.Quit() to exit application, it freeze to, and also can be recovered by change device list(plug some device in/out).</p><p>If not call GetDeviceList(), all about above will not happend.Also, DeviceListChanged callback will not be called.</p><p>I wanna know how to repair this issue.</p>]]></summary>
			<author>
				<name><![CDATA[engineerorca]]></name>
				<uri>https://swforum.seekye.com/user/14353/</uri>
			</author>
			<updated>2021-06-25T14:09:43Z</updated>
			<id>https://swforum.seekye.com/topic/10147/new/posts/</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Unable to open HID class device (OK) exception while open on Linux]]></title>
			<link rel="alternate" href="https://swforum.seekye.com/topic/10146/new/posts/" />
			<summary type="html"><![CDATA[<p>I have an issue on Linux. When I call Open method it throws &quot;Unable to open HID class device (OK)&quot;. But when I check CanOpen, it is true but cannot open. I also use TryOpen method&nbsp; but it didnt work. On windows side it works without any issue. I use HidSharpCore 1.2.1.1 at .net 5.0.&nbsp; </p><p>Please help me to solve this issue.<br /></p><div class="codebox"><pre><code>private static object lo = new object();
        public byte[] WriteAndWaitResponse(byte[] data)
        {

            lock (lo)
            {
                byte[] result;
                Console.WriteLine(&quot;vid:&quot; + vendorId + &quot; pid:&quot; + productId);

                if (!DeviceList.Local.TryGetHidDevice(out Dev, vendorId, productId))
                {
                    Console.WriteLine(&quot;Cannot GetHidDevice&quot;);
                    return null;
                }

                HidStream stream = null;
                if (Dev.CanOpen)
                {
                    
                    try
                    {
                        OpenConfiguration configuration = new OpenConfiguration();
                        stream = Dev.Open();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    if(stream == null)
                    {
                        Console.WriteLine(&quot;Try Open failed&quot;);
                    }
                }
                else
                {
                    Console.WriteLine(&quot;Cannot Open&quot;);
                }

                try
                {
                    stream.Write(data);
                    Console.WriteLine(&quot;data:&quot; + data.Length);
                    Thread.Sleep(100);
                    result = stream.Read();
                    Console.WriteLine(&quot;result:&quot; + result.Length);

                    return result;
                }
                catch (Exception ex)
                {

                    throw new RealDeviceException(&quot;error while writing to USB&quot;, ex);
                }
            }
        }</code></pre></div>]]></summary>
			<author>
				<name><![CDATA[azrael_yavuz]]></name>
				<uri>https://swforum.seekye.com/user/14348/</uri>
			</author>
			<updated>2021-03-05T13:08:59Z</updated>
			<id>https://swforum.seekye.com/topic/10146/new/posts/</id>
		</entry>
</feed>
