using System; using System.Runtime.InteropServices;
namespace NativeDll { /// <summary> /// SerialPort 的摘要说明。 /// </summary> public class SerialPort { #region 申明要引用的和串口调用有关的API //win32 api constants private const uint GENERIC_READ = 0x80000000; private const uint GENERIC_WRITE = 0x40000000; private const int OPEN_EXISTING = 3; private const int INVALID_HANDLE_VALUE = -1; private const int MAXBLOCK = 4096;
private const uint PURGE_TXABORT = 0x0001; // Kill the pending/current writes to the comm port. private const uint PURGE_RXABORT = 0x0002; // Kill the pending/current reads to the comm port. private const uint PURGE_TXCLEAR = 0x0004; // Kill the transmit queue if there. private const uint PURGE_RXCLEAR = 0x0008; // Kill the typeahead buffer if there.
[StrUCtLayout(LayoutKind.Sequential)] private struct DCB { //taken from c struct in platform sdk public int DCBlength; // sizeof(DCB) public int BaudRate; // current baud rate public int fBinary; // binary mode, no EOF check public int fParity; // enable parity checking public int fOutxCtsFlow; // CTS output flow control