Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I'm creating a progam, which shall communicate with a device through a parallel port. Is it possible to create a virtual parallel connection for testing?
Posted

Not in C#. You'll (ideally) need C++ and the Windows Driver Kit[^].

I hope you know how to write device drivers...
 
Share this answer
 
Hi,
Maybe you don't need to know how to write drivers. If I understand well you need somthing to simulate device. Have you tried adding another layer of abstraction?
Add an interface:
C#
interface IParallelPort
 {
     void Output(int address, int value);
     int Input(int address);
 }

When device is plugged implement it the normal way
C#
class RealPort : IParallelPort
{
    [DllImport("inpout32.dll", EntryPoint = "Out32")]
    private static extern void Out32(int address, int value);
    [DllImport("inpout32.dll", EntryPoint = "Inp32")]
    private static extern int Inp32(int address);
    void IParallelPort.Output(int address, int value)
    {
        Out32(address, value);
    }
    int IParallelPort.Input(int address)
    {
        return Inp32(address);
    }
}

For testing use fake class:
C#
class FakePort : IParallelPort
 {
     void IParallelPort.Output(int address, int value)
     {            //simulate output
     }
     int IParallelPort.Input(int address)
     {            //simulate input
     }
 }


Use factory method to switch between those two ports.
Hope it helps.
 
Share this answer
 

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