/// <summary> /// Переопределение строки продукта для устройства. /// При вызове происходит закрытие текущего подключения (если есть), далее происходит поиск и подключение к устройству с новыми параметрами. /// </summary> /// <param name="DevPrd">Указываем сюда глобальную константу DeviceProduct, с описанием продукта</param> /// <returns>Возвращает True - если устройство успешно найденно, иначе False</returns> public bool UpdateDeviceProduct(string Product) { bool success = true; if (specified_device != null) { specified_device.Dispose(); specified_device = null; if (OnSpecifiedDeviceRemoved != null) { this.OnSpecifiedDeviceRemoved(this, new EventArgs()); } } device_product = Product; CheckDevicePresent(); if (SpecifiedDevice == null) { success = false; } return(success); }
public bool SendData(byte[] data) { #if SHOW_USB_DATA Console.WriteLine("SendData " + SpecifiedDevice.ByteArrayToString(data)); #endif SpecifiedOutputReport specifiedOutputReport = new SpecifiedOutputReport(this); specifiedOutputReport.SendData(data); try { base.Write(specifiedOutputReport); if (this.DataSend != null) { this.DataSend(this, new DataSendEventArgs(data)); } } catch (GException0 gException) { Console.WriteLine(gException.Message); return(false); } catch (Exception ex) { Console.WriteLine(ex.Message); return(false); } return(true); }
/// <summary> /// Проверка подключения и поддержание в открытом состоянии доступа к устройству. /// Переподключение к устройству с подходящими PID\VID и соответствующим DeviceProduct /// </summary> /// <param name="OpenState">Если надо поддерживать связь, то True</param> /// <param name="Product">Указываем сюда глобальную константу DeviceProduct, с описанием продукта</param> /// <returns>Возвращает True - если устройство успешно найденно, иначе False</returns> public bool Open(bool OpenState, string Product) { bool success = true; if (OpenState) { CheckDevicePresent(); if (SpecifiedDevice == null) { success = false; } } else { CheckDevicePresent(); if (SpecifiedDevice != null) { specified_device.Dispose(); specified_device = null; this.OnSpecifiedDeviceRemoved(this, new EventArgs()); } else { success = false; } } return(success); }
/// <summary> /// Checks the devices that are present at the moment and checks if one of those /// is the device you defined by filling in the product id and vendor id. /// </summary> public void CheckDevicePresent() { try { //Mind if the specified device existed before. bool history = false; if (specified_device != null) { history = true; } specified_device = SpecifiedDevice.FindSpecifiedDevice(this.vendor_id, this.product_id); // look for the device on the USB bus if (specified_device != null) // did we find it? { if (OnSpecifiedDeviceArrived != null) { this.OnSpecifiedDeviceArrived(this, new EventArgs()); specified_device.DataRecieved += new DataRecievedEventHandler(OnDataRecieved); specified_device.DataSend += new DataSendEventHandler(OnDataSend); } } else { if (OnSpecifiedDeviceRemoved != null && history) { this.OnSpecifiedDeviceRemoved(this, new EventArgs()); } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public UsbHidPort() { //initializing in initial state product_id = 0; vendor_id = 0; specified_device = null; device_class = Win32Usb.HIDGuid; }
public UsbScopeDevice() { scopeDevice = SpecifiedDevice.FindSpecifiedDevice(0x4242, 3); if (scopeDevice != null) { scopeDevice.DataRecieved += OnDataReceived; } }
public bool IsDevicePresent() { if (specified_device == null) { specified_device = SpecifiedDevice.FindSpecifiedDevice(this.vendor_id, this.product_id); } return(specified_device != null); }
public bool ReceiveData(byte[] data) { bool retVal = base.BeginAsyncRead(data); #if SHOW_USB_DATA Console.WriteLine("ReceiveData " + SpecifiedDevice.ByteArrayToString(data)); #endif return(retVal); }
public UsbHidPort() { product_id = 0; vendor_id = 0; specified_device = null; device_product = null; device_class = Win32Usb.HIDGuid; InitializeComponent(); }
public UsbHidPort() { //initializing in initial state product_id = 0; vendor_id = 0; specified_device = null; device_class = Win32Usb.HIDGuid; InitializeComponent(); }
public UsbHidPort(IContainer container) { //initializing in initial state product_id = 0; vendor_id = 0; specified_device = null; device_class = Win32Usb.HIDGuid; container.Add(this); InitializeComponent(); }
/// <summary> /// Закрываем текущее подключение к устройству, если есть таковое. /// </summary> public void Close() { if (specified_device != null) { specified_device.Dispose(); specified_device = null; if (OnSpecifiedDeviceRemoved != null) { this.OnSpecifiedDeviceRemoved(this, new EventArgs()); } } }
public bool SendData(byte[] data) { #if false switch (data[0]) { case 0x52: Console.WriteLine(data[1] * 256 + data[2]); break; case 0x57: Console.WriteLine(data[1] * 256 + data[2]); break; } Console.WriteLine("SendData " + SpecifiedDevice.ByteArrayToString(data)); #endif SpecifiedOutputReport specifiedOutputReport = new SpecifiedOutputReport(this); specifiedOutputReport.SendData(data); try { base.Write(specifiedOutputReport); if (this.DataSend != null) { this.DataSend(this, new DataSendEventArgs(data)); } } catch (GException0 gException) { Console.WriteLine(gException.Message); return(false); } catch (Exception ex) { Console.WriteLine(ex.Message); return(false); } return(true); }
public void SetSpecifiedDevice(SpecifiedDevice specifiedDevice) { try { //Mind if the specified device existed before. bool history = false; if (specified_device != null) { history = true; } specified_device = specifiedDevice; if (specified_device != null) // did we find it? { if (OnSpecifiedDeviceArrived != null) { this.OnSpecifiedDeviceArrived(this, new EventArgs()); specified_device.DataRecieved += new DataRecievedEventHandler(OnDataRecieved); specified_device.DataSend += new DataSendEventHandler(OnDataSend); } } else { if (OnSpecifiedDeviceRemoved != null && history) { this.OnSpecifiedDeviceRemoved(this, new EventArgs()); } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
/// <summary> /// Checks the devices that are present at the moment and checks if one of those /// is the device you defined by filling in the product id and vendor id. /// </summary> public void CheckDevicePresent() { try { //Mind if the specified device existed before. bool history = false; if(specified_device != null ){ history = true; } specified_device = SpecifiedDevice.FindSpecifiedDevice(this.vendor_id, this.product_id); // look for the device on the USB bus if (specified_device != null) // did we find it? { if (OnSpecifiedDeviceArrived != null) { this.OnSpecifiedDeviceArrived(this, new EventArgs()); specified_device.DataRecieved += new DataRecievedEventHandler(OnDataRecieved); specified_device.DataSend += new DataSendEventHandler(DataSend); } } else { if (OnSpecifiedDeviceRemoved != null && history) { this.OnSpecifiedDeviceRemoved(this, new EventArgs()); } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public bool IsDevicePresent() { if (specified_device == null) specified_device = SpecifiedDevice.FindSpecifiedDevice(this.vendor_id, this.product_id); return specified_device != null; }