-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommManager.cs
More file actions
56 lines (54 loc) · 1.34 KB
/
CommManager.cs
File metadata and controls
56 lines (54 loc) · 1.34 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
using System;
using System.IO.Ports;
namespace Microsoft.Samples.Kinect.SkeletonBasics
{
class CommManager
{
public static SerialPort ComPort;
public String[] ports;
public int baudRate = 9600;
public int BaudRate
{
get
{
if (ComPort != null)
return ComPort.BaudRate;
return 0;
}
set
{
if (ComPort != null)
ComPort.BaudRate = value;
}
}
public CommManager()
{
ports = SerialPort.GetPortNames();
ComPort = null;
}
public CommManager(String port)
{
ports = SerialPort.GetPortNames();
if (ComPort != null && ComPort.PortName == port)
return;
else if (ComPort != null)
ComPort.Close();
ComPort = new SerialPort(port);
try
{
ComPort.Open();
}
catch
{
}
ComPort.WriteTimeout = 500;
}
public int write(byte [] array) {
if (ComPort != null && ComPort.IsOpen)
ComPort.Write(array, 0, 7);
else
return 0;
return -1;
}
}
}