无法将数据发送到串行

时间:2019-06-14 17:08:33

标签: spring-boot serial-port spring-restcontroller

我正在尝试使用XYItemRenderer r = new XYStepAreaRenderer(XYStepAreaRenderer.AREA,…); 通过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();

    }

    }


}

0 个答案:

没有答案