Je n'arrive pas à envoyer des données à un Arduino
Bonjour,
J'essaie d'envoyer des données à l'Arduino via `SpringSerialPortConnector` mais je n'obtiens aucun message et aucune erreur.
Voici l'application spring boot que j'ai utilisée
Code:
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
|
@RestController
public class arduino {
AbstractSpringSerialPortConnector ard;
@RequestMapping("/hh")
public void hh() throws NoSuchPortException, TooManyListenersException, IOException {
ard.connect();
ard.sendMessage("try");
}
static com.fazecast.jSerialComm.SerialPort chosenPort;
@RequestMapping(value="/get")
public String getdata() throws IOException {
SerialPort[] portNames =SerialPort.getCommPorts();
System.out.println(portNames[0]);
chosenPort =getCommPort("COM4");
System.out.println(chosenPort.getSystemPortName());
if(chosenPort.openPort()) {
// enter an infinite loop that sends text to the arduino
PrintWriter output = new PrintWriter(chosenPort.getOutputStream());
output.print("first try");
output.flush();
return "send ";
}
else {
// disconnect from the serial port
chosenPort.closePort();
return "dis"+chosenPort.getSystemPortName();
}
}
} |
et ceci :
Code:
1 2 3 4 5 6 7 8 9
|
AbstractSpringSerialPortConnector ard;
@RequestMapping("/hh")
public void hh() throws NoSuchPortException, TooManyListenersException, IOException {
ard.connect();
ard.sendMessage("try");
} |