Re: Optimizing reading from Serial Port
Bryan Armstrong <bryan.armstrong-6tN4nzCoH/[email protected]>
| Newsgroups | gmane.comp.hardware.microcontrollers.tini |
|---|---|
| Message-ID | <[email protected]> |
Martin, Anabel wrote:
> We are communicating with an Omron PLC through TINI's serial
> port using a baudrate of 19200 bps. Our application sends some commands
> to the PLC and wait for the answers. We have tested the application with
> the PC and with TINI and we can observe some differences in the time
> that is needed to read data from serial port:
> - PC: 2,3 ms
> - TINI: 15 ms
>
> What reason could cause that difference?
Several factors may be involved including serial latency and parse overhead.
> outStream.write(commands); // Transmit the commands
Possibly follow this write by a flush().
> timer = timeOut + TINIOS.uptimeMillis();
> while (System.currentTimeMillis() < timer && !finished) {
^^^^^^^^^^^^^^^^^^^^^^^^^^^
Make this uptimeMillis().
> for (count = index; count < (bytesCount + index); count++)
^^^^^^^^^^^^^^^^^^^
Take this loop invariant out of the loop like this:
maxindex = bytesCount + index;
for (count = index; count < maxindex; count++)
> if (buffer [count] == RETURN) {
^^^^^^
Make sure these constant type values are declared static final so that
the code is inlined and no instance fields must be accessed.
-Bryan
--
--
Bryan Armstrong
bryan.armstrong-6tN4nzCoH/[email protected]
_______________________________________________
TINI mailing list
TINI-6tN4nzCoH/[email protected]
To UNSUBSCRIBE, edit your profile, or see list archives:
http://lists.dalsemi.com/mailman/listinfo/tini