forked from SmokyMountainScientific/WheeStat6_0e
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCom_Port.pde
77 lines (67 loc) · 1.91 KB
/
Com_Port.pde
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
// Com_Port tab
// code on this tab sets up communications with the launchpad
void setupComPort() {
///////// connect button ////////////
cp5Com = new ControlP5(this);
cp5Com.addButton("connect")
.setPosition(10, 10)
.setSize(45, 20)
// .setImages(imgs)
// .updateSize()
;
}
/////////// connect button program //////////
public void connect() {
println("connect button pressed");
try {
serialPort.clear();
serialPort.stop();
}
catch(Exception e) {}
char cData = 'a';
comList = null;
comList = Serial.list();
int n = comList.length;
println("com list length = "+n);
if (n == 0) {
comStatTxt = "No com ports detected";
}
else {
int k = 9999;
// comStatTxt = "Multiple com ports detected";
for (int m = 0; m <= n-1; m++) {
try {
serialPort = new Serial(this, comList[m], 9600);
serialPort.write('*'); // should this be *? was &
// listen for return character '&'
delay(100);
if (serialPort.available () <= 0) {
println (comList[m]+" not responsive");
}
if (serialPort.available() > 0)
{
cData = serialPort.readChar();
if (cData == '&') {
println (comList[m]+" responsive");
k = m;
}else {
println("Com port says: "+cData);
}
serialPort.clear();
serialPort.stop();
}
} // end of try loop
catch(Exception e) {
print(comList[m]);
println(" not responsive");
} /// end of catch thing ///////////////
} // end of itterative look at ports
if (k == 9999) {
comStatTxt = "No responsive port";
} else {
serialPort = new Serial(this, comList[k], 9600);
comStatTxt = "Connected on "+comList[k];
Comselected = true;
}
}
}