本文整理汇总了C#中Parity类的典型用法代码示例。如果您正苦于以下问题:C# Parity类的具体用法?C# Parity怎么用?C# Parity使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Parity类属于命名空间,在下文中一共展示了Parity类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParityDecode
static public ushort ParityDecode(Parity aParity)
{
ushort zReturn;
switch (aParity)
{
case Parity.Even:
zReturn = 1;
break;
case Parity.Mark:
zReturn = 2;
break;
case Parity.None:
zReturn = 4;
break;
case Parity.Odd:
zReturn = 0;
break;
case Parity.Space:
zReturn = 3;
break;
default:
throw new ArgumentOutOfRangeException();
}
return zReturn;
}
示例2: SerialTerminal
public SerialTerminal(string portName, int baudRate, Parity parity, int dataBits, StopBits stopBits)
: base(portName, baudRate, parity, dataBits, stopBits)
{
Open();
Handshake = Handshake.XOnXOff;
OperatingMode = IBM3151.OperatingModes.Echo;
}
示例3: 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;
}
}
示例4: 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();
}
示例5: 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;
}
}
示例6: 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++;
}
}
示例7: 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;
}
示例8: 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);
}
}
示例9: setportvalues
public void setportvalues(UInt32 BaudRate, int DataBits, StopBits StopBits, Parity Parity)
{
vBaudRate = BaudRate;
vDataBits = DataBits;
vStopBits = StopBits;
vParity = Parity;
}
示例10: 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;
}
}
示例11: 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();
}
示例12: 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;
}
}
示例13: 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;
}
示例14: PortInitInfo
public PortInitInfo(int mBaudRate,Parity mParity, int mDataBits, StopBits mStopBits)
{
this._BaudRate = mBaudRate;
this._Parity = mParity;
this._DataBits = mDataBits;
this._StopBits = mStopBits;
}
示例15: SerialPort
/// <summary>Initializes a new instance of the <see cref="SerialPort"/> class using the specified port name, baud rate, and parity bit.
/// </summary>
/// <param name="portName">The port to use (for example, COM1)</param>
/// <param name="baudRate">The baud rate</param>
/// <param name="parity">One of the <see cref="Parity"/> values</param>
public SerialPort(string portName, int baudRate, Parity parity)
: this()
{
PortName = portName;
BaudRate = baudRate;
Parity = parity;
}