/// <summary> /// Find and connect to any CVLS unit with the given parameters. /// </summary> /// <param name="cvlsPortType">Select the CVLSPortType, can use multiple flags</param> /// <param name="serialNumber">The serial number to connect too</param> public static CVLSComPort AutoConnectComPort(CVLSPortType cvlsPortType, int serialNumber) { var parameters = ComParameters(serialNumber); var comPorts = ComPortInfo.GetDescriptions(); if (ComMode(cvlsPortType) == ThreadedComPortBase.ConnectionMode.SelectionRule) { comPorts = comPorts.Where(SelectionRule(cvlsPortType)).ToList(); } return(comPorts.Any() ? AutoConnectComPort <CVLSComPort>(comPorts.Select(p => p.Port).ToList(), parameters) : null); }
/// <summary> /// Extension to give the ComPortBase.ConnectionMode for a given CVLS CVLSPortType /// </summary> /// <param name="cvlsPortType">The CVLSPortType to use.</param> /// <returns>ComPortBase.ConnectionMode to pass into ComPortBase</returns> public static ThreadedComPortBase.ConnectionMode ComMode(CVLSPortType cvlsPortType) { switch (cvlsPortType) { case CVLSPortType.Usb: case CVLSPortType.Rs232: return(ThreadedComPortBase.ConnectionMode.SelectionRule); default: return(ThreadedComPortBase.ConnectionMode.AnyCom); } }
/// <summary> /// Extension to give the SelectionRule for a given CVLS CVLSPortType /// </summary> /// <param name="cvlsPortType">The CVLSPortType to use.</param> /// <returns>SelectionRule to pass into ComPortBase</returns> public static Func <ComPortInfo, bool> SelectionRule(CVLSPortType cvlsPortType) { switch (cvlsPortType) { case CVLSPortType.Usb: return(port => port.Name.Contains("SCHOTT CV-LS")); case CVLSPortType.Rs232: return(port => !port.Name.Contains("SCHOTT CV-LS")); default: return(null); } }
/// <summary> /// Create a CVLSThreadedComPort for a CVLS unit. This port type should be used when the unit connection /// state is unknown. Functions are provided to be notified of connections and status changes. When using /// a static configuration, consider using the CVLSComPort classes instead. /// </summary> /// <param name="threadName">Name of the thread.</param> /// <param name="closingWorker">The ClosingWorker to add this thread too</param> /// <param name="cvlsPortType">Select the CVLSPortType, can use multiple flags</param> /// <param name="serialNumber">The serial number to connect too</param> public CVLSThreadedComPort(string threadName, ClosingWorker closingWorker, CVLSPortType cvlsPortType, int serialNumber) : base(threadName, closingWorker, CVLSComPort.ComParameters(serialNumber), CVLSComPort.ComMode(cvlsPortType), CVLSComPort.SelectionRule(cvlsPortType)) { InitializeFirmwareUploader(); }
/// <summary> /// Change the connection method of the CVLSThreadedComPort. /// </summary> /// <param name="cvlsPortType">Select the CVLSPortType, can use multiple flags</param> /// <param name="serialNumber">The serial number to connect too</param> public void ChangeMode(CVLSPortType cvlsPortType, int serialNumber) { ConnectionParameters.CopyFrom(CVLSComPort.ComParameters(serialNumber)); base.ChangeMode(CVLSComPort.ComMode(cvlsPortType), CVLSComPort.SelectionRule(cvlsPortType)); }