-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSafeSerial.cs
More file actions
executable file
·51 lines (42 loc) · 1.05 KB
/
SafeSerial.cs
File metadata and controls
executable file
·51 lines (42 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.IO;
using System.IO.Ports;
/* Not being used */
namespace SerialTerminal {
public class SafeSerialPort : SerialPort {
private Stream theBaseStream;
public SafeSerialPort(string portName, int baudRate, Parity parity, int dataBits, StopBits stopBits)
: base(portName, baudRate, parity, dataBits, stopBits) {
}
public SafeSerialPort(string portName, int baudRate)
: base(portName, baudRate) {
}
public new void Open() {
try {
base.Open();
theBaseStream = BaseStream;
GC.SuppressFinalize(BaseStream);
}
catch {
}
}
public new void Dispose() {
Dispose(true);
}
protected override void Dispose(bool disposing) {
if (disposing && (base.Container != null)) {
base.Container.Dispose();
}
try {
if (theBaseStream.CanRead) {
theBaseStream.Close();
GC.ReRegisterForFinalize(theBaseStream);
}
}
catch {
// ignore exception - bug with USB - serial adapters.
}
base.Dispose(disposing);
}
}
}