public PortUtil(string usbVid, string usbPid, string endpointId) { Int32 vid = Int32.Parse(usbVid, NumberStyles.HexNumber); Int32 pid = Int32.Parse(usbPid, NumberStyles.HexNumber); _usbFinder = new UsbDeviceFinder(vid, pid); _endpointId = GetEndpointId(endpointId); _portType = PortType.USB; }
/// <summary> /// Initializes a new instance of the LIB USB class. /// </summary> /// <param name="vendorId">Vendor identifier.</param> /// <param name="productId">Product identifier.</param> /// <param name="readId">Read identifier.</param> /// <param name="writeId">Write identifier.</param> public LibUsb(short vendorId, short productId, ReadEndpointID readId, WriteEndpointID writeId) { this.vendorId = vendorId; this.productId = productId; this.readId = readId; this.writeId = writeId; myUsbFinder = new UsbDeviceFinder(this.vendorId, this.productId); }
public UsbDevStream(IUsbDevice dev, WriteEndpointID writePipe, ReadEndpointID readPipe) { device = dev; WritePipe = writePipe; ReadPipe = readPipe; writer = device.OpenEndpointWriter(writePipe); reader = device.OpenEndpointReader(readPipe); Flush(); }
public PTPDevice(UsbDevice dev) { _Device = dev; PTPSupported = false; _Name = dev.Info.ProductString; // TODO: try get better name Reader = null; Writer = null; ConfigurationID = 1; InterfaceID = 0; ReaderEndpointID = ReadEndpointID.Ep01; WriterEndpointID = WriteEndpointID.Ep02; }
public PTPDevice(UsbDevice dev) { this.Device = dev; this.PTPSupported = false; this._Name = dev.Info.ProductString; // TODO: try get better name this.Reader = null; this.Writer = null; this.ConfigurationID = 1; this.InterfaceID = 0; this.ReaderEndpointID = ReadEndpointID.Ep01; this.WriterEndpointID = WriteEndpointID.Ep02; }
public UsbLibDotNetHIDDevice() { this.m_vendorID = -1; this.m_productID = -1; this.m_configID = 255; this.m_interfaceID = 255; this.m_readEndpoint = ReadEndpointID.Ep01; this.m_writeEndpoint = WriteEndpointID.Ep01; this.m_usbDevice = null; this.m_usbReader = null; this.m_usbWriter = null; }
/// <summary> /// Opens an endpoint for writing /// </summary> /// <param name="writeEndpointID">Endpoint number for read operations.</param> /// <param name="endpointType">The type of endpoint to open.</param> /// <returns>A <see cref="UsbEndpointWriter"/> class ready for writing. If the specified endpoint is already been opened, the original <see cref="UsbEndpointWriter"/> class is returned.</returns> public virtual UsbEndpointWriter OpenEndpointWriter(WriteEndpointID writeEndpointID, EndpointType endpointType) { foreach (UsbEndpointBase activeEndpoint in ActiveEndpoints) { if (activeEndpoint.EpNum == (byte)writeEndpointID) { return((UsbEndpointWriter)activeEndpoint); } } UsbEndpointWriter epNew = new UsbEndpointWriter(this, writeEndpointID, endpointType); return((UsbEndpointWriter)mActiveEndpoints.Add(epNew)); }
/// <summary> /// Opens an endpoint for writing /// </summary> /// <param name="writeEndpointID">Endpoint number for read operations.</param> /// <param name="endpointType">The type of endpoint to open.</param> /// <returns>A <see cref="UsbEndpointWriter"/> class ready for writing. If the specified endpoint is already been opened, the original <see cref="UsbEndpointWriter"/> class is returned.</returns> public virtual UsbEndpointWriter OpenEndpointWriter(WriteEndpointID writeEndpointID, EndpointType endpointType) { foreach (UsbEndpointBase activeEndpoint in ActiveEndpoints) { if (activeEndpoint.EpNum == (byte)writeEndpointID) { return((UsbEndpointWriter)activeEndpoint); } } byte altIntefaceID = mClaimedInterfaces.Count == 0 ? UsbAltInterfaceSettings[0] : UsbAltInterfaceSettings[mClaimedInterfaces[mClaimedInterfaces.Count - 1]]; UsbEndpointWriter epNew = new UsbEndpointWriter(this, altIntefaceID, writeEndpointID, endpointType); return((UsbEndpointWriter)mActiveEndpoints.Add(epNew)); }
/// <summary> /// ctor. /// </summary> /// <param name="shouter">The shouter instance.</param> /// <param name="vendorId">The vendor id.</param> /// <param name="productId">The product id.</param> /// <param name="configuration">The configuration id.</param> /// <param name="@interface">The interface id.</param> /// <param name="readEndpointInt">The read endpoint id.</param> /// <param name="writeEndpointInt">The write end point id.</param> public RawUsbBulkDevice( IShouter shouter, int vendorId, int productId, byte configuration, int @interface, int readEndpointInt, int writeEndpointInt) { Shouter = shouter; VendorId = vendorId; ProductId = productId; Configuration = configuration; Interface = @interface; ReadEndpointID = (ReadEndpointID)readEndpointInt; WriteEndpointID = (WriteEndpointID)writeEndpointInt; Init(); }
/// <summary> /// Opens a <see cref="EndpointType.Bulk"/> endpoint for writing /// </summary> /// <param name="writeEndpointID">Endpoint number for read operations.</param> /// <returns>A <see cref="UsbEndpointWriter"/> class ready for writing. If the specified endpoint is already been opened, the original <see cref="UsbEndpointWriter"/> class is returned.</returns> public virtual UsbEndpointWriter OpenEndpointWriter(WriteEndpointID writeEndpointID) { return(OpenEndpointWriter(writeEndpointID, EndpointType.Bulk)); }
/// <summary> /// Opens an endpoint for writing /// </summary> /// <param name="writeEndpointID">Endpoint number for read operations.</param> /// <param name="endpointType">The type of endpoint to open.</param> /// <returns>A <see cref="UsbEndpointWriter"/> class ready for writing. If the specified endpoint is already been opened, the original <see cref="UsbEndpointWriter"/> class is returned.</returns> public UsbEndpointWriter OpenEndpointWriter(WriteEndpointID writeEndpointID, EndpointType endpointType) { byte altIntefaceID = this.mClaimedInterfaces.Count == 0 ? this.usbAltInterfaceSettings[0] : this.usbAltInterfaceSettings[this.mClaimedInterfaces[this.mClaimedInterfaces.Count - 1]]; return(new UsbEndpointWriter(this, altIntefaceID, writeEndpointID, endpointType)); }
public abstract UsbEndpointWriter OpenEndpointWriter(WriteEndpointID writeEndpointID);
/// <summary> /// Opens an endpoint for writing /// </summary> /// <param name="writeEndpointID">Endpoint number for read operations.</param> /// <param name="endpointType">The type of endpoint to open.</param> /// <returns>A <see cref="UsbEndpointWriter"/> class ready for writing. If the specified endpoint is already been opened, the original <see cref="UsbEndpointWriter"/> class is returned.</returns> public virtual UsbEndpointWriter OpenEndpointWriter(WriteEndpointID writeEndpointID, EndpointType endpointType) { foreach (UsbEndpointBase activeEndpoint in ActiveEndpoints) if (activeEndpoint.EpNum == (byte) writeEndpointID) return (UsbEndpointWriter) activeEndpoint; byte altIntefaceID = mClaimedInterfaces.Count == 0 ? UsbAltInterfaceSettings[0] : UsbAltInterfaceSettings[mClaimedInterfaces[mClaimedInterfaces.Count - 1]]; UsbEndpointWriter epNew = new UsbEndpointWriter(this, altIntefaceID, writeEndpointID, endpointType); return (UsbEndpointWriter) mActiveEndpoints.Add(epNew); }
internal MonoUsbEndpointWriter(UsbDevice usbDevice, byte alternateInterfaceID, WriteEndpointID writeEndpointID, EndpointType endpointType) : base(usbDevice, alternateInterfaceID, writeEndpointID, endpointType) { }
internal MonoUsbEndpointWriter(UsbDevice usbDevice, WriteEndpointID writeEndpointID, EndpointType endpointType) : base(usbDevice, writeEndpointID, endpointType) { }
public static bool TryExtractEndpointPair(this UsbDevice device, out ReadEndpointID readId, out WriteEndpointID writeId) { var ids = ( from info in device.Configs.SelectMany(config => config.InterfaceInfoList) let r = info.EndpointInfoList.Select(ep => ep.Descriptor.EndpointID).FirstOrDefault(id => (id & 0x80) > 0) let w = info.EndpointInfoList.Select(ep => ep.Descriptor.EndpointID).FirstOrDefault(id => (id & 0x80) == 0) where r > 0 && w > 0 select new { ReadId = (ReadEndpointID)r, WriteId = (WriteEndpointID)w, }).FirstOrDefault(); readId = ids?.ReadId ?? 0; writeId = ids?.WriteId ?? 0; return(ids != null); }
internal UsbEndpointWriter(UsbDevice usbDevice, WriteEndpointID writeEndpointID, EndpointType endpointType) : base(usbDevice, (byte)writeEndpointID, endpointType) { }
public UsbEndpointWriter(IUsbDevice usbDevice, byte alternateInterfaceID, WriteEndpointID writeEndpointID, EndpointType endpointType) : base(usbDevice, alternateInterfaceID, (byte)writeEndpointID, endpointType) { }
public UsbDevStream OpenStream(WriteEndpointID WriteEp, ReadEndpointID ReadEp) => new UsbDevStream(dev, WriteEp, ReadEp);
public UsbEndpointWriter OpenEndpointWriter(WriteEndpointID writeEndpointID) { return(usbDevice.OpenEndpointWriter(writeEndpointID)); }
/// <summary> /// Opens a <see cref="EndpointType.Bulk"/> endpoint for writing /// </summary> /// <param name="writeEndpointID">Endpoint number for read operations.</param> /// <returns>A <see cref="UsbEndpointWriter"/> class ready for writing. If the specified endpoint is already been opened, the original <see cref="UsbEndpointWriter"/> class is returned.</returns> public virtual UsbEndpointWriter OpenEndpointWriter(WriteEndpointID writeEndpointID) { return OpenEndpointWriter(writeEndpointID, EndpointType.Bulk); }
internal MonoUsbEndpointWriter(UsbDevice usbDevice, WriteEndpointID writeEndpointID,EndpointType endpointType) : base(usbDevice, writeEndpointID, endpointType) { }
/// <summary> /// Gets endpoint policies for the specified endpoint id. /// </summary> /// <param name="epNum">The endpoint ID to retrieve <see cref="PipePolicies"/> for.</param> /// <returns>A <see cref="PipePolicies"/> class.</returns> public PipePolicies EndpointPolicies(WriteEndpointID epNum) { return new PipePolicies(mUsbHandle, (byte) epNum); }
public UsbDisplayDevice(int pVid, int pPid, WriteEndpointID pWriteEndpointID, string COM) { try { //Init Usb Finder UsbDeviceFinder usbFinder = new UsbDeviceFinder(pVid, pPid); // Find and open the usb device. _usbDevice = UsbDevice.OpenUsbDevice(usbFinder); // If the device is open and ready string message = string.Empty; if (_usbDevice == null) { //string baud, string par, string sBits, string dBits, string name _communicationManager = new CommunicationManager(); _communicationManager.CurrentTransmissionType = PCComm.CommunicationManager.TransmissionType.Hex; _communicationManager.PortName = COM; // Start With OpenPort OpenPort(); //message = string.Format("UsbDisplayDevice: Device Not Found VID:{0} PID:{1}", pVid, pPid); //_log.Error(message); //throw new Exception("UsbDisplayDevice(int pVid, int pPid, WriteEndpointID pWriteEndpointID) :: " + message); } else { message = string.Format("UsbDisplayDevice: Device Found VID:{0} PID:{1}", pVid, pPid); _log.Debug(message); } // If this is a "whole" usb device (libusb-win32, linux libusb) // it will have an IUsbDevice interface. If not (WinUSB) the // variable will be null indicating this is an interface of a // device. IUsbDevice wholeUsbDevice = _usbDevice as IUsbDevice; if (!ReferenceEquals(wholeUsbDevice, null)) { // This is a "whole" USB device. Before it can be used, // the desired configuration and interface must be selected. // Select config wholeUsbDevice.SetConfiguration(1); // Claim interface wholeUsbDevice.ClaimInterface(1); } // open write endpoint if (_usbDevice != null) { _usbWriter = _usbDevice.OpenEndpointWriter(pWriteEndpointID); } //Init Display if (_usbWriter != null) { InitializeDisplay(); if (_debug) { // Unreachable code detected #pragma warning disable CS0162 SetCursorInOff(0x01); #pragma warning restore CS0162 } } } catch (Exception ex) { _log.Error((_usbErrorCode != ErrorCode.None ? _usbErrorCode + ":" : string.Empty) + ex.Message); } }
/// <summary> /// Opens an endpoint for writing /// </summary> /// <param name="writeEndpointID">Endpoint number for read operations.</param> /// <param name="endpointType">The type of endpoint to open.</param> /// <returns>A <see cref="UsbEndpointWriter"/> class ready for writing. If the specified endpoint is already been opened, the original <see cref="UsbEndpointWriter"/> class is returned.</returns> public override UsbEndpointWriter OpenEndpointWriter(WriteEndpointID writeEndpointID, EndpointType endpointType) { foreach (UsbEndpointBase activeEndpoint in ActiveEndpoints) if (activeEndpoint.EpNum == (byte)writeEndpointID) return (UsbEndpointWriter)activeEndpoint; UsbEndpointWriter epNew = new LibUsbEndpointWriter(this, writeEndpointID, endpointType); return (UsbEndpointWriter) mActiveEndpoints.Add(epNew); }
public UsbEndpointWriter OpenEndpointWriter(WriteEndpointID writeEndpointID) { return usbDevice.OpenEndpointWriter(writeEndpointID); }
/// <summary> /// Gets endpoint policies for the specified endpoint id. /// </summary> /// <param name="epNum">The endpoint ID to retrieve <see cref="PipePolicies"/> for.</param> /// <returns>A <see cref="PipePolicies"/> class.</returns> public PipePolicies EndpointPolicies(WriteEndpointID epNum) { return(new PipePolicies(mUsbHandle, (byte)epNum)); }
public static void USBPrint(string printerName, byte[] document) { _log.Debug(String.Format("USBPrint to printerName: [{0}], document: [{1}]", printerName, document.ToString())); UsbDevice usbDevice; UsbEndpointWriter usbWriter; ErrorCode usbErrorCode = ErrorCode.None; //int vid = Convert.ToInt32(ConfigurationManager.AppSettings["printerVID"], 16); //int pid = Convert.ToInt32(ConfigurationManager.AppSettings["printerPID"], 16); //WriteEndpointID endpoint = GetEnumFromString(ConfigurationManager.AppSettings["printerEndPoint"]); //string printerPort = ConfigurationManager.AppSettings["printerPort"]; //string[] printerParam = printerPort.Split('|'); string[] printerParam = printerName.Split('|'); int vid = Convert.ToInt32(printerParam[0], 16); int pid = Convert.ToInt32(printerParam[1], 16); WriteEndpointID endpointWrite = GetWriteEndpointFromString(printerParam[2]); ReadEndpointID endpointRead = GetReadEndpointFromString(printerParam[2]); try { //Init Usb Finder UsbDeviceFinder usbFinder = new UsbDeviceFinder(vid, pid); // Find and open the usb device. usbDevice = UsbDevice.OpenUsbDevice(usbFinder); // If the device is open and ready if (usbDevice == null) { throw new Exception("Device Not Found."); } // If this is a "whole" usb device (libusb-win32, linux libusb) // it will have an IUsbDevice interface. If not (WinUSB) the // variable will be null indicating this is an interface of a // device. IUsbDevice wholeUsbDevice = usbDevice as IUsbDevice; if (!ReferenceEquals(wholeUsbDevice, null)) { // This is a "whole" USB device. Before it can be used, // the desired configuration and interface must be selected. // Select config wholeUsbDevice.SetConfiguration(1); // Claim interface wholeUsbDevice.ClaimInterface(1); } // open read endpoint UsbEndpointReader reader = usbDevice.OpenEndpointReader(endpointRead); reader.DataReceived += Reader_DataReceived; // open write endpoint usbWriter = usbDevice.OpenEndpointWriter(endpointWrite); //byte[] document = Encoding.ASCII.GetBytes("Hello World"); try { // write data, read data int bytesWritten; usbErrorCode = usbWriter.Write(document, 2000, out bytesWritten); if (usbErrorCode != ErrorCode.None) { Close(usbDevice); // Write that output to the console. throw new Exception(UsbDevice.LastErrorString); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } catch (Exception ex) { _log.Error((usbErrorCode != ErrorCode.None ? usbErrorCode + ":" : String.Empty) + ex.Message); } }
public UsbEndpointWriter OpenEndpointWriter(WriteEndpointID writeEndpointID, EndpointType endpointType) { return(_device.OpenEndpointWriter(writeEndpointID, endpointType)); }
public UsbDisplayDevice(int pVid, int pPid, WriteEndpointID pWriteEndpointID) { try { //Init Usb Finder UsbDeviceFinder usbFinder = new UsbDeviceFinder(pVid, pPid); // Find and open the usb device. _usbDevice = UsbDevice.OpenUsbDevice(usbFinder); // If the device is open and ready string message = string.Empty; if (_usbDevice == null) { message = string.Format("UsbDisplayDevice: Device Not Found VID:{0} PID:{1}", pVid, pPid); _log.Error(message); //throw new Exception(message); } else { message = string.Format("UsbDisplayDevice: Device Found VID:{0} PID:{1}", pVid, pPid); _log.Debug(message); } // If this is a "whole" usb device (libusb-win32, linux libusb) // it will have an IUsbDevice interface. If not (WinUSB) the // variable will be null indicating this is an interface of a // device. IUsbDevice wholeUsbDevice = _usbDevice as IUsbDevice; if (!ReferenceEquals(wholeUsbDevice, null)) { // This is a "whole" USB device. Before it can be used, // the desired configuration and interface must be selected. // Select config wholeUsbDevice.SetConfiguration(1); // Claim interface wholeUsbDevice.ClaimInterface(1); } // open write endpoint if (_usbDevice != null) { _usbWriter = _usbDevice.OpenEndpointWriter(pWriteEndpointID); } //Init Display if (_usbWriter != null) { InitializeDisplay(); if (_debug) { SetCursorInOff(0x01); } } } catch (Exception ex) { _log.Error((_usbErrorCode != ErrorCode.None ? _usbErrorCode + ":" : string.Empty) + ex.Message); } }
/// <summary> /// Opens a <see cref="EndpointType.Bulk"/> endpoint for writing /// </summary> /// <param name="writeEndpointID">Endpoint number for read operations.</param> /// <returns>A <see cref="UsbEndpointWriter"/> class ready for writing. If the specified endpoint is already been opened, the original <see cref="UsbEndpointWriter"/> class is returned.</returns> public UsbEndpointWriter OpenEndpointWriter(WriteEndpointID writeEndpointID) { return(this.OpenEndpointWriter(writeEndpointID, EndpointType.Bulk)); }