コード例 #1
0
        static void Main(string[] args)
        {
            // Get a list of devices that match vid and pid
            // This list should NEVER have more than one element.
            Console.WriteLine("USB HID Test");
            String[] list = usb.getDeviceList();
            Console.WriteLine("Devices with vid = 0x046d and pid = 0xc245: " + list.Length);

            // usb.Connect() returns false if the device is not physically connected.
            while (!usb.Connect())
            {
                Thread.Sleep(1000);
                Console.WriteLine("Not Connected");
            }


            Console.WriteLine("Connected!");


            // This only attaches "myEventCatcher" to the UsbBufferEvent.
            Console.WriteLine("Enabling Buffer Event...");
            usb.enableUsbBufferEvent(new System.EventHandler(myEventCatcher));


            // After calling usb.startRead(), "myEventCacher" will be called whenever the device sends data to the PC.
            Console.WriteLine("Press a key to begin data dump.");
            Console.ReadKey();
            usb.startRead();


            // Device is configured and reading, you can keep on doing your important shit.
            while (true)
            {
                if (!usb.Connect())
                {
                    Console.WriteLine("Device Disconnected");
                }

                Thread.Sleep(1000);
            }
        }
コード例 #2
0
ファイル: G13Engine.cs プロジェクト: flyingoverclouds/G13.Net
        /// <summary>
        /// Connect to the first G13 device available and start listening HID event.
        /// If connexion succeeded, the property DevicePath is valued
        /// </summary>
        /// <returns>true if connection succeeded, false in case of failure</returns>
        public bool Connect()
        {
            usbInterface = new USBHIDDRIVER.USBInterface(G13UsbVendorID, G13UsbProductID);
            if (usbInterface == null)
            {
                Console.WriteLine($"ERROR: Unable to instantiate USb interface for {G13UsbVendorID} {G13UsbProductID} ");
                return(false);
            }

            if (!usbInterface.Connect())
            {
                Console.WriteLine("ERROR: Unable to connect to G13 Device!!");
                usbInterface = null;
                return(false);
            }

            usbInterface.EnableUsbBufferEvent(UsbHidEventHandler); // Register event handler to receive HID event
            usbInterface.StartRead();
            return(true);
        }
コード例 #3
0
        private void btnRocheGetData_Click(object sender, EventArgs e)
        {
            usb = new USBHIDDRIVER.USBInterface("vid_173a", "pid_2106");

            string [] devices = usb.getDeviceList();
            usb.enableUsbBufferEvent(new EventHandler(Accuchek_ReceivedData));
            System.Threading.Thread.Sleep(100);
            Console.WriteLine("Connect: " + usb.Connect().ToString());

            //string temp = Convert.ToString(Convert.ToChar(01));
            //temp += Convert.ToString(Convert.ToChar(44));
            //temp += Convert.ToString(Convert.ToChar(01));

            //commandindex = 1;
            //commands.Clear();

            //commands.Add(temp);
            //commands.Add("\n");
            //commands.Add("C4\n");
            //commands.Add("C 3\n");
            //commands.Add("S 1\n");
            //commands.Add("S 2\n");
            //commands.Add("`\n");
            //commands.Add("S 3\n");

            //Send_AccuChek_Command(commandindex++);

            commands.Add(new byte[] { 0x01, 0x13 });
            commands.Add(new byte[] { 0x01, 0x44, 0x01 });
            commands.Add(new byte[] { 0x01, 0x44, 0x01 });
            commands.Add(new byte[] { 0x01, 0x43, 0x01, 0x02 });
            commands.Add(new byte[] { 0x01, 0x45 });
            commands.Add(new byte[] { 0x01, 0x43, 0x04, 0x01 });
            commands.Add(new byte[] { 0x01, 0x44 });
            Send_AccuChek_Command(commands[commandindex++]);

            usb.startRead();
        }
コード例 #4
0
ファイル: TestFixture.cs プロジェクト: sunrise20000/Test
        public void sendStartCMD()
        {
            byte[] startCMD = new byte[8];
            //Start
            startCMD[0] = 255;
            //Mode
            startCMD[1] = 0;
            //USync
            startCMD[2] = 28;
            //ULine
            startCMD[3] = 20;
            //tSync
            startCMD[4] = 20;
            //tRepeat - High
            startCMD[5] = 0;
            //tRepeat - Low
            startCMD[6] = 0x01;
            //BusMode
            startCMD[7] = 0xF4;
            //send the command

            Assert.IsTrue(usbI.Connect());
            Assert.IsTrue(usbI.write(startCMD));
        }
コード例 #5
0
 private Hardware()
 {
     // Try and connect on init.
     usb.Connect();
     FirstTime = true;
 }
コード例 #6
0
        private void btnRocheGetData_Click(object sender, EventArgs e)
        {
            usb = new USBHIDDRIVER.USBInterface("vid_173a", "pid_2106");
            
            string [] devices = usb.getDeviceList();
            usb.enableUsbBufferEvent(new EventHandler(Accuchek_ReceivedData));
            System.Threading.Thread.Sleep(100);
            Console.WriteLine("Connect: " + usb.Connect().ToString());

            //string temp = Convert.ToString(Convert.ToChar(01));
            //temp += Convert.ToString(Convert.ToChar(44));
            //temp += Convert.ToString(Convert.ToChar(01));

            //commandindex = 1;
            //commands.Clear();

            //commands.Add(temp);
            //commands.Add("\n");
            //commands.Add("C4\n");
            //commands.Add("C 3\n");
            //commands.Add("S 1\n");
            //commands.Add("S 2\n");
            //commands.Add("`\n");
            //commands.Add("S 3\n");
            
            //Send_AccuChek_Command(commandindex++);

            commands.Add(new byte[] { 0x01, 0x13 });
            commands.Add(new byte[] { 0x01 ,0x44, 0x01});
            commands.Add(new byte[] { 0x01, 0x44, 0x01 });
            commands.Add(new byte[] { 0x01, 0x43, 0x01, 0x02 });
            commands.Add(new byte[] { 0x01, 0x45 });
            commands.Add(new byte[] { 0x01, 0x43, 0x04, 0x01 });
            commands.Add(new byte[] { 0x01, 0x44 });
            Send_AccuChek_Command(commands[commandindex++]);

            usb.startRead();
        }