Help code updating

I think i know what he means, this happen when you debug, its on a breakpoint, you then stop and press debug again - then it sometimes cannot attach debugger, you just reset then

I have written the following code as per tutorials Data Buses USB Client for a keyboard but I don’t know why the instantiation

var kb = new Keyboard(usbclientController, usbClientSetting);

gives error that I should pass two parameters in the function Keyboard (unit id byte InterfaceIndex)

do you have any idea or example program for usb keyboard ?

What exactly are the error message(s) you are seeing?

the error says that I have to pass an id and interfaceindex in the function Keyboard not usbclientController and usbClientSetting

Please show all of your initialization code.

class Program
{
static void Main()
{
var usbClientSetting = new UsbClientSetting()
{
ManufactureName = “ttttttt”,
ProductName = “YYY2”,
VendorId = 0x1F26,
ProductId = 0x12,
SerialNumber = “01”,

        };
        var usbclientController = UsbClientController.GetDefault();
        var kb = new Keyboard(usbclientController, usbClientSetting);
        var key = new Key[] { Key.G, Key.H, Key.I, Key.Space, Key.E, Key.L, Key.E, Key.C, Key.T, Key.R, Key.O, Key.N, Key.I, Key.C, Key.S };
        kb.Enable();
        while (kb.DeviceState != DeviceState.Configured)
            Thread.Sleep(100);// wait or use events

        kb.Press(Key.LeftShift);// hold shift down
        for (var i = 0; i < key.Length; i++)
        {
            kb.Stroke(key[i]);
            Thread.Sleep(500);// type it twice a second
        }
        kb.Release(Key.LeftShift)

        var usbHostController = UsbHostController.GetDefault();

        usbHostController.OnConnectionChangedEvent += UsbHostController_OnConnectionChangedEvent;

        usbHostController.Enable();

        Thread.Sleep(Timeout.Infinite);



        
    }

Are you trying to build a key capture device?

I am not comfortable providing assistance. I am out.

I tried to follow but I am confused. What have you gotten to work so far? Do you have a blinking LED working? Can you load and debug the blink LED?

Maybe we should do it step by step

2 Likes

What firmware version are you using? Look like too old version.

I have copied the program for a keyboard as UsbCleint but when I am in debugging mode I get an error
“System.NotSupportedException” in this function Acquire()

  public UsbClientControllerApiWrapper(NativeApi api)
        {
            this.Api = api;

            this.impl = api.Implementation;

            this.Acquire();

            this.dataReceivedDispatcher = NativeEventDispatcher.GetDispatcher("GHIElectronics.TinyCLR.NativeEventNames.UsbClient.DataReceived");
            this.dataReceivedDispatcher.OnInterrupt += (apiName, d0, d1, d2, d3, ts) => { if (this.Api.Name == apiName) this.dataReceivedCallbacks?.Invoke(null, (uint)d0); };

            this.deviceStateChangedDispatcher = NativeEventDispatcher.GetDispatcher("GHIElectronics.TinyCLR.NativeEventNames.UsbClient.DeviceStateChanged");
            this.deviceStateChangedDispatcher.OnInterrupt += (apiName, d0, d1, d2, d3, ts) => { if (this.Api.Name == apiName) this.deviceStateChangedCallbacks?.Invoke(null, (DeviceState)d0); };

        }

Did you switch to serial debugging to free up USB?

no but how to do that switch from DebugInterface to Serial. do you have a lien where the info about it ?

The info you need is right on the USB tutorial page

I followed the instructions on the USB-Tutorial but it is not sufficient

It works for us. Please provide more info.

It did not work but I have known the problem that I use a USB for debugging, and the same for the USB client that was the problem

That is exactly what I have been saying and what the tutorial clearly states.