private void panel2_MouseDown(object sender, MouseEventArgs e)
 {
     if (OpenedPad != null)
     {
         OpenedPad.close();
     }
     this.Close();
 }
Esempio n. 2
0
 public void close()
 {
     if (connected)
     {
         device.close();
     }
 }
Esempio n. 3
0
        // Apologies for the repeated code, however i feel it provides a better demonstration
        // of the functionality of this code.
        public void useSynchronousOperation()
        {
            //Get the details of all connected USB HID devices
            HIDDevice.interfaceDetails[] devices = HIDDevice.getConnectedDevices();

            //Arbitrarily select one of the devices which we found in the previous step
            //record the details of this device to be used in the class constructor
            int    selectedDeviceIndex = 0;
            ushort VID        = devices[selectedDeviceIndex].VID;
            ushort PID        = devices[selectedDeviceIndex].PID;
            int    SN         = devices[selectedDeviceIndex].serialNumber;
            string devicePath = devices[selectedDeviceIndex].devicePath;

            //create a handle to the device by calling the constructor of the HID class
            //This can be done using either the VID/PID/Serialnumber, or the device path (string)
            //all of these details are available from the HIDDevice.interfaceDetails[] struct array created above
            //The "false" boolean in the constructor tells the class we only want synchronous operation
            HIDDevice device = new HIDDevice(devicePath, false);

            //OR, the normal usage when you know the VID and PID of the device
            //HIDDevice device = new HIDDevice(VID, PID, (ushort)SN, false);

            //Write some data to the device (the write method throws an exception if the data is longer than the report length
            //specified by the device, this length can be found in the HIDDevice.interfaceDetails struct)
            byte[] writeData = { 0x00, 0x01, 0x02, 0x03, 0x04 };
            device.write(writeData);    //Its that easy!!

            //Read some data synchronously from the device. This method blocks the calling thread until the data
            //is returned. This takes 1-20ms for most HID devices
            byte[] readData = device.read();    //again, that easy!

            //close the device to release all handles etc
            device.close();
        }
Esempio n. 4
0
 //close the device to release all handles etc
 public void Disconnect()
 {
     if (device != null)
     {
         device.close();
         device = null;
     }
 }
Esempio n. 5
0
 //-----------------------------------------------------------------------------------------------------------------------------------------------------------------
 protected void closeDevice()
 {
     if (mHIDDevice != null)
     {
         mHIDDevice.close();
         mHIDDevice = null;
     }
     mDeviceConnect = DEVICE_CONNENT.DC_CLOSE;
 }
 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (OpenedPad != null)
     {
         OpenedPad.close();
     }
     OpenedPad = new HIDDevice(UtilValues.PublicValue.nanoPads[comboBox1.SelectedIndex].devicePath, false);
     //读取配置
 }
        public static void FindNanoPad()
        {
            if (UtilValues.PublicValue.nanoPads.Length != 0)
            {
                Array.Clear(UtilValues.PublicValue.nanoPads, 0, UtilValues.PublicValue.nanoPads.Length);
                Array.Resize(ref UtilValues.PublicValue.nanoPads, 0);
            }
            HIDDevice.interfaceDetails[] Pads = HIDDevice.getConnectedPads();
            foreach (HIDDevice.interfaceDetails Pad in Pads)
            {
                SayobotNanoPad pad = new SayobotNanoPad
                {
                    devicePath = Pad.devicePath,
                    ProductID  = Pad.PID
                };
                pad.ReadingPadSettings();
                HIDDevice PadDevice = new HIDDevice(pad.devicePath, false);
                byte[]    writeData = CalcSHA(new byte[] { 0x02, 0x00, 0x00 });
                PadDevice.write(writeData);
                System.Threading.Thread.Sleep(100);
                byte[] readData = PadDevice.read();
                if (readData[1] == 0)
                {
                    pad.OSVersion = readData[4].ToString();
                }
                else
                {
                    pad.OSVersion = "Unknown";
                }

                writeData = CalcSHA(new byte[] { 0x02, 0x08, 0x01, 0x00 });
                PadDevice.write(writeData);
                System.Threading.Thread.Sleep(100);
                readData = PadDevice.read();
                if (readData[0] != 0xff)
                {
                    byte[] nameEncode = new byte[readData[2]];
                    Array.Copy(readData, 3, nameEncode, 0, readData[2]);
                    nameEncode = ChangeToSystemUnicodeEncoding(nameEncode);
                    pad.Name   = Encoding.Unicode.GetString(nameEncode);
                }
                else
                {
                    pad.Name = Pad.product;
                }

                PadDevice.close();

                Array.Resize(ref UtilValues.PublicValue.nanoPads, UtilValues.PublicValue.nanoPads.Length + 1);
                UtilValues.PublicValue.nanoPads[UtilValues.PublicValue.nanoPads.Length - 1] = pad;
            }
        }
Esempio n. 8
0
        //Whenever a report comes in, this method will be called and the data will be available! Like magic...
        void device_dataReceived(byte[] message)
        {
            byte[] mydata = new byte[64];

            for (int i = 0; i < 64; i++)
            {
                mydata[i] = message[i + 1];
            }

            if (this.InvokeRequired)
            {
                this.Invoke((Action)(() => { Proccess_HID_Data_MCU_to_PC(mydata); }));
            }

            else
            {
                Proccess_HID_Data_MCU_to_PC(mydata);
            }



            string NewMsg = "";

            SetTextBox("");

            NewMsg = "";
            int wrap = 0;

            for (int i = 0; i < message.Length; i++)
            {
                NewMsg += message[i].ToString("X2") + " ";
                wrap++;
                if (wrap > 15)
                {
                    wrap    = 0;
                    NewMsg += "\r\n";
                }
            }
            NewMsg += "\r\n";
            AppendTextBox(NewMsg);
            if (CloseDev)
            {
                if (device.deviceConnected)
                {
                    device.close();
                }
            }
        }
Esempio n. 9
0
        public void startAsyncOperation()
        {
            //Get the details of all connected USB HID devices
            HIDDevice.interfaceDetails[] devices = HIDDevice.getConnectedDevices();

            //Arbitrarily select one of the devices which we found in the previous step
            //record the details of this device to be used in the class constructor
            int    selectedDeviceIndex = 0;
            ushort VID        = devices[selectedDeviceIndex].VID;
            ushort PID        = devices[selectedDeviceIndex].PID;
            int    SN         = devices[selectedDeviceIndex].serialNumber;
            string devicePath = devices[selectedDeviceIndex].devicePath;

            //create a handle to the device by calling the constructor of the HID class
            //This can be done using either the VID/PID/Serialnumber, or the device path (string)
            //all of these details are available from the HIDDevice.interfaceDetails[] struct array created above
            //The "true" boolean in the constructor tells the class we want asynchronous operation this time
            HIDDevice device = new HIDDevice(devicePath, true);

            //OR, the normal usage when you know the VID and PID of the device
            //HIDDevice device = new HIDDevice(VID, PID, (ushort)SN, true);

            //next create the event handler for the incoming reports
            device.dataReceived += new HIDDevice.dataReceivedEvent(device_dataReceived);

            //Write some data to the device (the write method throws an exception if the data is longer than the report length
            //specified by the device, this length can be found in the HIDDevice.interfaceDetails struct)
            //The write method is identical to the synchronous mode of operation
            byte[] writeData = { 0x00, 0x01, 0x02, 0x03, 0x04 };
            device.write(writeData);    //Its that easy!!

            //Send your program off to do other stuff here, wait for UI events etc
            //When a report occurs, the device_dataReceived(byte[] message) method will be called
            System.Threading.Thread.Sleep(100);

            //close the device to release all handles etc
            device.close();
        }