1

I'm attempting to use one of the pins from the serial port to toggle some outside hardware. I want to be able to call a batch file or something similar to be able to turn on/off the output of the pin. Is there a simple way to do this?

Ideally i'd like to be able to do this with a USB port as well but I'd image it will be harder to do. Is this the case is it easy to flip one pin on a usb port?

Cheers,

Mark

skaffman
  • 398,947
  • 96
  • 818
  • 769
Mark
  • 113
  • 5
  • 1
    What is your platform by the way? Windows NT series (2k, XP, Vista, 7); DOS (DOS, Win 3.1, Win9x); Unix (Linux, Unix, MacOS)? – Matthew Whited Jan 12 '11 at 21:01

2 Answers2

3

You can do this with a serial port, even with a USB to RS232 adapter.

The easiest way to do it is to bring up the DSR/DTR lines. The easiest way to bring up those lines is by simply opening the port with most software. I could help you more, but I don't know what platform you're targeting.

See the pinout here: http://www.aggsoft.com/rs232-pinout-cable/pinout-and-signal.htm

Brad
  • 159,648
  • 54
  • 349
  • 530
1

If you have a LPT (Line Printer Terminal) that would be your best bet. You would also be able to use a USB-2-LPT adapter. More options would be USB Digital I/O device. You will probably want something that uses either parallel output or has digital IO pins (such as this). Trying to use a serial port to control something external will require a UART device to convert the serial signal into the parallel bits.

(Even more fun... Bluetooth to GPIO)

Edit to make some happy...

Yes you could control the hardware control pins for single bits of input/output with a serial port. As to the point about USB-LPT, that could be the case depending on the particular hardware or platform btu I have yet to run into it as an issue.

Matthew Whited
  • 22,160
  • 4
  • 52
  • 69
  • Thanks Matthew. LTP port works great. I'm not actually transferring any data simply toggling what amounts to a relay. links for anyone else that finds this: http://www.epanorama.net/circuits/parallel_output.html http://electrosofts.com/parallel/index.html http://www.lvr.com/parport.htm – Mark Jan 12 '11 at 21:25
  • Factually incorrect claim in this answer. A serial port will not require a UART for external interface if one of the control signals is used rather than the actual serial data pin. Also be aware that many USB-LPT adapters are not register accessible for static byte output the way that a true parallel port is, though again you probably can set the control signals. – Chris Stratton Jan 18 '11 at 03:30
  • You could use a control signal for 1 bit and every usb-lpt device I have worked with works as a normal LPT port allowign you to manage the output byte... but thanks for playing. – Matthew Whited Jan 18 '11 at 11:37
  • Raw write to the LPT port address is not going to accomplish anything with a USB LPT adapter, unless you have an O/S level driver that traps that I/O access and redirects it, and one of the rare pieces of hardware that is addressable in such fashion. Most are not, because raw byte access is an inefficient way of actually printing - USB is a high latency interface that works best with buffers of data, not raw bytes and bit banging of the strobe line. Most people gave up on trying to source byte addressable adapters long ago and go for USB I/O chips such as FT245 family instead. – Chris Stratton Jan 18 '11 at 17:15
  • The way you address any device in a system with protected memory is always going to be different. And most of the time will not be direct memory access. But that doesn't prevent a driver for an usb-lpt device from acting as an lpt device as far as an application is concerned. The reason I didn't list memory addresses and provide source code is I don't even know what platform the guy is using (other than he says `batch file` which leads me to believe DOS or Windows.) – Matthew Whited Jan 18 '11 at 18:42
  • A true parallel port can be accessed via well-known registers on any O/S which provides a means (for user or kernel code) to do I/O access. But a driver for a USB-lpt device typically implements the interface needed to print documents, not to directly manipulate the I/O pins - only a minority of the hardware sold actually has that capability, as it's not useful for printing. And there's no standard for how this would be exposed to an application. For actual I/O tasks people long ago learned to use dedicated USB I/O chips, which don't cost any more anyway. – Chris Stratton Jan 19 '11 at 17:47
  • On windows you can just open an I/O stream to a device (such as COM or LPT) and when you send byte data to the stream it will do the correct signaling of the pins. (I have done it on every version of windows since 3.11 to 7) I do believe I commented on a USB I/O device as well as a Bluetooth version. I'm fairly certain you can do the same on Linux... it's just been a few years since I've done programming over there. – Matthew Whited Jan 19 '11 at 18:31
  • Stream type access, which is to say sending a stream of bytes with the strobe appropriately toggled - which USB LPT adapaters are designed to support (as it's useful for printing) - is far different from raw manipulation of the signal states as a simple I/O register, which you used to be able to do with a genuine parallel port. Most USB LPT adapter hardware lacks that capability, so instead people who need raw access use USB I/O chips like the FT245 family and its successors instead of USB LPT adapters. – Chris Stratton Jan 24 '11 at 06:09