Optimizing Serial Read/Write Routines
-
Right now my Serial Library works. i can read/write correctly, However i do not think I am doing it optimally and I know that I am not doing it the overlapped way. So maybe you could help me to optimize my serial read/write function so that it is done correctly. Right now i am using a for loop to read X number of bytes from the port. Problem with this method is that it will loop forever if X # of bytes are never read. What I want to be able to do is read from the port until there is no more bytes to read. That way i dont always need to know how many bytes I need to read and the read wont block the program flow indefinitely. Below is a sample of how i would currently read from the port:
= Buf; //put byte read into array x++; //increment array pointer } } //else loop and try againThis just seems horribly inefficient to me. Anyone else think so? -
Right now my Serial Library works. i can read/write correctly, However i do not think I am doing it optimally and I know that I am not doing it the overlapped way. So maybe you could help me to optimize my serial read/write function so that it is done correctly. Right now i am using a for loop to read X number of bytes from the port. Problem with this method is that it will loop forever if X # of bytes are never read. What I want to be able to do is read from the port until there is no more bytes to read. That way i dont always need to know how many bytes I need to read and the read wont block the program flow indefinitely. Below is a sample of how i would currently read from the port:
= Buf; //put byte read into array x++; //increment array pointer } } //else loop and try againThis just seems horribly inefficient to me. Anyone else think so?You may want to take some ideas from Ramon de Klein's Serial library[^]. Behind every great black man... ... is the police. - Conspiracy brother Blog[^]