Hacker News new | ask | show | jobs
by NateLawson 1230 days ago
There's another reason why USB-to-parallel adaptors can't replace a PC with a printer port: the latency for round-trip applications is significantly higher over USB. It takes a few microseconds to read/write a byte from a PC printer port. Over USB, the control message latency leads to this taking tens of milliseconds. USB beats it on throughput, but only when transferring lots of data.

Before they disappeared, printer ports on motherboards began getting worse for latency and compatibility. This was likely due to cost reduction since low latency two-way communication was not needed for printing.

There was an interface for old Commodore floppy drives that is just remapped pins on the printer port[1]. When PC's circa 2005 stopped working with it, I designed a USB microcontroller board to implement the protocol[2]. It had to do some fancy state machines to get around the round-trip problem, caching a set of commands until the host was ready for the transfer. Then it would send them all back-to-back and start streaming back the bulk data. Fun stuff.

[1] https://www.c64-wiki.com/wiki/X1541

[2] http://www.root.org/~nate/c64/xum1541/

1 comments

> Over USB, the control message latency leads to this taking tens of milliseconds.

This sounds an order of magnitude wrong. I have just setup a loopback with a CH340 USB to serial adapter and ran the following code:

  #!/usr/bin/python3
  import serial
  import time
  
  ser = serial.Serial(port="/dev/ttyUSB0", baudrate=1_000_000, timeout=1)
  
  iters = 100
  x = time.time()
  for i in range(iters):
    towrite = b"%i\n"%i
    ser.write(towrite)
    line = ser.readline()
    assert(line == towrite)
  delta_ms = (time.time() - x)*1000

  print("Finished %i iterations in %ims = %.1fms/iteration"%(iters, delta_ms, delta_ms/iters))
and it says Finished 100 iterations in 272ms = 2.7ms/iteration