Click here to Skip to main content
15,893,190 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
Only found the serialport control in windows form application.

How about parallel port?

If i want to send a character 'a' towards a device by LPT port.

How can i achieve this?
Posted

1 solution

If you have installed a generic printer text driver and have that set to the LPT1 port (pretty standard) , then you can print to LPT1 as if it was a file.

System.IO.StreamWriter writer = new System.IO.StreamWriter(@\\.\LPT1);
writer.Write("Hello World");
writer.Flush();
writer.Close();



You should read the Code Project article on parallel ports[^].


You can also find a lot of info on parallel ports here[^].

[added]
The above example code is in C#. For something in Visual Basic look at this article[^]
Read this Code Project article[^] on printing using Visual Basic.
 
Share this answer
 
v3
Comments
tuolesi 15-Oct-10 13:35pm    
erm
i try to translate it in vb however it giv me error
FileStream will not open Win32 devices such as disk partitions and tape drives. Avoid use of "\\.\" in the path.
BillW33 15-Oct-10 14:36pm    
Try reading this article on programming parallel ports: http://www.aaroncake.net/electronics/vblpt.htm
BillW33 15-Oct-10 14:43pm    
I updated my answer with a link to an article on using the parallel port with VB.
tuolesi 16-Oct-10 8:59am    
erm i doubt is it working in c#?
i try in c# but same error.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900