?
Solved

Parallel Port access with C#

Posted on 2004-05-01
6
Medium Priority
?
447 Views
Last Modified: 2012-06-27
I'm looking for some help on writing to the parallel port within WinXP Pro using C#.  I'm not sure how this is done and I can't find any substantial resources online.  All I want to do is be able to write a byte, that's it, nothing else.

Thanks
0
Comment
Question by:ChaveTech
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 5

Expert Comment

by:jjacksn
ID: 10969965
This should do it:

http://www.codeproject.com/csharp/csppleds.asp?df=100&forumid=21021&exp=0&select=799135

In addition, you could always write it in a C++ com and interop to it.
0
 

Author Comment

by:ChaveTech
ID: 10970057
I've been to that site and have tried it, but it's not working.  I don't know if the DLL the author provides is valid.  I don't have a problem writing it in C++, but I'm not familiar with writing in COM.  Do you have any suggestions?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 5

Expert Comment

by:jjacksn
ID: 10970873
ChaveTech,

With com, all you need to do is create an ATL com object.  Use the template.  Add a method called to the COM interface you create called WriteParallelByte which takes in a byte (as an int).  You can then simply include this in a C# project by adding a reference to the COM object (dll).  .NET Studio will then automatically create an interop dll that will allow you to instantiate this com object and make the call.
0
 
LVL 4

Accepted Solution

by:
philippe_leybaert earned 2000 total points
ID: 11003906
If you just want to write some bytes or text to the parallel port, you can create an output file stream that maps to the parallel port:

The drawback is that you need to call unmanaged code from kernel32.dll

class myClass
{            
   [DllImport("kernel32.dll", CharSet=CharSet.Unicode)]
   private static extern IntPtr CreateFile(
                    string lpFileName,
                    [MarshalAs(UnmanagedType.U4)] uint dwDesiredAccess,
                    [MarshalAs(UnmanagedType.U4)] int dwShareMode,
                    [MarshalAs(UnmanagedType.U4)] uint lpSecurityAttributes,
                    [MarshalAs(UnmanagedType.U4)] int dwCreationAttributes,
                    [MarshalAs(UnmanagedType.U4)] int dwFlagsAndAttributes,
                    IntPtr hTemplateFile
                   );

   public FileStream createLPT1_FS()
   {
      IntPtr h = CreateFile("LPT1",0xC0000000,0,0,3,0,(IntPtr)0);

      return new FileStream(h,FileAccess.ReadWrite);
   }
}
0
 
LVL 5

Expert Comment

by:jjacksn
ID: 11006866
Windows knows how to Map files like this?  I had no idea....
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question