So Im working on a GUI which reads and writes to a serial port, and everything works fine till I write to the port. Following that the GUI no longer updates the serial read. Even if I close the GUI and re-open it the GUI still refuses to read/display data until I go to the terminal and clear the buffer through that. Is there a method to check if the information is being actually written or if the program is still reading so I can find my errors?
Oh I have no clue if this makes a difference but fedora machine but running everything on a server which I think is also running some sort of linux, the serial device is on the server not my machine.
Below is a copy of my code with the GUI aspects mostly removed as well as some other things that do not relate to the serial communication process directly
This is my first program in this language and I have only worked with visual basic and matlab before this so any help or explanations is greatly appreciated!!!
Is there a problem with trying to send a string through the serial object? I didnt see str's listed as a type when looking up write...
Oh I have no clue if this makes a difference but fedora machine but running everything on a server which I think is also running some sort of linux, the serial device is on the server not my machine.
Below is a copy of my code with the GUI aspects mostly removed as well as some other things that do not relate to the serial communication process directly
This is my first program in this language and I have only worked with visual basic and matlab before this so any help or explanations is greatly appreciated!!!
import processing.serial.*;
Serial myPort;
String Commandt = "--------";
String Additional = "---.- ";
String command= "";
void setup(){
...
myPort = new Serial(this, "/dev/ttyS0", 9600);
String empty= myPort.readString();
myPort.clear();
println(empty);
// myPort.write("2d56!GETSTATUS");
}
String[] dataTypes= {"0","0","0","0"};
String data="--";
void draw(){
if (myPort.available()>0){
String inBuffer=myPort.readStringUntil('\n');//collects the data
if (inBuffer != null) {//sends data to text label if new data
data=inBuffer;
dataTypes= splitTokens(inBuffer," ");//splits to spaces to deal with in chunks, 3rd = # of auth code
myPort.clear();
}else{
data=data;
}
}
text(data,250,200);//display data read
}//END VOID DRAW
void mouseClicked() {
if (mouseX>=210 && mouseX<=290 && mouseY>=100 && mouseY<=130){//button pressing deals with mouse location
String fauthourize=trim(Authourize[int(dataTypes[3])].substring(2,Authourize[int(dataTypes[3])].length()));//trims length and spaces
Commandt= trim(Commandt).toUpperCase();//format texts
Additional= trim(Additional).toUpperCase();
char go = 'y';//preset to send
if (Commandt.equals("RESTART")){//allows only exact commands to pass and be sent also helps format commands(additional)
Additional="";
go = 'y';
}else if(Commandt.equals("SETTIME")){
go = 'y';
Additional= " " + Additional;
}else if (Commandt.equals("GETSTATUS")){
go = 'y';
Additional= "";
}else{//prevent corruption
Additional="";
Commandt="";
go ='n';
}
String command = fauthourize + "!" + Commandt + Additional+'\n';//concatenate the command
if (go == 'y'){//sends command if correct
myPort.write(command);
myPort.clear();}
redraw();//re-enter loop to continue...?
}
}
Is there a problem with trying to send a string through the serial object? I didnt see str's listed as a type when looking up write...
1