Ok, I did a little fiddling. Instead of processing, I wrote a tiny C program. I'll attach the code below.
It sends the 7 byte pin command and measures the time until the 4 byte ack is received.
I tested on Mac OS-X 10.5.8 on a 2.4 GHz (Intel) Macbook. Here's what I got:
For Duemilanove:
port /dev/cu.usbserial-A800daD3 opened, waiting for board to boot up
sending 7 bytes, read 4 bytes, elased: 11.75 ms
sending 7 bytes, read 4 bytes, elased: 15.96 ms
sending 7 bytes, read 4 bytes, elased: 15.96 ms
sending 7 bytes, read 4 bytes, elased: 15.96 ms
sending 7 bytes, read 4 bytes, elased: 15.87 ms
sending 7 bytes, read 4 bytes, elased: 16.02 ms
sending 7 bytes, read 4 bytes, elased: 15.96 ms
sending 7 bytes, read 4 bytes, elased: 15.96 ms
sending 7 bytes, read 4 bytes, elased: 15.96 ms
sending 7 bytes, read 4 bytes, elased: 15.96 ms
For Uno:
port /dev/cu.usbmodem411 opened, waiting for board to boot up
sending 7 bytes, read 4 bytes, elased: 3.56 ms
sending 7 bytes, read 4 bytes, elased: 3.96 ms
sending 7 bytes, read 4 bytes, elased: 3.96 ms
sending 7 bytes, read 4 bytes, elased: 3.97 ms
sending 7 bytes, read 4 bytes, elased: 3.97 ms
sending 7 bytes, read 4 bytes, elased: 3.96 ms
sending 7 bytes, read 4 bytes, elased: 3.96 ms
sending 7 bytes, read 4 bytes, elased: 4.98 ms
sending 7 bytes, read 4 bytes, elased: 3.96 ms
sending 7 bytes, read 4 bytes, elased: 3.96 ms
For Teensy (with Serial.send_now() added)
port /dev/cu.usbmodem12341 opened, waiting for board to boot up
sending 7 bytes, read 4 bytes, elased: 0.85 ms
sending 7 bytes, read 4 bytes, elased: 0.95 ms
sending 7 bytes, read 4 bytes, elased: 0.87 ms
sending 7 bytes, read 4 bytes, elased: 1.03 ms
sending 7 bytes, read 4 bytes, elased: 0.98 ms
sending 7 bytes, read 4 bytes, elased: 0.96 ms
sending 7 bytes, read 4 bytes, elased: 0.96 ms
sending 7 bytes, read 4 bytes, elased: 0.96 ms
sending 7 bytes, read 4 bytes, elased: 0.96 ms
sending 7 bytes, read 4 bytes, elased: 0.96 ms
Here is the (admittedly ugly and quickly tossed together) C program:
// compile with: gcc -O2 -Wall -o latency_test latency_test.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <fcntl.h>
#include <poll.h>
#include <termios.h>
#include <unistd.h>
#define PORT "/dev/cu.usbserial-A800daD3" // Duemilanove
//#define PORT "/dev/cu.usbmodem411" // Uno
//#define PORT "/dev/cu.usbmodem12341" // Teensy
//#define PORT "/dev/ttyUSB0" // Duemilanove on Linux
//#define PORT "/dev/ttyACM0" // Uno or Teensy on Linux
#define BAUD B115200
void die(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
int main()
{
int r, fd, count;
struct termios tinfo;
unsigned char buf[7];
struct pollfd fds;
struct timeval begin, end;
double elapsed;
fd = open(PORT, O_RDWR);
if (fd < 0) die("unable to open port %s\n", PORT);
if (tcgetattr(fd, &tinfo) < 0) die("unable to get serial parms\n");
if (cfsetspeed(&tinfo, B115200) < 0) die("error in cfsetspeed\n");
if (tcsetattr(fd, TCSANOW, &tinfo) < 0) die("unable to set baud rate\n");
printf("port %s opened, waiting for board to boot up\n", PORT);
sleep(3);
for (count=0; count < 10; count++) {
// send the ping request
buf[0] = 1;
buf[1] = 0;
buf[2] = 1;
buf[3] = 4;
buf[4] = 0x10;
buf[5] = 2;
buf[6] = 0x20;
printf("sending 7 bytes");
gettimeofday(&begin, NULL);
r = write(fd, buf, 7);
if (r != 7) die("unable to write, r = %d\n", r);
// wait for a responds
fds.fd = fd;
fds.events = POLLIN;
poll(&fds, 1, 500);
r = read(fd, buf, 4);
gettimeofday(&end, NULL);
printf(", read %d bytes", r);
if (r != 4) die ("unable to read 4 bytes\n");
elapsed = (double)(end.tv_sec - begin.tv_sec) * 1000.0;
elapsed += (double)(end.tv_usec - begin.tv_usec) / 1000.0;
printf(", elased: %.2f ms\n", elapsed);
}
close(fd);
return 0;
}
void die(const char *format, ...)
{
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
exit(1);
}