-
Notifications
You must be signed in to change notification settings - Fork 0
/
ardoSerial.java
71 lines (58 loc) · 1.92 KB
/
ardoSerial.java
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
package arduino;
import com.panamahitek.PanamaHitek_Arduino;
import javax.swing.JOptionPane;
import jssc.SerialPortEvent;
import jssc.SerialPortEventListener;
import utilerias.msg;
public class ardoSerial {
private PanamaHitek_Arduino ph;
private int brate = 9600;
private String portName = "COM3";
private arduinable reactBase;
SerialPortEventListener listener = new SerialPortEventListener() {
@Override
public void serialEvent(SerialPortEvent spe) {
try {
if (ph.isMessageAvailable()) {
reactBase.behavior(ph.printMessage());
}
} catch (Exception Ex) {
msg.error(Ex.getMessage());
}
}
};
public ardoSerial(arduinable reactBase) {
this.reactBase = reactBase;
try {
this.ph = new PanamaHitek_Arduino();
this.ph.arduinoRXTX("COM3", this.brate, this.listener);
} catch (Exception ex) {
msg.error(ex.getMessage());
}
}
public ardoSerial() {
try {
this.ph = new PanamaHitek_Arduino();
this.ph.arduinoRXTX("COM3", this.brate, this.listener);
} catch (Exception ex) {
msg.error(ex.getMessage());
}
}
public void setArduinable(arduinable reactBase){
this.reactBase = reactBase;
}
public void sendToArdo(String data) {
try {
this.ph.sendData(data);
} catch (Exception ex) {
msg.error(ex.getMessage());
}
}
public void exit() {
try {
this.ph.killArduinoConnection();
} catch (Exception ex) {
msg.error(ex.getMessage());
}
}
}