static void Main()
        {
            // visit link for demo: https://ghi-electronics.github.io/TinyCLR-WebUSB/
            gpio = GpioController.GetDefault();

            var usbclientController = UsbClientController.GetDefault();

            var usbClientSetting = new UsbClientSetting
            {
                ProductName   = "TinyCLR WebUsb",
                InterfaceName = "TinyCLR WebUsb",
                MaxPower      = RawDevice.MAX_POWER,
                SerialNumber  = "12344321",
                Guid          = "{A5FDFBF7-E5EE-489D-8037-48E2EED80A29}",
                Mode          = UsbClientMode.WinUsb,
            };

            webUsb = new WinUsb(usbclientController, usbClientSetting);
            webUsb.DeviceStateChanged += (a, b) => Debug.WriteLine("Connection changed.");
            webUsb.DataReceived       += (a, count) => Debug.WriteLine("Data received:" + count);

            webUsb.Enable();

            while (webUsb.DeviceState != DeviceState.Configured)
            {
                ;
            }
            Debug.WriteLine("UsbClient Connected");

            while (true)
            {
                try
                {
                    var command = ReadString();
                    HandleCommand(command);
                    SendString("Success");
                }
                catch (Exception ex)
                {
                    SendString(ex.Message);
                }
            }
        }
Exemple #2
0
        static void Main()
        {
            gpio = GpioController.GetDefault();

            var usbclientController = UsbClientController.GetDefault();

            var usbClientSetting = new UsbClientSetting
            {
                ProductName   = "TinyCLR Serial WebUsb",
                InterfaceName = "TinyCLR Serial WebUsb",
                MaxPower      = RawDevice.MAX_POWER,
                SerialNumber  = "12344321",
                Mode          = UsbClientMode.Cdc,
            };

            webUsb = new Cdc(usbclientController, usbClientSetting);
            webUsb.DeviceStateChanged += (a, b) => Debug.WriteLine("Connection changed.");
            webUsb.DataReceived       += (a, count) => Debug.WriteLine("Data received:" + count);

            webUsb.Enable();

            while (webUsb.DeviceState != DeviceState.Configured)
            {
                ;
            }
            Debug.WriteLine("UsbClient Connected");

            while (true)
            {
                try {
                    var command = ReadString();
                    HandleCommand(command);
                    SendString("Success");
                }
                catch (Exception ex) {
                    SendString(ex.Message);
                }
            }
        }