|
public override void EndWrite (IAsyncResult asyncResult) {
EndOperation (asyncResult, false);
}
public int EndWriteEx (IAsyncResult asyncResult) {
return EndOperation (asyncResult, false);
}
public override int Read (byte [] buffer, int offset, int count) {
return EndRead (BeginRead (buffer, offset, count, null, null));
}
public override void Write (byte [] buffer, int offset, int count) {
EndWrite (BeginWrite (buffer, offset, count, null, null));
}
public int WriteEx (byte [] buffer, int offset, int count) {
return EndWriteEx (BeginWrite (buffer, offset, count, null, null));
}
public int Read (byte [] buffer) {
return EndRead (BeginRead (buffer, 0, buffer.Length, null, null));
}
public int Write (byte [] buffer) {
return EndOperation (BeginWrite (buffer, 0, buffer.Length, null, null), false);
}
public override void Flush () {
FlushFileBuffers (m_hFile);
}
public bool PurgeRead () {
return PurgeComm (m_hFile, PURGE_RXCLEAR);
}
public bool PurgeWrite () {
return PurgeComm (m_hFile, PURGE_TXCLEAR);
}
public bool Purge () {
return PurgeRead ()&&PurgeWrite ();
}
public bool CancelRead () {
return PurgeComm (m_hFile, PURGE_RXABORT);
}
public bool CancelWrite () {
return PurgeComm (m_hFile, PURGE_TXABORT);
}
public bool CancelAll () {
return CancelRead ()&&CancelWrite ();
}
public override void SetLength (long nLength) {
throw new NotSupportedException ("SetLength isn't supported on serial ports.");
}
public override long Seek (long offset, SeekOrigin origin) {
throw new NotSupportedException ("Seek isn't supported on serial ports.");
}
public void SetTimeouts (int ReadIntervalTimeout,
int ReadTotalTimeoutMultiplier,
int ReadTotalTimeoutConstant,
int WriteTotalTimeoutMultiplier,
int WriteTotalTimeoutConstant) {
SerialTimeouts Timeouts = new SerialTimeouts (ReadIntervalTimeout,
ReadTotalTimeoutMultiplier,
ReadTotalTimeoutConstant,
WriteTotalTimeoutMultiplier,
WriteTotalTimeoutConstant);
unsafe {SetCommTimeouts (m_hFile, ref Timeouts);}
}
public bool SetPortSettings (uint baudrate) {
return SetPortSettings (baudrate, FlowControl.Hardware);
}
public bool SetPortSettings (uint baudrate, FlowControl flowControl) {
return SetPortSettings (baudrate, flowControl, Parity.None);
}
public bool SetPortSettings (uint baudrate, FlowControl flowControl, Parity parity) {
return SetPortSettings (baudrate, flowControl, parity, 8, StopBits.One);
}
public bool SetPortSettings (uint baudrate, FlowControl flowControl, Parity parity, byte databits, StopBits stopbits) {
unsafe {
DCB dcb = new DCB ();
dcb.DCBlength = sizeof (DCB);
dcb.BaudRate = baudrate;
dcb.ByteSize = databits;
dcb.StopBits = (byte) stopbits;
dcb.Parity = (byte) parity;
dcb.fParity = (parity> 0)? 1U: 0U;
dcb.fBinary = dcb.fDtrControl = dcb.fTXContinueOnXoff = 1;
dcb.fOutxCtsFlow = dcb.fAbortOnError = (flowControl == FlowControl.Hardware)? 1U: 0U;
dcb.fOutX = dcb.fInX = (flowControl == FlowControl.XOnXOff)? 1U: 0U;
dcb.fRtsControl = (flowControl == FlowControl.Hardware)? 2U: 1U;
dcb.XonLim = 2048;
dcb.XoffLim = 512;
dcb.XonChar = 0x11; // Ctrl-Q
dcb.XoffChar = 0x13; // Ctrl-S
return SetCommState (m_hFile, ref dcb);
}
}
public bool SetPortSettings (DCB dcb) {
return SetCommState (m_hFile, ref dcb);
}
public bool GetPortSettings (out DCB dcb) {
unsafe {
DCB dcb2 = new DCB ();
dcb2.DCBlength = sizeof (DCB);
bool ret = GetCommState (m_hFile, ref dcb2);
dcb = dcb2;
return ret;
}
}
Then: |
|