Hi-
I am in the processing of making my code run faster and smoother as I have several sections of identical code in my program because I can not pass the values of variables up the chain. So, I am trying to create some threads that only run when a key is pressed or when a mouse is clicked...Would it be more efficient to create a thread or something else? Also how would I go about adding the conditional part? In the example below I believe I would alter the run() command but so far I have been unsuccessful in my attempts.
class TxtChange extends Thread { boolean active;//running status PApplet p;// to run serial ports as well
TxtChange() {//initial setting active = false; }
void start() {//start command active = true; super.start(); }
void run () {//to keep running this makes a loop how to get conditional while(true){ if(active){
execute();
}else break; }
}
TxtChange(PApplet p) { this.p = p; // store the reference to PApplet active = false; }
void execute() {// what it does if(keyPressed){ if (mouseX>=406 && mouseX<=586 && mouseY>=45 && mouseY<=70){ if(key==BACKSPACE){ Additional = Additional.substring(0, Additional.length()-1); } else if(key==DELETE){ Additional = ""; } else if(keyCode != SHIFT && keyCode != CONTROL && keyCode != ALT){ Additional = Additional + key; } } else if (mouseX>=113 && mouseX<=293 && mouseY>=45 && mouseY<=70){ if(key==BACKSPACE){ Commandt = Commandt.substring(0, Commandt.length()-1); } else if(key==DELETE){ Commandt = ""; } else if(keyCode != SHIFT && keyCode != CONTROL && keyCode != ALT){ Commandt = Commandt + key; } } } delay(80);//need to pause to not take all the processor memory }
boolean isActive() {// no clue return active; }
void quit() {//how to end it active = false; interrupt(); } }
So I have input coming in from a GUI therefore the number I need is coming in as a string. I need to then save it as a long variable to do the character transforms or what ever it is called then save the result as chars to send to an array list to send over a serial port.
Section of code Im dealing with:
unsigned long time= long(Additional);//taking in the GUI data unsigned char b1, b2, b3, b4;//the multiple bytes set up as char for reasons unknown to me
b1= time>>24; b2= time>>16; b3= time>>8; b4= time & 0xff;
hexadd.add(b1,b2,b3,b4);
This is a code that I got from someone who actually knows what they are doing, unfortunately he isnt as great as explaining what he wrote does, so If someone could also explain what all this does that would be great...
I've gotten as far as this description: take the Additional variable from format of string save to another variable(time) in format of unsigned long(which I dont know if how that is written actually works), then create some chars(why they are unsigned too I have no clue), magic, then add the chars to the array list.
So I am splitting data that comes in from a serial port and saving each piece as a separate part of the array. Later in the code I reference parts of the array that I saved. The array's length is either 1 or 12. When the length is 1 I can't reference the array for my display leading to errors, so I am trying to set it to catch the errors and force that part of the array to exist.
Below is the code I am trying to use and I keep getting unexpected '{' as an error....
try { text(Authourize[int(dataTypes[3])], 135, 50, 80, 25);//textboxes and choose the correct auth code } catch(ArrayIndexOutOfBoundsException e) {//catches if most sent but 3= number not in array dataTypes={"0","0","0","0"}; } catch(NullPointerException e) {//catches if not enough sent ie 3 DNE dataTypes={"0","0","0","0"}; }
I tried to do the same thing with an if statement which is less preferable because then the program checks dataTypes on every loop, but I still get the same error...
if (dataTypes.length<3) { dataTypes= {"0", "0", "0", "0"}; } else if (int(dataTypes[3])>49) { dataTypes[3]="0"; }
I know this is probably a really silly question but any help would be greatly appreciated.
Would someone clarify how a thread operates for me in preferably these specific aspects:
Can a thread be looped or run as a loop without being repeatedly called in the draw function? If so how?
If not, then would calling the thread again in draw cause timing issues eventually, such as if the draw finishes and calls the other thread before the thread has finished processing and executing the first set of instructions?
I am working on a GUI that asynchronously reads from a port but I keep getting the buffer stuck so I am trying to find out where the hitch is.
Does Processing include the ability to write Strings to serial ports? I am working on a GUI that reads from the port fine but as soon as I try to write the data 1. doesnt always actually make it to the port and execute and 2. clogs up the buffer preventing me from reading again even if I read and print what is clogging the buffer(for some reason the command I sent) it still refuses to read from the serial port...
This is my first program in this language and I have experience with only matlab and visual basic before this so I am trying to learn... but I keep getting stuck...
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!!!
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
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'; }
So I am trying to set up my serial object but before just to make sure it is connected I test it with print(Serial.list());
What is printed out is as follows:
WARNING: RXTX Version mismatch
Jar version = RXTX-2.2pre1
native lib Version = RXTX-2.2pre2
check_group_uucp(): error testing lock file creation Error details:Permission deniedcheck_lock_status: No permission to create lock file.
please see: How can I use Lock Files with rxtx? in INSTALL
check_group_uucp(): error testing lock file creation Error details:Permission deniedcheck_lock_status: No permission to create lock file.
please see: How can I use Lock Files with rxtx? in INSTALL
check_group_uucp(): error testing lock file creation Error details:Permission deniedcheck_lock_status: No permission to create lock file.
please see: How can I use Lock Files with rxtx? in INSTALL
check_group_uucp(): error testing lock file creation Error details:Permission deniedcheck_lock_status: No permission to create lock file.
please see: How can I use Lock Files with rxtx? in INSTALL
check_group_uucp(): error testing lock file creation Error details:Permission deniedcheck_lock_status: No permission to create lock file.
please see: How can I use Lock Files with rxtx? in INSTALL
check_group_uucp(): error testing lock file creation Error details:Permission deniedcheck_lock_status: No permission to create lock file.
please see: How can I use Lock Files with rxtx? in INSTALL
check_group_uucp(): error testing lock file creation Error details:Permission deniedcheck_lock_status: No permission to create lock file.
please see: How can I use Lock Files with rxtx? in INSTALL
check_group_uucp(): error testing lock file creation Error details:Permission deniedcheck_lock_status: No permission to create lock file.
please see: How can I use Lock Files with rxtx? in INSTALL
check_group_uucp(): error testing lock file creation Error details:Permission deniedcheck_lock_status: No permission to create lock file.
please see: How can I use Lock Files with rxtx? in INSTALL
check_group_uucp(): error testing lock file creation Error details:Permission deniedcheck_lock_status: No permission to create lock file.
please see: How can I use Lock Files with rxtx? in INSTALL
check_group_uucp(): error testing lock file creation Error details:Permission deniedcheck_lock_status: No permission to create lock file.
please see: How can I use Lock Files with rxtx? in INSTALL
check_group_uucp(): error testing lock file creation Error details:Permission deniedcheck_lock_status: No permission to create lock file.
please see: How can I use Lock Files with rxtx? in INSTALL
check_group_uucp(): error testing lock file creation Error details:Permission deniedcheck_lock_status: No permission to create lock file.
please see: How can I use Lock Files with rxtx? in INSTALL
check_group_uucp(): error testing lock file creation Error details:Permission deniedcheck_lock_status: No permission to create lock file.
please see: How can I use Lock Files with rxtx? in INSTALL
check_group_uucp(): error testing lock file creation Error details:Permission deniedcheck_lock_status: No permission to create lock file.
please see: How can I use Lock Files with rxtx? in INSTALL
check_group_uucp(): error testing lock file creation Error details:Permission deniedcheck_lock_status: No permission to create lock file.
please see: How can I use Lock Files with rxtx? in INSTALL
[Ljava.lang.String;@d1e233
The first three lines and last line are white all else red
What does this mean? I continued trying to just assign the port with Serial myPort; then myPort = new Serial(this,Serial.list()[0],9600); . Later on all I have to do is write to the port.
I am not directly connected to this port as I am accessing the file which is on the server and not my computer, the port on the server is dev/ttyS0 (yes, I'm on a Linux system, fedora), is there a way to use that instead of the Serial.list()?