не может отправить данные на серийный номер - PullRequest
0 голосов
/ 14 июня 2019

Я пытаюсь отправить данные через серийный номер Arduino, используя SpringSerialPortConnector, но не получаю ни сообщения, ни ошибки так что это приложение весенней загрузки, которое я использовал

@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();

    }

    }


}

и это:

  AbstractSpringSerialPortConnector ard;
    @RequestMapping("/hh")
public void hh() throws NoSuchPortException, TooManyListenersException, IOException {

            ard.connect();
            ard.sendMessage("try");

    }
...