Interesting about the manufacturer app functioning without delay. I don't have a PL2303 on hand to test, but I confirmed that my FTDI devices have a long delay just for the `open()` and `close()` syscalls on Sequoia 15.1.1. The below code compiles with clang, so you can build and run with `clang -o porttest porttest.c && ./porttest /path/to/port`.
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
double diff_timespec(const struct timespec *lhs, const struct timespec *rhs)
{
return lhs->tv_sec - rhs->tv_sec + (lhs->tv_nsec - rhs->tv_nsec) / 1000000000.0;
}
int main(int argc, char ** argv)
{
if (argc != 2)
{
printf("Usage: %s <port>\n", argv[0]);
return 1;
}
for (int i = 0; i < 5; ++i)
{
struct timespec start, opened, closed;
clock_gettime(CLOCK_MONOTONIC, &start);
int fd = open(argv[1], O_RDWR | O_NONBLOCK);
if (fd < 0)
{
printf("Opening %s failed with errno %d (%s)\n", argv[1], errno, strerror(errno));
return 2;
}
clock_gettime(CLOCK_MONOTONIC, &opened);
printf("opened %d in %lf\n", i, diff_timespec(&opened, &start));
if (close(fd) < 0)
{
printf("Closing %s failed with errno %d (%s)\n", argv[1], errno, strerror(errno));
return 2;
}
clock_gettime(CLOCK_MONOTONIC, &closed);
printf("closed %d in %lf\n", i, diff_timespec(&closed, &opened));
}
}
I consistently get ~0.5 seconds to open, ~1.5 seconds to close:
❯ clang -o porttest porttest.c && ./porttest /dev/my-port-devname 10s 19:45:11
opened 0 in 0.513056
closed 0 in 1.509778
opened 1 in 0.511126
closed 1 in 1.509884
opened 2 in 0.516253
closed 2 in 1.507144
opened 3 in 0.512745
closed 3 in 1.508266
opened 4 in 0.511512
closed 4 in 1.50949