本文整理汇总了C#中StopBits类的典型用法代码示例。如果您正苦于以下问题:C# StopBits类的具体用法?C# StopBits怎么用?C# StopBits使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StopBits类属于命名空间,在下文中一共展示了StopBits类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SerialConfig
public SerialConfig(string cfg)
{
var parts = cfg.Split(new Char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
this.initialConfig = cfg;
int index = 0;
if (!parts[index].StartsWith("COM"))
{
this.DeviceName = parts[index];
index++;
}
this.PortName = parts[index]; index++;
this.AutoConnect = Boolean.Parse(parts[index]); index++;
this.Speed = UInt32.Parse(parts[index]); index++;
this.DataBits = Byte.Parse(parts[index]); index++;
this.Parity = (Parity)Byte.Parse(parts[index]); index++;
this.StopBits = (StopBits)Byte.Parse(parts[index]); index++;
//this.PacketType = (PacketType)Byte.Parse(parts[index]); index++;
this.RxPacketType = (PacketType)Byte.Parse(parts[index]); index++;
this.TxPacketType = (PacketType)Byte.Parse(parts[index]); index++;
this.PacketType = this.RxPacketType;
if (parts.Length > index)
{
this.ReceiverCRC = Byte.Parse(parts[index]); index++;
this.TransmitterCRC = Byte.Parse(parts[index]); index++;
}
if (parts.Length > index)
{
this.DefaultDeviceAddr = Byte.Parse(parts[index]); index++;
}
}
示例2: SetComboBoxes
public void SetComboBoxes(String comPortName, int baudRate, Parity parity, int dataBits, StopBits stopBits)
{
try
{
cmbComPortName.Text = GetValidPortName(cmbComPortName.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
cmbComPortName.Text = "NONE";
}
cmbBaudRate.Text = baudRate.ToString();
cmbParity.SelectedIndex = GetIndexOfValue(cmbParity.Items, parity.ToString());
cmbDataBits.SelectedIndex = GetIndexOfValue(cmbDataBits.Items, dataBits.ToString());
switch (stopBits)
{
case StopBits.One:
cmbStopBits.SelectedIndex = GetIndexOfValue(cmbStopBits.Items, "1");
break;
case StopBits.OnePointFive:
cmbStopBits.SelectedIndex = GetIndexOfValue(cmbStopBits.Items, "1.5");
break;
case StopBits.Two:
cmbStopBits.SelectedIndex = GetIndexOfValue(cmbStopBits.Items, "2");
break;
case StopBits.None:
cmbStopBits.SelectedIndex = GetIndexOfValue(cmbStopBits.Items, "1");
break;
default:
cmbStopBits.SelectedIndex = GetIndexOfValue(cmbStopBits.Items, "1");
break;
}
}
示例3: RTU_Client
public RTU_Client(string PortName, int BaudRate = 9600, Parity Parity = Parity.None, int DataBits = 8, StopBits StopBits = StopBits.One, int Timeout = 2500)
{
try
{
Port = new SerialPort(PortName, BaudRate, Parity, DataBits, StopBits);
}
catch (IOException ex)
{
throw new RTU_Exception("Ошибка настроек коммуникационного порта. " + ex.Message, ex);
}
ByteTimeout = 20;
MaxCount = 5;
this.Timeout = Timeout;
this.Buffer = new List<byte>(256);
ReqSendEvent += delegate { };
ByteRecievedEvent += delegate { };
try
{
Port.Open();
}
catch (Exception ex)
{
throw new RTU_Exception("Ошибка открытия коммуникационного порта. " + ex.Message, ex);
}
}
示例4: Open
public bool Open(string portName, int baudRate, int databits, Parity parity, StopBits stopBits)
{
//Ensure port isn't already opened:
if (!sp.IsOpen)
{
//Assign desired settings to the serial port:
sp.PortName = portName;
sp.BaudRate = baudRate;
sp.DataBits = databits;
sp.Parity = parity;
sp.StopBits = stopBits;
//These timeouts are default and cannot be editted through the class at this point:
sp.ReadTimeout = 2000;
sp.WriteTimeout = 2000;
try
{
sp.Open();
}
catch (Exception err)
{
return false;
}
return true;
}
else
{
return false;
}
}
示例5: initialize
public static void initialize(string COM_port_Name, int baudRate, Parity parity, int dataBits, StopBits stopBits)
{
try
{
if (COM_port != null)
{
if (COM_port.IsOpen)
{
COM_port.Close();
}
}
COM_port = new SerialPort(COM_port_Name, baudRate, parity, dataBits, stopBits);
COM_port.DataReceived += new SerialDataReceivedEventHandler(DataReceived);
if (!COM_port.IsOpen)
{
COM_port.Open();
}
initialized = 1;
Receiver.Interval = 10;
Receiver.Elapsed += new System.Timers.ElapsedEventHandler(Receiver_time_out);
Receiver.AutoReset = false;
Synchro.Interval = 50;
Synchro.Elapsed += new System.Timers.ElapsedEventHandler(Synchro_time_out);
Synchro.AutoReset = false;
}
catch (Exception exception)
{
Error_messager.Invoke("Ошибка инициализации!\r\nRadist: \r\n" + exception.Message);
initialized = 2;
}
}
示例6: SerialPortSetting
/// <summary>
///
/// </summary>
/// <param name="bardRate"></param>
/// <param name="parity"></param>
/// <param name="dataBits"></param>
/// <param name="stopBits"></param>
public SerialPortSetting(int baudRate, Parity parity, int dataBits, StopBits stopBits)
{
this.BaudRate = baudRate;
this.Parity = parity;
this.DataBits = dataBits;
this.StopBits = stopBits;
}
示例7: RCRadio
public RCRadio(string id, string port = "COM1", int baudRate = 115200, Parity parity = Parity.None, int dataBits = 8, StopBits stopBits = StopBits.One)
{
Port = new SerialPort(port, baudRate, parity, dataBits, stopBits);
AutoPing = true;
PingPeriod = 3000;
DataQueue = new StringFifoQueue();
}
示例8: setportvalues
public void setportvalues(UInt32 BaudRate, int DataBits, StopBits StopBits, Parity Parity)
{
vBaudRate = BaudRate;
vDataBits = DataBits;
vStopBits = StopBits;
vParity = Parity;
}
示例9: PortManager
public PortManager(String portName, int baudRate, Parity parity, int dataBits, StopBits stopBits, Form1 form )
{
if (this.port == null)
{
this.portName = portName;
this.baudRate = baudRate;
this.parity = parity;
this.dataBits = dataBits;
this.stopBits = stopBits;
this.port = new SerialPort(portName, baudRate, parity, dataBits, stopBits);
this.port.DtrEnable = true;
this.port.RtsEnable = true;
this.port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
Form = form;
}
else
{
this.port.BaudRate = baudRate;
this.port.Parity = parity;
this.port.DataBits = dataBits;
this.port.StopBits = stopBits;
}
}
示例10: Start
public static EM406aGPS Start(string portName, int baudRate = 4800, Parity parity = Parity.None, int dataBits = 8, StopBits stopBits = StopBits.One)
{
EM406aGPS gps = new EM406aGPS(portName, baudRate, parity, dataBits, stopBits);
gps._thread = new Thread(gps.Run);
gps._thread.Start();
return gps;
}
示例11: SerialPortSettings
/// <summary>
/// Default constructor of SerialPortSettings.
/// </summary>
public SerialPortSettings()
{
m_baudRate=9600;
m_dataBits=8;
Parity=Parity.None;
StopBits=StopBits.One;
}
示例12: Open
/// <summary>
/// Opens the serial port using the specified baud rate, parity bit, data bits, and stop bit.
/// </summary>
/// <param name="baudRate">The baud rate.</param>
/// <param name="parity">One of the Parity values.</param>
/// <param name="dataBits">The data bits value.</param>
/// <param name="stopBits">One of the StopBits values.</param>
public Windows.Foundation.IAsyncAction Open(
uint baudRate,
Parity parity,
int dataBits,
StopBits stopBits
)
{
return Task.Run(async () =>
{
this.baudRate = baudRate;
this.parity = parity;
this.dataBits = dataBits;
this.stopBits = stopBits;
if (this.cdcControl == null)
{
return;
}
// Do SetLineCoding
var len = await SetLineCoding(this.cdcControl.InterfaceNumber, this.baudRate, (byte)this.stopBits, (byte)this.parity, (byte)this.dataBits);
if (len != Constants.ExpectedResultSetLineCoding)
{
throw new System.NotSupportedException("SetLineCoding request is not supported.");
}
// Do SetControlLineState
len = await SetControlLineState(this.cdcControl.InterfaceNumber);
return;
}).AsAsyncAction();
}
示例13: BalanceReader
/*
* public string ComPort = String.Empty;
public int BaudRate = 110;
public StopBits StopBits = StopBits.None;
public int DataBits = 7;
public Parity Parity = Parity.None;
* */
public BalanceReader(string comPort = "COM1", int baudRate = 9600, StopBits stopBits = StopBits.One,
int dataBits = 7, Parity parity = Parity.Even, string sicsCommand = "SI", bool rts = false)
{
_sicsCommand = sicsCommand;
if (comPort == String.Empty) comPort = "COM1";
_port = new SerialPort
{
PortName = comPort,
BaudRate = baudRate,
StopBits = stopBits,
DataBits = 7,
Parity = Parity.Even,
RtsEnable = rts
};
// from Page 39 of NewClassic Balances METTLER TOLEDO manual for MS-S / MS-L Models
//_port.Handshake = Handshake.XOnXOff;
if (_port.IsOpen == false)
{
try
{
_port.Open();
}
catch (Exception)
{
// port will not be open, therefore will become null
}
}
_port.DataReceived += _port_DataReceived;
}
示例14: SetOptions
public void SetOptions(int baudrate, Parity parity, int databits, StopBits stopbits)
{
this.baudrate = baudrate;
this.parity = parity;
this.databits = databits;
this.stopbits = stopbits;
}
示例15: SerialClass
/// <summary>
/// 构造函数,可以自定义串口的初始化参数
/// </summary>
/// <param name="comPortName">需要操作的COM口名称</param>
/// <param name="baudRate">COM的速度</param>
/// <param name="parity">奇偶校验位</param>
/// <param name="dataBits">数据长度</param>
/// <param name="stopBits">停止位</param>
public SerialClass(string comPortName, int baudRate, Parity parity, int dataBits, StopBits stopBits)
{
_serialPort = new SerialPort(comPortName, baudRate, parity, dataBits, stopBits);
_serialPort.RtsEnable = true; //自动请求
_serialPort.ReadTimeout = 3000;//超时
setSerialPort();
}