forked from JonathanDotCel/NOTPSXSerial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SerialTarget.cs
84 lines (67 loc) · 2.17 KB
/
SerialTarget.cs
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//
// For connections through a local device (COM14, /dev/tty.SLAB_USBtoUART, etc)
//
using System.IO.Ports;
public class SerialTarget : TargetDataPort
{
private static SerialPort properSerial;
// barrier to prevent the monitor going nuts and
// eating our serial data when we're trying to do
// comms on another thread, initiated by socket callbacks
public static object serialLock = new object();
protected SIOSPEED connectionType;
public SerialTarget(string portName, SIOSPEED connectionType, int baudRate, Parity parity, int dataBits, StopBits stopBits)
: base(portName, connectionType, baudRate, parity, dataBits, stopBits)
{
properSerial = new SerialPort(portName, baudRate, parity, dataBits, stopBits);
this.connectionType = connectionType;
}
public override int BytesToRead
{
get { return properSerial.BytesToRead; }
}
public override int BytesToWrite
{
get { return properSerial.BytesToWrite; }
}
public override Handshake Handshake
{
get { return properSerial.Handshake; }
set { properSerial.Handshake = value; }
}
public override bool DtrEnable
{
get { return properSerial.DtrEnable; }
set { properSerial.DtrEnable = value; }
}
public override bool RtsEnable
{
get { return properSerial.RtsEnable; }
set { properSerial.RtsEnable = value; }
}
public override int ReadTimeout
{
get { return properSerial.ReadTimeout; }
set { properSerial.ReadTimeout = value; }
}
public override int WriteTimeout
{
get { return properSerial.WriteTimeout; }
set { properSerial.WriteTimeout = value; }
}
public override bool SkipAcks => connectionType == SIOSPEED.FTDI;
public override void Open()
{ properSerial.Open(); }
public override void Close()
{ properSerial.Close(); }
public override int ReadByte()
{ return properSerial.ReadByte(); }
public override int ReadChar()
{ return properSerial.ReadChar(); }
public override void Write(string text)
{ properSerial.Write(text); }
public override void Write(char[] buffer, int offset, int count)
{ properSerial.Write(buffer, offset, count); }
public override void Write(byte[] buffer, int offset, int count)
{ properSerial.Write(buffer, offset, count); }
}