cserial-portlpt

How can I send hex data through a serial port into a custom instrument using C?


I have a machine (instrument) that can read hexadecimal numbers separately from 8 pins in Serial Port or Printer.

I want to send hexadecimal data from a C Program running on a computer into this machine. The computer and machine are connected via the printer port.

Please let me know how can I send my data from each pin separately.

Thanks in Advance.


Solution

  • First, Some clarification:

    Serial communication is a protocol that uses all (most) of the pins. Some pins are used for synchronising the two communication chips. But the actual data is sent out of ONE DATA PIN, one BIT at a time.

    Parallel communication on the other hand is a protocol that uses 8 DATA PINS to simultaneously communicate one BYTE at a time. Printer ports are usually parallel ports.

    Depends on OS:

    How you send data from a program via either of these ports depends on your operating system.

    It's easier on Linux than on Windows.

    For Windows, it's a bit more complicated, because Windows puts restrictions on port access in user mode (i.e. by user programs).

    For Parallel Port on Windows:

    However, for Windows I have successfully driven LEDs off the parallel port using the io.dll provided here on Geek Hideout. The io.dll package contains a .dll and a .h header file documenting the functions which your C program can use.

    For Serial Port on Linux:

    See the code from this answer and this Serial HOWTO (for Linux)