Skip to content

Commit 7227b03

Browse files
native ser methods test on linux under processing 3.5
1 parent 8a7b203 commit 7227b03

File tree

2 files changed

+128
-69
lines changed

2 files changed

+128
-69
lines changed

serial_stuff.pde

Lines changed: 57 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,38 @@ int serialReadBaud = 115200;
66
boolean enableFlashing = false;
77
boolean enableDebugPortRead = false;
88

9-
//StringList getSerialPortsInLinux() {
10-
// StringList serialPortsList = new StringList();
11-
// String[] get_ports_cmd = {"bash", "-c", "ls /dev/tty*"};
12-
// try {
13-
// Process p = Runtime.getRuntime().exec(get_ports_cmd);
14-
// // 2. Create a buffer reader to capture input stream. (Note: we are not capturing error stream
15-
// // but it can be done)
16-
// BufferedReader buff = new BufferedReader(new InputStreamReader(p.getInputStream()));
17-
// String stdIn = null;
18-
// // 3. Read a line and if it's not null, print it.
19-
// while ((stdIn = buff.readLine()) != null) {
20-
// //println(stdIn.toString());
21-
// serialPortsList.append(stdIn.toString());
22-
// }
23-
// // 4. Check the exit code to be 100% sure, the command ran successfully (exitCode 0)
24-
// int exitVal = p.waitFor();
25-
// println("Serial Ports list command's EXIT CODE:\t", str(exitVal));
26-
// buff.close();
27-
// }
28-
// catch (Exception e) {
29-
// //println("Running Serial Ports list command had exceptions");
30-
// serialPortsList = null;
31-
// }
32-
// return serialPortsList;
33-
//}
9+
/*
10+
AS OF MAY-2022, if using Processing 4.0b8, the serial library is broken for Linux.
11+
Specifically Serial.list() method doesn't list all available serial ports in LInux.
12+
So you want to use this version of IDE, anyways in Linux, Un comment the below function block.
13+
*/
14+
/*
15+
StringList getSerialPortsInLinux() {
16+
StringList serialPortsList = new StringList();
17+
String[] get_ports_cmd = {"bash", "-c", "ls /dev/tty*"};
18+
try {
19+
Process p = Runtime.getRuntime().exec(get_ports_cmd);
20+
// 2. Create a buffer reader to capture input stream. (Note: we are not capturing error stream
21+
// but it can be done)
22+
BufferedReader buff = new BufferedReader(new InputStreamReader(p.getInputStream()));
23+
String stdIn = null;
24+
// 3. Read a line and if it's not null, print it.
25+
while ((stdIn = buff.readLine()) != null) {
26+
//println(stdIn.toString());
27+
serialPortsList.append(stdIn.toString());
28+
}
29+
// 4. Check the exit code to be 100% sure, the command ran successfully (exitCode 0)
30+
int exitVal = p.waitFor();
31+
println("Serial Ports list command's EXIT CODE:\t", str(exitVal));
32+
buff.close();
33+
}
34+
catch (Exception e) {
35+
//println("Running Serial Ports list command had exceptions");
36+
serialPortsList = null;
37+
}
38+
return serialPortsList;
39+
}
40+
*/
3441

3542

3643

@@ -230,20 +237,34 @@ boolean openSerialPort(String portName, int baudRate) {
230237

231238
StringList currPorts() {
232239
StringList serialPortsList = new StringList();
233-
//// For Linux -> **Spl method due to bug for which Serial.list() doesn't work in linux
234-
//if (OS() == 1) {
235-
// //printArray(get_serial_ports_in_linux());
236-
// serialPortsList = getSerialPortsInLinux();
237-
//}
238-
//// For mac and win
239-
//if (OS() == 0 || OS() == 2) {
240-
// for (int i=0; i<Serial.list().length; i++ ) {
241-
// serialPortsList.append(Serial.list()[i]);
242-
// }
243-
//}
240+
/*
241+
AS OF MAY-2022, if using Processing 4.0b8, the serial library is broken for Linux.
242+
Specifically Serial.list() method doesn't list al; available serial ports in LInux.
243+
So you want to use 4.0b8 version of IDE, anyways in Linux, Un comment the below block.
244+
*/
245+
/*
246+
// For Linux -> **Spl method due to bug for which Serial.list() doesn't work in linux
247+
if (OS() == 1) {
248+
//printArray(get_serial_ports_in_linux());
249+
serialPortsList = getSerialPortsInLinux();
250+
}
251+
// For mac and win
252+
if (OS() == 0 || OS() == 2) {
253+
for (int i=0; i<Serial.list().length; i++ ) {
254+
serialPortsList.append(Serial.list()[i]);
255+
}
256+
}
257+
*/
258+
/*
259+
AS OF MAY-2022, if using Processing 3.5.4, the serial library is working for Linux.
260+
Specifically Serial.list() method correctly lists all available serial ports in Linux.
261+
So you want to use 3.5.4 version of IDE, in Linux (Recommened until seril bug is foxed in Ver 4.X),
262+
Comment out this for loop block below
263+
*/
244264
for (int i=0; i<Serial.list().length; i++ ) {
245265
serialPortsList.append(Serial.list()[i]);
246266
}
267+
247268
return serialPortsList;
248269
}
249270

ui_stuff.pde

Lines changed: 71 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,30 @@ void createUploadPortsMenu(ControlFont f) {
105105
// Create an StringList of all the Serial ports available
106106
StringList serialPortsList = new StringList();
107107

108-
//// For Linux -> **Spl method due to bug for which Serial.list() doesn't work in linux
109-
//if (OS() == 1) {
110-
// //printArray(get_serial_ports_in_linux());
111-
// serialPortsList = getSerialPortsInLinux();
112-
//}
113-
//// For mac and win
114-
//if (OS() == 0 || OS() == 2) {
115-
// for (int i=0; i<Serial.list().length; i++ ) {
116-
// serialPortsList.append(Serial.list()[i]);
117-
// }
118-
//}
119-
108+
/*
109+
AS OF MAY-2022, if using Processing 4.0b8, the serial library is broken for Linux.
110+
Specifically Serial.list() method doesn't list al; available serial ports in LInux.
111+
So you want to use 4.0b8 version of IDE, anyways in Linux, Un comment the below block.
112+
*/
113+
/*
114+
// For Linux -> **Spl method due to bug for which Serial.list() doesn't work in linux
115+
if (OS() == 1) {
116+
//printArray(get_serial_ports_in_linux());
117+
serialPortsList = getSerialPortsInLinux();
118+
}
119+
// For mac and win
120+
if (OS() == 0 || OS() == 2) {
121+
for (int i=0; i<Serial.list().length; i++ ) {
122+
serialPortsList.append(Serial.list()[i]);
123+
}
124+
}
125+
*/
126+
/*
127+
AS OF MAY-2022, if using Processing 3.5.4, the serial library is working for Linux.
128+
Specifically Serial.list() method correctly lists all available serial ports in Linux.
129+
So you want to use 3.5.4 version of IDE, in Linux (Recommened until seril bug is foxed in Ver 4.X),
130+
Comment out this for loop block below
131+
*/
120132
for (int i=0; i<Serial.list().length; i++ ) {
121133
serialPortsList.append(Serial.list()[i]);
122134
}
@@ -169,17 +181,30 @@ void createDebugPortsMenu(ControlFont f) {
169181
// Create an StringList of all the Serial ports available
170182
StringList serialPortsList = new StringList();
171183

184+
/*
185+
AS OF MAY-2022, if using Processing 4.0b8, the serial library is broken for Linux.
186+
Specifically Serial.list() method doesn't list al; available serial ports in LInux.
187+
So you want to use 4.0b8 version of IDE, anyways in Linux, Un comment the below block.
188+
*/
189+
/*
172190
// For Linux -> **Spl method due to bug for which Serial.list() doesn't work in linux
173-
//if (OS() == 1) {
174-
// //printArray(get_serial_ports_in_linux());
175-
// serialPortsList = getSerialPortsInLinux();
176-
//}
177-
//// For mac and win
178-
//if (OS() == 0 || OS() == 2) {
179-
// for (int i=0; i<Serial.list().length; i++ ) {
180-
// serialPortsList.append(Serial.list()[i]);
181-
// }
182-
//}
191+
if (OS() == 1) {
192+
//printArray(get_serial_ports_in_linux());
193+
serialPortsList = getSerialPortsInLinux();
194+
}
195+
// For mac and win
196+
if (OS() == 0 || OS() == 2) {
197+
for (int i=0; i<Serial.list().length; i++ ) {
198+
serialPortsList.append(Serial.list()[i]);
199+
}
200+
}
201+
*/
202+
/*
203+
AS OF MAY-2022, if using Processing 3.5.4, the serial library is working for Linux.
204+
Specifically Serial.list() method correctly lists all available serial ports in Linux.
205+
So you want to use 3.5.4 version of IDE, in Linux (Recommened until seril bug is foxed in Ver 4.X),
206+
Comment out this for loop block below
207+
*/
183208
for (int i=0; i<Serial.list().length; i++ ) {
184209
serialPortsList.append(Serial.list()[i]);
185210
}
@@ -314,17 +339,30 @@ void refreshPorts() {
314339
// Create an StringList of all the Serial ports available
315340
StringList serialPortsList = new StringList();
316341

317-
//// For Linux -> **Spl method due to bug for which Serial.list() doesn't work in linux
318-
//if (OS() == 1) {
319-
// //printArray(get_serial_ports_in_linux());
320-
// serialPortsList = getSerialPortsInLinux();
321-
//}
322-
//// For mac and win
323-
//if (OS() == 0 || OS() == 2) {
324-
// for (int i=0; i<Serial.list().length; i++ ) {
325-
// serialPortsList.append(Serial.list()[i]);
326-
// }
327-
//}
342+
/*
343+
AS OF MAY-2022, if using Processing 4.0b8, the serial library is broken for Linux.
344+
Specifically Serial.list() method doesn't list al; available serial ports in LInux.
345+
So you want to use 4.0b8 version of IDE, anyways in Linux, Un comment the below block.
346+
*/
347+
/*
348+
// For Linux -> **Spl method due to bug for which Serial.list() doesn't work in linux
349+
if (OS() == 1) {
350+
//printArray(get_serial_ports_in_linux());
351+
serialPortsList = getSerialPortsInLinux();
352+
}
353+
// For mac and win
354+
if (OS() == 0 || OS() == 2) {
355+
for (int i=0; i<Serial.list().length; i++ ) {
356+
serialPortsList.append(Serial.list()[i]);
357+
}
358+
}
359+
*/
360+
/*
361+
AS OF MAY-2022, if using Processing 3.5.4, the serial library is working for Linux.
362+
Specifically Serial.list() method correctly lists all available serial ports in Linux.
363+
So you want to use 3.5.4 version of IDE, in Linux (Recommened until seril bug is foxed in Ver 4.X),
364+
Comment out this for loop block below
365+
*/
328366
for (int i=0; i<Serial.list().length; i++ ) {
329367
serialPortsList.append(Serial.list()[i]);
330368
}

0 commit comments

Comments
 (0)