sending string data to parallel port?
-
hi everyone, is there any way through which i can send sring data to a parallel port using C#.net... thanks in advance...
Hi yes there is. you can open the Parallel port open as a file and use FileStream to write on it. something like this:
public class ParallelWriter { //Constants for dwFlagsAndAttributes: public const UInt32 FILE_FLAG_OVERLAPPED = 0x40000000; //Constants for dwCreationDisposition: public const UInt32 OPEN_EXISTING = 3; //Constants for dwDesiredAccess: public const UInt32 GENERIC_READ = 0x80000000; public const UInt32 GENERIC_WRITE = 0x40000000; [DllImport("kernel32.dll", SetLastError=true)] private static extern IntPtr CreateFile(String lpFileName, UInt32 dwDesiredAccess, UInt32 dwShareMode, IntPtr lpSecurityAttributes, UInt32 dwCreationDisposition, UInt32 dwFlagsAndAttributes, IntPtr hTemplateFile); private FileStream strm; public FileStream Stream { get { return strm; } } public ParallelWriter(string Port) { IntPtr Handle = CreateFile(Port,GENERIC_READ|GENERIC_WRITE,0,IntPtr.Zero,OPEN_EXISTING,FILE_FLAG_OVERLAPPED,IntPtr.Zero); strm = new FileStream(Handle,FileAccess.ReadWrite,true,1,true); } }
now just use the Stream to write your data to the Parallelport greets m@u -
Hi yes there is. you can open the Parallel port open as a file and use FileStream to write on it. something like this:
public class ParallelWriter { //Constants for dwFlagsAndAttributes: public const UInt32 FILE_FLAG_OVERLAPPED = 0x40000000; //Constants for dwCreationDisposition: public const UInt32 OPEN_EXISTING = 3; //Constants for dwDesiredAccess: public const UInt32 GENERIC_READ = 0x80000000; public const UInt32 GENERIC_WRITE = 0x40000000; [DllImport("kernel32.dll", SetLastError=true)] private static extern IntPtr CreateFile(String lpFileName, UInt32 dwDesiredAccess, UInt32 dwShareMode, IntPtr lpSecurityAttributes, UInt32 dwCreationDisposition, UInt32 dwFlagsAndAttributes, IntPtr hTemplateFile); private FileStream strm; public FileStream Stream { get { return strm; } } public ParallelWriter(string Port) { IntPtr Handle = CreateFile(Port,GENERIC_READ|GENERIC_WRITE,0,IntPtr.Zero,OPEN_EXISTING,FILE_FLAG_OVERLAPPED,IntPtr.Zero); strm = new FileStream(Handle,FileAccess.ReadWrite,true,1,true); } }
now just use the Stream to write your data to the Parallelport greets m@u