GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Merge pull request #2529 from jdf/serial · othp/processing@9dfa130

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • java/libraries/serial/src/processing/serial
    • Serial.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: java/libraries/serial/src/processing/serial/Serial.java
+11-5Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,21 @@ public Serial(PApplet parent, String portName, int baudRate, char parity, int da
112112
throw new RuntimeException("Error opening serial port " + e.getPortName() + ": " + e.getExceptionType());
113113
}
114114

115+
serialEventMethod = findCallback("serialEvent");
116+
serialAvailableMethod = findCallback("serialAvailable");
117+
}
118+
119+
private Method findCallback(final String name) {
115120
try {
116-
serialEventMethod = parent.getClass().getMethod("serialEvent", new Class[] { this.getClass() });
121+
return parent.getClass().getMethod(name, this.getClass());
117122
} catch (Exception e) {
118123
}
119-
124+
// Permit callback(Object) as alternative to callback(Serial).
120125
try {
121-
serialAvailableMethod = parent.getClass().getMethod("serialAvailable", new Class[] { this.getClass() });
126+
return parent.getClass().getMethod(name, Object.class);
122127
} catch (Exception e) {
123128
}
129+
return null;
124130
}
125131

126132

@@ -133,7 +139,7 @@ public void pre() {
133139
if (serialAvailableMethod != null && invokeSerialAvailable) {
134140
invokeSerialAvailable = false;
135141
try {
136-
serialAvailableMethod.invoke(parent, new Object[] { this });
142+
serialAvailableMethod.invoke(parent, this);
137143
} catch (Exception e) {
138144
System.err.println("Error, disabling serialAvailable() for "+port.getPortName());
139145
System.err.println(e.getLocalizedMessage());
@@ -392,7 +398,7 @@ public void serialEvent(SerialPortEvent event) {
392398
// available() and read() inside draw - but this function has no
393399
// thread-safety issues since it's being invoked during pre in the context
394400
// of the Processing applet
395-
serialEventMethod.invoke(parent, new Object[] { this });
401+
serialEventMethod.invoke(parent, this);
396402
} catch (Exception e) {
397403
System.err.println("Error, disabling serialEvent() for "+port.getPortName());
398404
System.err.println(e.getLocalizedMessage());

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.