none
How to send text string to the parallel port in C#? RRS feed

  • Question

  • I want to make codes to send text string to the parallel port.

    How to do it?

    And currently my laptop doesn't have parallel port.

    Is there any way to test it from my laptop?

    Friday, March 15, 2019 5:34 PM

Answers

  • If you know your parallel port is on LPT1, then your previous strategy should still work.  Just open the special-named file and write to it, like you would write to any other file.  Those special names are still around.

    using (BinaryWriter writer = new BinaryWriter(File.Open("LPT1", FileMode.OpenOrCreate, FileAccess.Write)))
    {
        writer.Write("Hello, world.\n");
    }

    If you need to do two-way communication or use ECP or EPP capabilities, then your task becomes more complicated, but just to blast a string out is easy.  There is code here that uses P/Invoke to call the Win32 file APIs, but I don't THINK it should be necessary.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/cb34a005-0545-40df-b031-5e945ec0eb95/sending-info-to-lpt-port-from-c


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    • Marked as answer by Jeff0803 Saturday, March 16, 2019 3:11 PM
    Friday, March 15, 2019 9:31 PM

All replies

  • Hello,

    1. Parallel Port, at least implementation I have, have functionality to send String's. Limitation for buffer and transfers speed need to be checked.

    2. Parallel Port is not designed to send String's. It designed to transfer single byte, 7 or 8 bits, and one or two bits to detect simple errors. So, You configure port to transmit 8-bits byte, configure receiver on the same manner, convert String's to byte[] and transmit byte by byte, checking possible buffer overflow...


    Sincerely, Highly skilled coding monkey.

    Friday, March 15, 2019 5:44 PM
  • I've made code for printing dot matix(parallel communication) printer long time ago in DOS age.

    I just opened LPT1 port using fopen() and wrote text using just fwrite(I don't remember exactly but fwrite or fprint function in C language)

    I didn't have to check anything.

    Do you mean I should control each pin(D1~D8) from C#?

    Friday, March 15, 2019 9:00 PM
  • If you know your parallel port is on LPT1, then your previous strategy should still work.  Just open the special-named file and write to it, like you would write to any other file.  Those special names are still around.

    using (BinaryWriter writer = new BinaryWriter(File.Open("LPT1", FileMode.OpenOrCreate, FileAccess.Write)))
    {
        writer.Write("Hello, world.\n");
    }

    If you need to do two-way communication or use ECP or EPP capabilities, then your task becomes more complicated, but just to blast a string out is easy.  There is code here that uses P/Invoke to call the Win32 file APIs, but I don't THINK it should be necessary.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/cb34a005-0545-40df-b031-5e945ec0eb95/sending-info-to-lpt-port-from-c


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    • Marked as answer by Jeff0803 Saturday, March 16, 2019 3:11 PM
    Friday, March 15, 2019 9:31 PM
  • I have two more questions.

    1. In case of two-way communication or ECP/EPP, is the simple way(Open,Write...) still used and add more functions? or totally different way to send data?

    2. My laptop has no parallel port and no parallel device to test with. Is there any way to test, like virtual parallel port & device?

    • Edited by Jeff0803 Saturday, March 16, 2019 3:21 PM
    Saturday, March 16, 2019 3:18 PM
  • I need to control font size before I send text.

    Actually parallel printer is the ticket printer.

    How to control the font size?

    Wednesday, April 3, 2019 5:13 PM