plot - rs232 communication, general timing -
i have piece of hardware sends out byte of data representing voltage signal @ frequency of 100hz on serial port.
i want write program read in data can plot it. know need open serial port , open inputstream. next part confusing me , i'm having trouble understanding process conceptually:
i create while loop reads in data inputstream 1 byte @ time. how while loop timing there byte available read whenever reaches readbyte line? i'm guessing can't put sleep function inside while loop try , match hardware sample rate. matter of continuing reading inputstream in while loop, , if it's fast won't (since there's no new data), , if it's slow accumulate in inputstream buffer?
like said, i'm trying understand conceptually guidance appreciated! i'm guessing idea independent of programming language i'm using, if not, assume use in java.
if using java communications api not polling @ all. instead implement serialporteventlistener , receive callback when there data available port.
public class serialconnection implements serialporteventlistener { private serialport sport; ... // add object event listener serial port. try { sport.addeventlistener(this); } catch (toomanylistenersexception e) { sport.close(); throw new serialconnectionexception("too many listeners added"); } ...
Comments
Post a Comment