Ejemplo n.º 1
0
        ///  <summary>
        ///  Perform actions that must execute when the program starts.
        ///  </summary>
        private void Startup()
        {
            try
            {
                MyHid = new Hid();
                InitializeDisplay();

                tmrContinuousDataCollect = new System.Timers.Timer(1000);
                tmrContinuousDataCollect.Elapsed  += new ElapsedEventHandler(OnDataCollect);
                tmrContinuousDataCollect.Stop();
                tmrContinuousDataCollect.SynchronizingObject = this;

                tmrReadTimeout = new System.Timers.Timer(5000);
                tmrReadTimeout.Elapsed += new ElapsedEventHandler(OnReadTimeout);
                tmrReadTimeout.Stop();

                //  Default USB Vendor ID and Product ID:

                txtVendorID.Text = "0925";
                txtProductID.Text = "7001";
            }
            catch ( Exception ex )
            {
                DisplayException( this.Name, ex );
                throw ;
            }
        }
Ejemplo n.º 2
0
		///  <summary>
		///  Perform actions that must execute when the program starts.
		///  </summary>

		private void Startup()
		{
			const Int32 periodicTransferInterval = 1000;
			try
			{
				_myHid = new Hid();
				InitializeDisplay();

				_periodicTransfers = new System.Timers.Timer(periodicTransferInterval);
				_periodicTransfers.Elapsed += DoPeriodicTransfers;
				_periodicTransfers.Stop();
				_periodicTransfers.SynchronizingObject = this;

				//  Default USB Vendor ID and Product ID:

				txtVendorID.Text = "0925";
				txtProductID.Text = "7001";

				GetVendorAndProductIDsFromTextBoxes(ref _myVendorId, ref _myProductId);

				DeviceNotificationsStart();
				FindDeviceUsingWmi();
				FindTheHid();
			}
			catch (Exception ex)
			{
				DisplayException(Name, ex);
				throw;
			}
		}
Ejemplo n.º 3
0
        public bool do_connect(List <string> msgs)
        {
            if (m_DeviceDetected)
            {
                msgs.Add("USB device: was already open");
                return(m_DeviceDetected);
            }

            msgs.Add("USB device: connecting...");

            Boolean deviceFound = false;
            Guid    hidGuid     = Guid.Empty;

            String[] devicePathName = new String[128];
            Int32    myVendorID     = 0x16c0;
            Int32    myProductID    = 0x05df;
            Int32    memberIndex    = 0;
            Boolean  success        = false;

            Hid.HidD_GetHidGuid(ref hidGuid);

            deviceFound = m_DeviceManagement.FindDeviceFromGuid(hidGuid, ref devicePathName);
            if (deviceFound)
            {
                memberIndex = 0;

                do
                {
                    m_hidHandle = FileIO.CreateFile(devicePathName[memberIndex], 0, FileIO.FILE_SHARE_READ | FileIO.FILE_SHARE_WRITE, IntPtr.Zero, FileIO.OPEN_EXISTING, 0, 0);
                    if (!m_hidHandle.IsInvalid)
                    {
                        m_Hid.DeviceAttributes.Size = Marshal.SizeOf(m_Hid.DeviceAttributes);
                        success = Hid.HidD_GetAttributes(m_hidHandle, ref m_Hid.DeviceAttributes);
                        if (success)
                        {
                            if ((m_Hid.DeviceAttributes.VendorID == myVendorID) && (m_Hid.DeviceAttributes.ProductID == myProductID))
                            {
                                m_DeviceDetected = true;

                                //  Save the DevicePathName for OnDeviceChange().

                                m_DevicePathName = devicePathName[memberIndex];
                            }
                            else
                            {
                                //  It's not a match, so close the handle.

                                m_DeviceDetected = false;
                                m_hidHandle.Close();
                            }
                        }
                        else
                        {
                            m_DeviceDetected = false;
                            m_hidHandle.Close();
                        }
                    }
                    memberIndex = memberIndex + 1;
                }while (!((m_DeviceDetected || (memberIndex == devicePathName.Length))));

                if (m_DeviceDetected)
                {
                    msgs.Add("USB device: found the device on the bus");

                    m_Hid.Capabilities = m_Hid.GetDeviceCapabilities(m_hidHandle);

                    m_readHandle  = FileIO.CreateFile(m_DevicePathName, FileIO.GENERIC_READ, FileIO.FILE_SHARE_READ | FileIO.FILE_SHARE_WRITE, IntPtr.Zero, FileIO.OPEN_EXISTING, FileIO.FILE_FLAG_OVERLAPPED, 0);
                    m_writeHandle = FileIO.CreateFile(m_DevicePathName, FileIO.GENERIC_WRITE, FileIO.FILE_SHARE_READ | FileIO.FILE_SHARE_WRITE, IntPtr.Zero, FileIO.OPEN_EXISTING, 0, 0);
                    m_Hid.FlushQueue(m_readHandle);

                    Hid.InFeatureReport  myInFeatureReport  = new Hid.InFeatureReport();
                    Hid.OutFeatureReport myOutFeatureReport = new Hid.OutFeatureReport();
                    newOutBuffer();
                    newInBuffer();
                }
                else
                {
                    msgs.Add("USB device: cannot find the device on the bus");
                }
            }

            return(m_DeviceDetected);
        }