Skip to content

Commit f9762d7

Browse files
committed
add tool to fix the serial port on OS X
1 parent 0f82b93 commit f9762d7

File tree

3 files changed

+111
-12
lines changed

3 files changed

+111
-12
lines changed

app/src/processing/app/Editor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,9 @@ protected JMenu addInternalTools(JMenu menu) {
10191019
addToolMenuItem(menu, "processing.app.tools.Archiver");
10201020

10211021
if (Base.isMacOS()) {
1022+
if (SerialFixer.isNeeded()) {
1023+
addToolMenuItem(menu, "processing.app.tools.SerialFixer");
1024+
}
10221025
addToolMenuItem(menu, "processing.app.tools.InstallCommander");
10231026
}
10241027

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2+
3+
/*
4+
Part of the Processing project - http://processing.org
5+
6+
Copyright (c) 2012 The Processing Foundation
7+
8+
This program is free software; you can redistribute it and/or modify
9+
it under the terms of the GNU General Public License as published by
10+
the Free Software Foundation, version 2.
11+
12+
This program is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
GNU General Public License for more details.
16+
17+
You should have received a copy of the GNU General Public License
18+
along with this program; if not, write to the Free Software Foundation,
19+
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20+
*/
21+
22+
package processing.app.tools;
23+
24+
import java.io.File;
25+
26+
import javax.swing.JOptionPane;
27+
28+
import processing.app.Base;
29+
import processing.app.Editor;
30+
import processing.core.PApplet;
31+
32+
33+
public class SerialFixer implements Tool {
34+
Editor editor;
35+
36+
37+
public String getMenuTitle() {
38+
return "Fix the Serial Library";
39+
}
40+
41+
42+
public void init(Editor editor) {
43+
this.editor = editor;
44+
}
45+
46+
47+
public void run() {
48+
final String primary =
49+
"Attempt to fix common serial port problems?";
50+
final String secondary =
51+
"Click “OK” to perform additional installation steps to enable " +
52+
"the Serial library. An administrator password will be required.";
53+
54+
int result =
55+
JOptionPane.showConfirmDialog(editor,
56+
"<html> " +
57+
"<head> <style type=\"text/css\">"+
58+
"b { font: 13pt \"Lucida Grande\" }"+
59+
"p { font: 11pt \"Lucida Grande\"; margin-top: 8px }"+
60+
"</style> </head>" +
61+
"<b>" + primary + "</b>" +
62+
"<p>" + secondary + "</p>",
63+
"Commander",
64+
JOptionPane.OK_CANCEL_OPTION,
65+
JOptionPane.QUESTION_MESSAGE);
66+
67+
if (result == JOptionPane.OK_OPTION) {
68+
String shellScript = "mkdir -p /var/lock && chmod 777 /var/lock";
69+
String appleScript =
70+
"do shell script \"" + shellScript + "\" with administrator privileges";
71+
PApplet.exec(new String[] { "osascript", "-e", appleScript });
72+
}
73+
editor.statusNotice("Finished.");
74+
}
75+
76+
77+
static public boolean isNeeded() {
78+
if (Base.isMacOS()) {
79+
File lockFolder = new File("/var/lock");
80+
if (!lockFolder.exists() ||
81+
!lockFolder.canRead() ||
82+
!lockFolder.canWrite() ||
83+
!lockFolder.canExecute()) {
84+
return true;
85+
}
86+
}
87+
return false;
88+
}
89+
}

java/libraries/serial/src/processing/serial/Serial.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,15 @@ public Serial(PApplet parent) {
100100
this(parent, dname, drate, dparity, ddatabits, dstopbits);
101101
}
102102

103+
103104
/**
104105
* @param irate 9600 is the default
105106
*/
106107
public Serial(PApplet parent, int irate) {
107108
this(parent, dname, irate, dparity, ddatabits, dstopbits);
108109
}
109110

111+
110112
/**
111113
* @param iname name of the port (COM1 is the default)
112114
*/
@@ -118,6 +120,7 @@ public Serial(PApplet parent, String iname) {
118120
this(parent, iname, drate, dparity, ddatabits, dstopbits);
119121
}
120122

123+
121124
/**
122125
* @param iparity 'N' for none, 'E' for even, 'O' for odd ('N' is the default)
123126
* @param idatabits 8 is the default
@@ -143,8 +146,11 @@ public Serial(PApplet parent, String iname, int irate,
143146
"sudo mkdir -p /var/lock\n" +
144147
"sudo chmod 777 /var/lock";
145148
System.err.println(MESSAGE);
146-
throw new RuntimeException("Additional installation required to " +
147-
"use serial, read the console below.");
149+
//throw new RuntimeException("Additional installation required to " +
150+
// "use serial, read the console below.");
151+
final String msg =
152+
"Please use Tools \u2192 Fix the Serial Library.";
153+
throw new RuntimeException(msg);
148154
}
149155
}
150156

@@ -189,7 +195,7 @@ public Serial(PApplet parent, String iname, int irate,
189195
output = null;
190196
}
191197

192-
parent.registerDispose(this);
198+
parent.registerMethod("dispose", this);
193199

194200
// reflection to check whether host applet has a call for
195201
// public void serialEvent(processing.serial.Serial)
@@ -240,18 +246,19 @@ public void dispose() {
240246

241247

242248
/**
243-
* Set the DTR line. Addition from Tom Hulbert.
244-
*/
249+
* Set the DTR line. Addition from Tom Hulbert.
250+
*/
245251
public void setDTR(boolean state) {
246-
port.setDTR(state);
252+
port.setDTR(state);
247253
}
248254

249-
/**
250-
* @generate serialEvent.xml
251-
* @webref serial:events
252-
* @usage web_application
253-
* @param serialEvent the port where new data is available
254-
*/
255+
256+
/**
257+
* @generate serialEvent.xml
258+
* @webref serial:events
259+
* @usage web_application
260+
* @param serialEvent the port where new data is available
261+
*/
255262
synchronized public void serialEvent(SerialPortEvent serialEvent) {
256263
if (serialEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
257264
try {

0 commit comments

Comments
 (0)