Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
307 views
in Technique[技术] by (71.8m points)

java - Printwriter ; i can send only first of my commands to Serial of Arduino

here is my problem. i am making a machine that java program controls arduino by Serial.read() function of arduino. ?n order to communicate with arduino i used "Printwriter and get outputstream". my question is: "why i can send just one command when i clicked the button? I want to send that each listmember in that arraylist one by one" how can i do it please help

private void otomatikmoddenemebutonuActionPerformed(java.awt.event.ActionEvent evt) {                                                        
       
try {
    
    BufferedReader bufReader = new BufferedReader(new FileReader("E:\DenemeOtomatikKomutlar.txt"));
    ArrayList<String> listOfLines = new ArrayList<>();
    String line = bufReader.readLine(); 
    while (line != null) {
        listOfLines.add(line); line = bufReader.readLine(); 
    PrintWriter output = new PrintWriter(chosenPort.getOutputStream());
    
    for (int i = 0; i < listOfLines.size(); i++) {
        
        output.println(listOfLines.get(i));
        output.flush();
        
                 otodenemeTF.setText(listOfLines.get(3));
    
        }
    }
 bufReader.close();
    
} catch (FileNotFoundException ex) {
    Logger.getLogger(PaintMixer_JogModu.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
    Logger.getLogger(PaintMixer_JogModu.class.getName()).log(Level.SEVERE, null, ex);
} 
}     
question from:https://stackoverflow.com/questions/65625811/printwriter-i-can-send-only-first-of-my-commands-to-serial-of-arduino

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...