2017-02-14 50 views
0

我試圖移植一箇舊的C應用程序,該應用程序與串行設備對話到C#中。相當於設置termios c_iflag = IGNPAR使用C#SerialPort類

newtio.c_iflag = IGNPAR; 
newtio.c_oflag = 0; 

我不明白的方式在C#中複製這一點,我相信這將導致串行設備的行爲方式不同,當發送「9C」: C應用程序建立在串行通信設置以下字段。

回答

0

https://msdn.microsoft.com/en-us/library/system.io.ports.parity(v=vs.110).aspx

Public enum Parity 
Even Sets the parity bit so that the count of bits set is an even number. 
Mark Leaves the parity bit set to 1. 
None No parity check occurs. 
Odd  Sets the parity bit so that the count of bits set is an odd number. 
Space Leaves the parity bit set to 0. 

你應該關心None

創建端口與此構造:
https://msdn.microsoft.com/en-us/library/system.io.ports.serialport(v=vs.110).aspx

public SerialPort(
    string portName, 
    int baudRate, 
    Parity parity 
) 

設置校驗值,用這種方法:
https://msdn.microsoft.com/en-us/library/system.io.ports.serialport.parity(v=vs.110).aspx

_serialPort.Parity = SetPortParity(_serialPort.Parity);