forked from JonathanDotCel/NOTPSXSerial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerialTarget.cs
More file actions
69 lines (52 loc) · 2.21 KB
/
Copy pathSerialTarget.cs
File metadata and controls
69 lines (52 loc) · 2.21 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
//
// For connections through a local device (COM14, /dev/tty.SLAB_USBtoUART, etc)
//
using System;
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 SIOBaud connectionType;
public SerialTarget(string portName, UInt32 baudRate, PortConfig inConfig)
: base(inConfig)
{
properSerial = new SerialPort(portName, (int)baudRate, config.parity, config.dataBits, config.stopBits);
// Required for e.g. SharkLink & Yaroze cable compat. Doesn't interfere with the 3-wire setups
properSerial.Handshake = config.handshake;
properSerial.DtrEnable = config.dtrEnable;
properSerial.RtsEnable = config.rtsEnable;
}
public override int BytesToRead
{
get { return properSerial.BytesToRead; }
}
public override int BytesToWrite
{
get { return properSerial.BytesToWrite; }
}
// not implemented
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 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); }
}