public static PHCCPhysicalDeviceInfo[] GetDevices(bool throwOnFail) { var devices = new List <PHCCPhysicalDeviceInfo>(); var ports = new Ports(); foreach (var portName in ports.SerialPortNames) { var deviceInfo = new PHCCPhysicalDeviceInfo(portName, "PHCC device on " + portName); try { if ( PHCCDeviceMonitor.GetInstance(deviceInfo, MinAnalogDataSourceVal, MaxAnalogDataSourceVal) .IsDeviceAttached(false)) { devices.Add(deviceInfo); } } catch (Exception ex) { _log.Debug(ex.Message, ex); } } var toReturn = devices.ToArray(); return(toReturn); }
public static bool IsDeviceAttached(PHCCPhysicalDeviceInfo device, bool throwOnFail) { if (device == null) { throw new ArgumentNullException(nameof(device)); } return (PHCCDeviceMonitor.GetInstance(device, MinAnalogDataSourceVal, MaxAnalogDataSourceVal) .IsDeviceAttached(throwOnFail)); }
/// <summary> /// Factory method to create instances of this class. Stands in place of a constructor, /// in order to re-use instances /// when relevant constructor parameters are the same /// </summary> /// <param name="deviceInfo">a PHCCPhysicalDeviceInfo object representing the PHCC device to monitor</param> /// <param name="axisRangeMin">an integer specifying the value that should be reported when an axis is at its minimum value</param> /// <param name="axisRangeMax">an integer specifying the value that should be reported when an axis is at its maximum value</param> /// <returns> /// a PHCCDeviceMonitor object representing the PHCC device /// being monitored, either created newly from-scratch, or returned from /// this class's internal object pool if a monitor instance already exists /// </returns> public static PHCCDeviceMonitor GetInstance(PHCCPhysicalDeviceInfo deviceInfo, int axisRangeMin, int axisRangeMax) { PHCCDeviceMonitor monitor = null; if (_monitors.ContainsKey(deviceInfo)) { return(_monitors[deviceInfo]); } try { monitor = new PHCCDeviceMonitor(deviceInfo, axisRangeMin, axisRangeMax); _monitors.Add(deviceInfo, monitor); } catch (TimeoutException e) { _log.Debug(e.Message, e); } catch (IOException e) { _log.Debug(e.Message, e); } return(monitor); }