/// <summary> /// Gets a properties value. /// </summary> /// <param name="keyName">The key name to look up.</param> /// <returns>The keys value on success; Otherwise, null.</returns> public string GetCFPropertyString(string keyName) { string value = null; IOKitFramework.GetCFPropertyString(this, keyName, out value); return(value); }
/// <summary> /// Returns a list of available communication devices. /// </summary> /// <returns>A list of <see cref="USBCommunicationDevice"/> instances.</returns> public static List <USBCommunicationDevice> GetUSBCommunicationDevices() { var result = new List <USBCommunicationDevice>(); using (var serialPortIterator = IOKitFramework.FindModems()) { if (serialPortIterator != null) { var modemService = serialPortIterator.Next(); while (modemService != null) { using (modemService) { var modemPath = IOKitFramework.GetModemPath(modemService); if (String.IsNullOrEmpty(modemPath)) { if (verbosity > TraceVerbosity.Silent) { Trace.TraceError("Could not get path for modem.\n"); } } else { using (var device = IOKitFramework.GetUSBDevice(modemService)) { if (device != null) { var vendorString = device.GetCFPropertyString(IOKitFramework.kUSBVendorString); var productString = device.GetCFPropertyString(IOKitFramework.kUSBProductString); var productID = device.GetCFPropertyInt(IOKitFramework.kUSBProductID); var vendorID = device.GetCFPropertyInt(IOKitFramework.kUSBVendorID); if ((productID > 0) && (vendorID > 0)) { var deviceDescriptor = new USBCommunicationDevice { ComName = modemPath, VendorString = vendorString, ProductString = productString, VendorID = vendorID, ProductID = productID, Caption = String.Format("{0} {1}", vendorString, productString) }; result.Add(deviceDescriptor); } } } } } modemService = serialPortIterator.Next(); } } } return(result); }
/// <summary> /// Iterates one step forward. /// </summary> /// <returns>A <see cref="IOObject"/> instance on success; Null if the iterator has reached it's end.</returns> public IOObject Next() { if (disposedValue) { throw new ObjectDisposedException("handle"); } if (handle == IntPtr.Zero) { throw new InvalidOperationException("Can not iterate over uninitialized objects."); } return(IOKitFramework.IOIteratorNext(this)); }
/// <summary> /// Frees managed and unmanaged resources. /// </summary> /// <param name="disposing">True if called from user space; Otherwise, false.</param> protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { // dispose managed state (managed objects). } if (handle != IntPtr.Zero) { IOKitFramework.CFRelease(this); handle = IntPtr.Zero; } disposedValue = true; } }
/// <summary> /// Gets a properties value. /// </summary> /// <param name="keyName">The key name to look up.</param> /// <returns>The keys value on success; Otherwise, null.</returns> public int GetCFPropertyInt(string keyName) { return(IOKitFramework.GetCFPropertyInt(this, keyName)); }