public StopBits SetPortStopBits(StopBits defaultPortStopBits) { string stopBits; Console.WriteLine("Available Stop Bits options:"); foreach ( string s in Enum.GetNames( typeof(StopBits))) { Console.WriteLine(" {0}", s); } Console.Write( "Stop Bits({0}):", defaultPortStopBits.ToString()); stopBits = Console.ReadLine(); if (stopBits == "") { stopBits = defaultPortStopBits.ToString(); } return((StopBits)Enum.Parse( typeof(StopBits), stopBits)); }
// 设置串口的停止位 public static StopBits SetPortStopBits(StopBits defaultPortStopBits) { string stopBits; Console.Write("请输入要设置的停止位 One/Two/OnePointFive (默认: {0}):", defaultPortStopBits.ToString()); stopBits = Console.ReadLine(); if (stopBits == "") { stopBits = defaultPortStopBits.ToString(); } return((StopBits)Enum.Parse(typeof(StopBits), stopBits, true)); }
public void SaveUserData() { Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); config.AppSettings.Settings["CommunicationMode"].Value = CommunicationMode.ToString(); config.AppSettings.Settings["IPAddress"].Value = IPAddress.ToString(); config.AppSettings.Settings["TCPPort"].Value = TCPPort.ToString(); config.AppSettings.Settings["PortName"].Value = PortName.ToString(); config.AppSettings.Settings["Baud"].Value = Baud.ToString(); config.AppSettings.Settings["Parity"].Value = Parity.ToString(); config.AppSettings.Settings["SlaveId"].Value = SlaveId.ToString(); config.AppSettings.Settings["DataBits"].Value = DataBits.ToString(); config.AppSettings.Settings["StopBits"].Value = StopBits.ToString(); config.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("appSettings"); //Properties.Settings.Default.CommunicationMode = CommunicationMode.ToString(); //Properties.Settings.Default.IPAddress = IPAddress.ToString(); //Properties.Settings.Default.DisplayFormat = DisplayFormat.ToString(); //Properties.Settings.Default.TCPPort = TCPPort; //Properties.Settings.Default.PortName = PortName; //Properties.Settings.Default.Baud = Baud; //Properties.Settings.Default.Parity = Parity; //Properties.Settings.Default.StartAddress = StartAddress; //Properties.Settings.Default.DataLength = DataLength; //Properties.Settings.Default.SlaveId = SlaveId; //Properties.Settings.Default.SlaveDelay = SlaveDelay; //Properties.Settings.Default.DataBits = DataBits; //Properties.Settings.Default.StopBits = StopBits; //Properties.Settings.Default.Save(); }
public static void ConfigureAppSettings(IAppSettingsBuilder builder) { // Main configuration settings builder.Add($"{MainSection}:{nameof(AutoScan)}", "false", "Defines the value indicating if tool should start scan automatically on start."); builder.Add($"{MainSection}:{nameof(AutoRemoveIDs)}", "false", "Defines the value indicating if tool should auto-remove ID codes from list as they are completed."); builder.Add($"{MainSection}:{nameof(StartComPort)}", "0", "Defines the starting COM port number for the scan."); builder.Add($"{MainSection}:{nameof(EndComPort)}", "0", "Defines the ending COM port number for the scan."); builder.Add($"{MainSection}:{nameof(ComPorts)}", "", "Defines the comma separated list of serial COM ports to scan (overrides start/end range)."); builder.Add($"{MainSection}:{nameof(StartIDCode)}", "0", "Defines the starting IEEE C37.118 ID code for the scan."); builder.Add($"{MainSection}:{nameof(EndIDCode)}", "0", "Defines the ending IEEE C37.118 ID code for the scan."); builder.Add($"{MainSection}:{nameof(IDCodes)}", "", "Defines the comma separated list of IEEE C37.118 ID codes to scan (overrides start/end range)."); builder.Add($"{MainSection}:{nameof(Rescan)}", DefaultRescan.ToString(), "Defines the value indicating whether already configured COM ports should be rescanned."); builder.Add($"{MainSection}:{nameof(AutoStartParsingSequenceForScan)}", DefaultAutoStartParsingSequenceForScan.ToString(), "Defines the value indicating whether scan should send automatic parsing sequence to start connection."); builder.Add($"{MainSection}:{nameof(ControllingConnection)}", DefaultControllingConnection.ToString(), "Defines the value indicating whether added device configuration should be set for controlling connection."); builder.Add($"{MainSection}:{nameof(SourceConfig)}", DefaultSourceConfig, "Defines the source configuration file for host application that contains database connection info."); builder.Add($"{MainSection}:{nameof(ResponseTimeout)}", DefaultResponseTimeout.ToString(), "Defines the maximum time, in milliseconds, to wait for a serial response."); builder.Add($"{MainSection}:{nameof(ConfigFrameTimeout)}", DefaultConfigFrameTimeout.ToString(), "Defines the maximum time, in milliseconds, to wait for a configuration frame."); builder.Add($"{MainSection}:{nameof(DisableDataDelay)}", DefaultDisableDataDelay.ToString(), "Defined the delay time, in milliseconds, to wait after sending the DisableRealTimeData command to a device."); // Serial configuration settings builder.Add($"{SerialSection}:{nameof(BaudRate)}", DefaultBaudRate.ToString(), "Defines the serial baud rate. Standard values: 110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, 115200, 128000, or 256000."); builder.Add($"{SerialSection}:{nameof(DataBits)}", DefaultDataBits.ToString(), "Defines the standard length of data bits per byte. Standard values: 5, 6, 7 or 8."); builder.Add($"{SerialSection}:{nameof(Parity)}", DefaultParity.ToString(), "Defines the parity-checking protocol. Value is one of: Even, Mark, None, Odd or Space."); builder.Add($"{SerialSection}:{nameof(StopBits)}", DefaultStopBits.ToString(), "Defines the standard number of stopbits per byte. Value is one of: None, One, OnePointFive or Two."); builder.Add($"{SerialSection}:{nameof(DtrEnable)}", DefaultDtrEnable.ToString(), "Defines the value that enables the Data Terminal Ready (DTR) signal during serial communication."); builder.Add($"{SerialSection}:{nameof(RtsEnable)}", DefaultRtsEnable.ToString(), "Defines the value indicating whether the Request to Send (RTS) signal is enabled during serial communication."); }
// 显示StopBits值并提示用户输入值。 public static StopBits SetPortStopBits(StopBits defaultPortStopBits) { string stopBits; Console.WriteLine("可用的停止位选项:"); foreach (string s in Enum.GetNames(typeof(StopBits))) { Console.WriteLine(" {0}", s); } Console.Write("输入StopBits值(不支持None,并且 \n" + "引发参数超出范围异常。 \n (默认值:{0}):", defaultPortStopBits.ToString()); stopBits = Console.ReadLine(); if (stopBits == "") { stopBits = defaultPortStopBits.ToString(); } return((StopBits)Enum.Parse(typeof(StopBits), stopBits, true)); }
public string ToString(string format, IFormatProvider formatProvider) { if (string.IsNullOrEmpty(format)) { format = "G"; } if (formatProvider == null) { formatProvider = CultureInfo.CurrentCulture; } switch (format.ToUpperInvariant()) { case "G": return(ToString()); case "LOG": return(string.Format(Resources.SerialPortSettingsString, BaudRate.ToString(true), Parity.ToString(), StopBits.ToString(), headerTX, HeaderRX)); default: throw new FormatException(string.Format(Resources.FormatNotSupported, format)); } }
public void beginCommunication() { stopComms = false; _serialPort = new SerialPort(CommPort); _serialPort.StopBits = (StopBits)Enum.Parse(typeof(StopBits), StopBits.ToString()); _serialPort.BaudRate = BaudRate; _serialPort.Parity = (Parity)Enum.Parse(typeof(Parity), Parity); _serialPort.DataBits = DataBits; _serialPort.StopBits = (StopBits)Enum.Parse(typeof(StopBits), StopBits.ToString()); _serialPort.Handshake = (Handshake)Enum.Parse(typeof(Handshake), Handshake); _serialPort.ReadTimeout = 500; _serialPort.WriteTimeout = 500; try { _serialPort.Open(); Connected = _serialPort.IsOpen; receiveThread = new Thread(receiveCommand); receiveThread.Start(); sendThread = new Thread(sendCommand); sendThread.Start(); } catch (System.IO.IOException ex) { //Typically caused by either using wrong Com Port or the device not being connected. Console = $"{ex.Message}"; Console = $"Verify settings in Connection->Settings are correct and that the device is connected! {i}"; i++; } }
private async void SaveSettingss(string port, int baud, Parity parity, Handshake handshake, int dataBits, StopBits stopBits) { writing = true; XmlWriterSettings settings = new XmlWriterSettings { Indent = true, NewLineOnAttributes = true }; XmlWriter writer = XmlWriter.Create("Settings.xml", settings); writer.WriteStartDocument(); writer.WriteStartElement("Settings"); writer.WriteElementString("Port", port); writer.WriteElementString("Baudrate", baud.ToString()); writer.WriteElementString("Parity", parity.ToString()); writer.WriteElementString("Handshake", handshake.ToString()); writer.WriteElementString("Data_Bits", dataBits.ToString()); writer.WriteElementString("Stop_Bits", stopBits.ToString()); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Flush(); writer.Close(); writing = false; if(!initialization) { MessageDialogResult result = await MessageService.ShowMessage("Gespeichert!", "Settings wurden gespeichert!", MessageDialogStyle.Affirmative).ConfigureAwait(false); } }
/// <summary> /// create ini file,write the default value /// </summary> /// <param name="inifilepath">ini path</param> public static void createIniFile(string inifilepath) { IniFile.CreateIniFile(inifilepath); //IniFile.IniFilePath = inifilepath; // IniFile.IniWriteValue(IniSection.PLC_COM.ToString(), "PLC_Port", PLC_Port, inifilepath); IniFile.IniWriteValue(IniSection.PLC_COM.ToString(), "PLC_Baud_Rate", PLC_Baud_Rate, inifilepath); IniFile.IniWriteValue(IniSection.PLC_COM.ToString(), "PLC_Data_Bits", PLC_Data_Bits.ToString(), inifilepath); IniFile.IniWriteValue(IniSection.PLC_COM.ToString(), "PLC_Stop_Bits", PLC_Stop_Bits.ToString(), inifilepath); IniFile.IniWriteValue(IniSection.PLC_COM.ToString(), "PLC_Parity", PLC_Parity.ToString(), inifilepath); // IniFile.IniWriteValue(IniSection.Bar_COM.ToString(), "Scan_A_Port", Scan_A_Port, inifilepath); IniFile.IniWriteValue(IniSection.Bar_COM.ToString(), "Scan_B_Port", Scan_B_Port, inifilepath); IniFile.IniWriteValue(IniSection.Bar_COM.ToString(), "Scan_C_Port", Scan_C_Port, inifilepath); IniFile.IniWriteValue(IniSection.Bar_COM.ToString(), "Scan_D_Port", Scan_D_Port, inifilepath); IniFile.IniWriteValue(IniSection.Bar_COM.ToString(), "Scan_Baud_Rate", Scan_Baud_Rate, inifilepath); IniFile.IniWriteValue(IniSection.Bar_COM.ToString(), "Scan_Data_Bits", Scan_Data_Bits.ToString(), inifilepath); IniFile.IniWriteValue(IniSection.Bar_COM.ToString(), "Scan_Stop_Bits", Scan_Stop_Bits.ToString(), inifilepath); IniFile.IniWriteValue(IniSection.Bar_COM.ToString(), "Scan_Parity", Scan_Parity.ToString(), inifilepath); // IniFile.IniWriteValue(IniSection.Bar_COM.ToString(), "Open_Scan_Command", Open_Scan_Command, inifilepath); IniFile.IniWriteValue(IniSection.Bar_COM.ToString(), "Close_Scan_Command", Close_Scan_Command, inifilepath); IniFile.IniWriteValue(IniSection.Bar_COM.ToString(), "Open_Add_Enter", Open_Add_Enter.ToString(), inifilepath); IniFile.IniWriteValue(IniSection.Bar_COM.ToString(), "Close_Add_Enter", Close_Add_Enter.ToString(), inifilepath); IniFile.IniWriteValue(IniSection.Bar_COM.ToString(), "Send_Command_Use_Hex", Send_Command_Use_Hex.ToString(), inifilepath); }
public void InitialzeSerialPortSettings(int baudrate, int databits, StopBits stopbits, Parity parity, string COM) { cmbBaudRate.Text = baudrate.ToString(); cmbDataBits.Text = databits.ToString(); cmbStopBits.Text = stopbits.ToString(); cmbParity.Text = parity.ToString(); cmbPortName.Text = COM; }
// Display StopBits values and prompt user to enter a value. private void SetPortStopBits(StopBits portStopBits) { _serialPort.StopBits = portStopBits; if (Constants.VerboseMode) { Console.WriteLine($"Port Stop Bits Set To {portStopBits.ToString()}."); } }
//设置停止位 public static StopBits SetPortStopBits(StopBits defaultPortStopBits) { string stopBits; Console.WriteLine("可用停止位:"); foreach (string s in Enum.GetNames(typeof(StopBits))) { Console.WriteLine(" {0}", s); } Console.Write("输入停止位 (默认: {0}):", defaultPortStopBits.ToString()); stopBits = Console.ReadLine(); if (stopBits == "") { stopBits = defaultPortStopBits.ToString(); } return((StopBits)Enum.Parse(typeof(StopBits), stopBits, true)); }
/// <summary> /// Report settings using UserInterfaceData. /// </summary> private void ReportSettings() { if (UserInterfaceData != null) { string settings = portName + "," + baudRate.ToString() + "," + dataBits.ToString() + "," + parity.ToString() + "," + stopBits.ToString() + "," + handshake.ToString(); UserInterfaceData(ComPortEvent.ReportSettings, settings); } }
protected override void GetXml(XmlDocument document, XmlNode rootElement) { base.GetXml(document, rootElement); AddElement(document, rootElement, "PortName", PortName); AddElement(document, rootElement, "BaudRate", BaudRate.ToString(CultureInfo.InvariantCulture)); AddElement(document, rootElement, "DataBits", DataBits.ToString(CultureInfo.InvariantCulture)); AddElement(document, rootElement, "Parity", Parity.ToString()); AddElement(document, rootElement, "StopBits", StopBits.ToString()); AddElement(document, rootElement, "TryCount", TryCount.ToString(CultureInfo.InvariantCulture)); }
// Display StopBits values and prompt user to enter a value. public static StopBits SetPortStopBits(StopBits defaultPortStopBits) { string stopBits; Console.WriteLine("Available StopBits options:"); foreach (string s in Enum.GetNames(typeof(StopBits))) { Console.WriteLine(" {0}", s); } Console.Write("Enter StopBits value (None is not supported and \n" + "raises an ArgumentOutOfRangeException. \n (Default: {0}):", defaultPortStopBits.ToString()); stopBits = Console.ReadLine(); if (stopBits == "") { stopBits = defaultPortStopBits.ToString(); } return((StopBits)Enum.Parse(typeof(StopBits), stopBits, true)); }
public override string ToString() { List <string> paraList = new List <string>(); paraList.Add(PortName.ToString()); paraList.Add(BaudRate.ToString()); paraList.Add(DataBits.ToString()); paraList.Add(StopBits.ToString()); paraList.Add(Parity.ToString()); return(String.Format("{0}://{1}", Prefix, String.Join(SpitChar, paraList))); }
public static StopBits SetPortStopBits(StopBits defaultPortStopBits) { string stopBits = ConfigurationManager.AppSettings["StopBits"]; if (string.IsNullOrEmpty(stopBits)) { stopBits = defaultPortStopBits.ToString(); } return((StopBits)Enum.Parse(typeof(StopBits), stopBits)); }
/// <summary> /// Установить параметры канала связи в соответствии с настройками /// </summary> public void SetCommCnlParams(SortedList <string, string> commCnlParams) { commCnlParams["PortName"] = PortName; commCnlParams["BaudRate"] = BaudRate.ToString(); commCnlParams["Parity"] = Parity.ToString(); commCnlParams["DataBits"] = DataBits.ToString(); commCnlParams["StopBits"] = StopBits.ToString(); commCnlParams["DtrEnable"] = DtrEnable.ToString(); commCnlParams["RtsEnable"] = RtsEnable.ToString(); commCnlParams["Behavior"] = Behavior.ToString(); }
public static StopBits SetPortStopBits(StopBits defaultPortStopBits) { string stopBits = ""; if (stopBits == "") { stopBits = defaultPortStopBits.ToString(); } return((StopBits)Enum.Parse(typeof(StopBits), stopBits, true)); }
/// <summary> /// Adds the options to the list. /// </summary> public void AddToOptionList(OptionList options) { options.Clear(); options["PortName"] = PortName; options["BaudRate"] = BaudRate.ToString(); options["DataBits"] = DataBits.ToString(); options["Parity"] = Parity.ToString(); options["StopBits"] = StopBits.ToString(); options["DtrEnable"] = DtrEnable.ToLowerString(); options["RtsEnable"] = RtsEnable.ToLowerString(); options["Behavior"] = Behavior.ToString(); }
// Display StopBits values and prompt user to enter a value. // 显示StopBits值并提示用户输入一个值。 public static StopBits SetPortStopBits(StopBits defaultPortStopBits) { string stopBits; Console.WriteLine("可用的 StopBits 选择:"); foreach (string s in Enum.GetNames(typeof(StopBits))) { Console.WriteLine(" {0}", s); } Console.Write("输入StopBits值(不支持None并且 \n" + "引发一个 ArgumentOutOfRangeException. \n (默认: {0}):", defaultPortStopBits.ToString()); stopBits = Console.ReadLine(); if (stopBits == "") { stopBits = defaultPortStopBits.ToString(); } return((StopBits)Enum.Parse(typeof(StopBits), stopBits, true)); }
public void Save(XmlTextWriter xml) { xml.WriteStartElement("interface"); xml.WriteAttributeString("id", Id); xml.WriteAttributeString("portName", PortName); xml.WriteAttributeString("baudRate", BaudRate.ToString()); xml.WriteAttributeString("dataBits", DataBits.ToString()); xml.WriteAttributeString("handShake", HandShake.ToString()); xml.WriteAttributeString("parity", Parity.ToString()); xml.WriteAttributeString("stopBits", StopBits.ToString()); xml.WriteEndElement(); }
public static void ConfigureAppSettings(IAppSettingsBuilder builder) { // UDP configuration settings builder.Add($"{UDPSection}:{nameof(InterfaceIP)}", DefaultInterfaceIP, "Defines the IP of the network interface to use for the UDP socket. Use 0.0.0.0 to listen on all interfaces with IPv4 or ::0 for all interfaces with IPv6."); // Serial configuration settings builder.Add($"{SerialSection}:{nameof(BaudRate)}", DefaultBaudRate.ToString(), "Defines the serial baud rate. Standard values: 110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, 115200, 128000, or 256000."); builder.Add($"{SerialSection}:{nameof(DataBits)}", DefaultDataBits.ToString(), "Defines the standard length of data bits per byte. Standard values: 5, 6, 7 or 8."); builder.Add($"{SerialSection}:{nameof(Parity)}", DefaultParity.ToString(), "Defines the parity-checking protocol. Value is one of: Even, Mark, None, Odd or Space."); builder.Add($"{SerialSection}:{nameof(StopBits)}", DefaultStopBits.ToString(), "Defines the standard number of stopbits per byte. Value is one of: None, One, OnePointFive or Two."); builder.Add($"{SerialSection}:{nameof(DtrEnable)}", DefaultDtrEnable.ToString(), "Defines the value that enables the Data Terminal Ready (DTR) signal during serial communication."); builder.Add($"{SerialSection}:{nameof(RtsEnable)}", DefaultRtsEnable.ToString(), "Defines the value indicating whether the Request to Send (RTS) signal is enabled during serial communication."); }
public StopBits SetPortStopBits(StopBits defaultPortStopBits) { foreach (string s in Enum.GetNames(typeof(StopBits))) { } if (stopBits == "") { stopBits = defaultPortStopBits.ToString(); } return((StopBits)Enum.Parse(typeof(StopBits), stopBits)); }
private StopBits SetPortStopBits(StopBits defaultPortStopBits) { string stopBits; stopBits = this.bitparada.ToString(); if (stopBits == "" || stopBits == null) { stopBits = defaultPortStopBits.ToString(); } return((StopBits)Enum.Parse(typeof(StopBits), stopBits)); }
private void Form1_Load(object sender, EventArgs e) { // fill defaults cbBaudRate.Text = BAUD_RATE.ToString(); cbDataBits.Text = DATA_BITS.ToString(); cbParity.Text = PARITY.ToString(); cbStopBits.Text = STOP_BITS.ToString(); cbFlowControl.Text = HANDSHAKE.ToString(); nmRead.Value = READ_TIMEOUT; nmWrite.Value = WRITE_TIMEOUT; btEnumerate_Click(null, null); }
public static StopBits SetPortStopBits(StopBits defaultPortStopBits) { string stopBits; Console.WriteLine("可选停止位数选项:"); int tot = 1; foreach (string s in Enum.GetNames(typeof(StopBits))) { //if (s == 0) continue; Console.WriteLine("{0}: {1}", tot++, s); } Console.Write("请选择停止位数:", defaultPortStopBits.ToString()); stopBits = Console.ReadLine(); if (stopBits == "") { stopBits = defaultPortStopBits.ToString(); } return((StopBits)Enum.Parse(typeof(StopBits), stopBits, true)); }
// Display StopBits values and prompt user to enter a value. public static StopBits SetPortStopBits(StopBits defaultPortStopBits) { string stopBits; Console.WriteLine("目前可用结束位个数选项:"); foreach (string s in Enum.GetNames(typeof(StopBits))) { if (s == "None") { continue; } Console.WriteLine(" {0}", s); } Console.Write("输入结束位个数 (目前不能为None) (默认值为: {0}):", defaultPortStopBits.ToString()); stopBits = Console.ReadLine(); if (stopBits == "") { stopBits = defaultPortStopBits.ToString(); } return((StopBits)Enum.Parse(typeof(StopBits), stopBits, true)); }
public static StopBits SetPortStopBits(StopBits defaultStopBits)//设置每个字节的停止标准位 { string stopBits; Console.WriteLine("可选择的标准停止位:\n One Two OnePointFive"); Console.Write("请输入标准停止位(默认值为:One)"); stopBits = Console.ReadLine(); if (stopBits == "") { stopBits = defaultStopBits.ToString(); } return((StopBits)Enum.Parse(typeof(StopBits), stopBits, true)); }
private StopBits SetPortStopBits(StopBits defaultPortStopBits) { string stopBits = string.Empty; foreach (string s in Enum.GetNames(typeof(StopBits))) { break; } if (stopBits == "") { stopBits = defaultPortStopBits.ToString(); } return((StopBits)Enum.Parse(typeof(StopBits), stopBits)); }
//methods public ComPort(string name, int bps, Parity parity, StopBits stopBits) { //debug info Console.WriteLine(name.ToString()); Console.WriteLine(bps.ToString()); Console.WriteLine(parity.ToString()); Console.WriteLine(stopBits.ToString()); this.name = name; this.bps = bps; this.parity = parity; this.stopBits = stopBits; recieveTimeOutTimer = new Timer(); recieveTimeOutTimer.AutoReset = false; recieveTimeOutTimer.Elapsed += recieveTimeOut_Elapsed; }
public bool Open(string portName, int baudRate, Parity parity, int dataBits, StopBits stopBits) { try { log.Debug(string.Format("准备打开串口{0},波特率{1},奇偶校验位{2},数据位{3},停止位{4}", portName, baudRate.ToString(), parity.ToString(), dataBits.ToString(), stopBits.ToString())); comPort = new SerialPort(portName, baudRate, parity, dataBits, stopBits); if (comPort.IsOpen) { comPort.Close(); } comPort.Open(); log.Debug(string.Format("成功打开串口{0}!", portName)); return true; } catch (Exception ex) { log.Info(string.Format("打开串口:{0}异常:{1}", portName, ex.ToString())); return false; } }
/// <summary> /// Переводит количество стоповых битов в строку /// </summary> /// <param name="stopBits">Число стоповых битов</param> /// <returns>Значение количества стоповых бит</returns> public static string StopBitsToStr(StopBits stopBits) { switch (stopBits) { case StopBits.None: return "0"; case StopBits.One: return "1"; case StopBits.OnePointFive: return "1.5"; case StopBits.Two: return "2"; default: return stopBits.ToString(); } }
public static StopBits SetPortStopBits(StopBits defaultPortStopBits) { string stopBits = ConfigurationManager.AppSettings["StopBits"]; if (string.IsNullOrEmpty(stopBits)) { stopBits = defaultPortStopBits.ToString(); } return (StopBits)Enum.Parse(typeof(StopBits), stopBits); }
public StopBits SetPortStopBits(StopBits defaultPortStopBits) { Console.WriteLine("Available StopBits options:"); foreach (var s in Enum.GetNames(typeof(StopBits))) { Console.WriteLine(" {0}", s); } Console.Write("Enter StopBits value (None is not supported and \n" + "raises an ArgumentOutOfRangeException. \n (Default: {0}):", defaultPortStopBits.ToString()); var stopBits = Console.ReadLine(); if (stopBits == "") { stopBits = defaultPortStopBits.ToString(); } // ReSharper disable once AssignNullToNotNullAttribute return (StopBits)Enum.Parse(typeof(StopBits), stopBits, true); }
// Display StopBits values and prompt user to enter a value. public static StopBits SetPortStopBits(StopBits defaultPortStopBits) { string stopBits; Console.WriteLine("Available StopBits options:"); foreach (string s in Enum.GetNames(typeof(StopBits))) { Console.WriteLine(" {0}", s); } Console.Write("Enter StopBits value (None is not supported and \n" + "raises an ArgumentOutOfRangeException. \n (Default: {0}):", defaultPortStopBits.ToString()); stopBits = Console.ReadLine(); if (stopBits == "") { stopBits = defaultPortStopBits.ToString(); } return (StopBits)Enum.Parse(typeof(StopBits), stopBits, true); }
public static StopBits SetPortStopBits(StopBits defaultPortStopBits) { string stopBits; Console.WriteLine("Available Stop Bits options:"); foreach (string s in Enum.GetNames(typeof(StopBits))) { Console.WriteLine(" {0}", s); } Console.Write("Stop Bits({0}):", defaultPortStopBits.ToString()); stopBits = Console.ReadLine(); if (stopBits == "") { stopBits = defaultPortStopBits.ToString(); } return (StopBits)Enum.Parse(typeof(StopBits), stopBits); }
// Display StopBits values and prompt user to enter a value. public static StopBits SetPortStopBits(StopBits defaultPortStopBits) { string stopBits; stopBits = defaultPortStopBits.ToString(); return (StopBits)Enum.Parse(typeof(StopBits), stopBits, true); }