By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,992 Members | 934 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,992 IT Pros & Developers. It's quick & easy.

Doing I/O to the Printer port and legacy IO space in C# ?

P: n/a
What is the way to send/read bits to the printer port at the hex 3F8-3FF or
any other legacy io space??

Does C# include the methods to drive the printer or other ports?

tia
Nov 16 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Bradley1234,

AFAIK, there is nothing in .NET to access it. You might have to
actually use CreateFileEx and pass LPT1 (assuming your printer is connected
to that) in order to write to the printer port (there might also be a more
elegant way, but I am not sure).

However, you will most likely have to access the API in order to
read/write bits directly to the printer attached to a port.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Bradley1234" <so*****@yahoo.com> wrote in message
news:fcJtd.2513$N%6.101@trnddc05...
What is the way to send/read bits to the printer port at the hex 3F8-3FF
or
any other legacy io space??

Does C# include the methods to drive the printer or other ports?

tia

Nov 16 '05 #2

P: n/a
Thanks Nicholas,

I found one site so far, http://www.codeproject.com/csharp/csppleds.asp
that claims a way to do this with their .dll (Im unable to copy text from
the site) but when I entered their code verbatim? Errors,

using System.Runtime.InteropServices;

.... windows generated form1 + declarations

public class portAccess

{
[DllImport{"inpout32.dll", EntryPoint="Out32")]

* *

// syntax error, "]" expected and "{" is invalid token, "=" invalid
token
public static extern void Output(int adress, int value);

}

There is no help available for "DllImport" or its syntax that I could find

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@TK2MSFTNGP12.phx.gbl...
Bradley1234,

AFAIK, there is nothing in .NET to access it. You might have to
actually use CreateFileEx and pass LPT1 (assuming your printer is connected to that) in order to write to the printer port (there might also be a more
elegant way, but I am not sure).

However, you will most likely have to access the API in order to
read/write bits directly to the printer attached to a port.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Bradley1234" <so*****@yahoo.com> wrote in message
news:fcJtd.2513$N%6.101@trnddc05...
What is the way to send/read bits to the printer port at the hex 3F8-3FF
or
any other legacy io space??

Does C# include the methods to drive the printer or other ports?

tia


Nov 16 '05 #3

P: n/a
Bradley1234,

The declaration should be:

[DllImport("inpout32.dll", EntryPoint="Out32")]

Not:

[DllImport{"inpout32.dll", EntryPoint="Out32")]

Notice the bracket instead of the open parenthesis.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Bradley1234" <so*****@yahoo.com> wrote in message
news:REJtd.639$Qp.189@trnddc01...
Thanks Nicholas,

I found one site so far, http://www.codeproject.com/csharp/csppleds.asp
that claims a way to do this with their .dll (Im unable to copy text
from
the site) but when I entered their code verbatim? Errors,

using System.Runtime.InteropServices;

... windows generated form1 + declarations

public class portAccess

{
[DllImport{"inpout32.dll", EntryPoint="Out32")]

* *

// syntax error, "]" expected and "{" is invalid token, "=" invalid
token
public static extern void Output(int adress, int value);

}

There is no help available for "DllImport" or its syntax that I could find

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:%2****************@TK2MSFTNGP12.phx.gbl...
Bradley1234,

AFAIK, there is nothing in .NET to access it. You might have to
actually use CreateFileEx and pass LPT1 (assuming your printer is

connected
to that) in order to write to the printer port (there might also be a
more
elegant way, but I am not sure).

However, you will most likely have to access the API in order to
read/write bits directly to the printer attached to a port.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Bradley1234" <so*****@yahoo.com> wrote in message
news:fcJtd.2513$N%6.101@trnddc05...
> What is the way to send/read bits to the printer port at the hex
> 3F8-3FF
> or
> any other legacy io space??
>
> Does C# include the methods to drive the printer or other ports?
>
> tia
>
>



Nov 16 '05 #4

P: n/a
Hey thanks, that works so much better!

But... it cannot or will not add inpout32.dll

It cannot be added because its not a valid assembly... Okay I need to
compile it somehow? or run it by something in the command line?
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2******************@TK2MSFTNGP12.phx.gbl...
Bradley1234,

The declaration should be:

[DllImport("inpout32.dll", EntryPoint="Out32")]

Not:

[DllImport{"inpout32.dll", EntryPoint="Out32")]

Notice the bracket instead of the open parenthesis.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Bradley1234" <so*****@yahoo.com> wrote in message
news:REJtd.639$Qp.189@trnddc01...
Thanks Nicholas,

I found one site so far, http://www.codeproject.com/csharp/csppleds.asp
that claims a way to do this with their .dll (Im unable to copy text
from
the site) but when I entered their code verbatim? Errors,

using System.Runtime.InteropServices;

... windows generated form1 + declarations

public class portAccess

{
[DllImport{"inpout32.dll", EntryPoint="Out32")]

* *

// syntax error, "]" expected and "{" is invalid token, "=" invalid
token
public static extern void Output(int adress, int value);

}

There is no help available for "DllImport" or its syntax that I could find
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:%2****************@TK2MSFTNGP12.phx.gbl...
Bradley1234,

AFAIK, there is nothing in .NET to access it. You might have to
actually use CreateFileEx and pass LPT1 (assuming your printer is

connected
to that) in order to write to the printer port (there might also be a
more
elegant way, but I am not sure).

However, you will most likely have to access the API in order to
read/write bits directly to the printer attached to a port.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Bradley1234" <so*****@yahoo.com> wrote in message
news:fcJtd.2513$N%6.101@trnddc05...
> What is the way to send/read bits to the printer port at the hex
> 3F8-3FF
> or
> any other legacy io space??
>
> Does C# include the methods to drive the printer or other ports?
>
> tia
>
>



Nov 16 '05 #5

P: n/a
Bradley,

It's not a managed assembly, so you don't add it to the references for
your project. Rather, you have to make sure it is located where LoadLibrary
can find it (try in the directory the executable runs from, etc, etc).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bradley1234" <so*****@yahoo.com> wrote in message
news:feKtd.644$Qp.308@trnddc01...
Hey thanks, that works so much better!

But... it cannot or will not add inpout32.dll

It cannot be added because its not a valid assembly... Okay I need to
compile it somehow? or run it by something in the command line?
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:%2******************@TK2MSFTNGP12.phx.gbl...
Bradley1234,

The declaration should be:

[DllImport("inpout32.dll", EntryPoint="Out32")]

Not:

[DllImport{"inpout32.dll", EntryPoint="Out32")]

Notice the bracket instead of the open parenthesis.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Bradley1234" <so*****@yahoo.com> wrote in message
news:REJtd.639$Qp.189@trnddc01...
> Thanks Nicholas,
>
> I found one site so far, http://www.codeproject.com/csharp/csppleds.asp
> that claims a way to do this with their .dll (Im unable to copy text
> from
> the site) but when I entered their code verbatim? Errors,
>
> using System.Runtime.InteropServices;
>
> ... windows generated form1 + declarations
>
> public class portAccess
>
> {
>
>
> [DllImport{"inpout32.dll", EntryPoint="Out32")]
>
> * *
>
> // syntax error, "]" expected and "{" is invalid token, "=" invalid
> token
>
>
> public static extern void Output(int adress, int value);
>
> }
>
>
>
> There is no help available for "DllImport" or its syntax that I could find >
>
>
> "Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com>
> wrote
> in
> message news:%2****************@TK2MSFTNGP12.phx.gbl...
>> Bradley1234,
>>
>> AFAIK, there is nothing in .NET to access it. You might have to
>> actually use CreateFileEx and pass LPT1 (assuming your printer is
> connected
>> to that) in order to write to the printer port (there might also be a
>> more
>> elegant way, but I am not sure).
>>
>> However, you will most likely have to access the API in order to
>> read/write bits directly to the printer attached to a port.
>>
>> Hope this helps.
>>
>>
>> --
>> - Nicholas Paldino [.NET/C# MVP]
>> - mv*@spam.guard.caspershouse.com
>>
>>
>> "Bradley1234" <so*****@yahoo.com> wrote in message
>> news:fcJtd.2513$N%6.101@trnddc05...
>> > What is the way to send/read bits to the printer port at the hex
>> > 3F8-3FF
>> > or
>> > any other legacy io space??
>> >
>> > Does C# include the methods to drive the printer or other ports?
>> >
>> > tia
>> >
>> >
>>
>>
>
>



Nov 16 '05 #6

P: n/a
Hey getting closer, it runs with no complaints. I finally pasted the .dll
file in about 10 different folders, where the project is located, the debug,
bin, obj, every folder. and it found the one it wanted.

I like the built in exception handler with this C#, nice improvement.

At least its appearing to run, now I can leave for a bit, will try more
later, thanks for your help
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:eB**************@TK2MSFTNGP10.phx.gbl...
Bradley,

It's not a managed assembly, so you don't add it to the references for
your project. Rather, you have to make sure it is located where LoadLibrary can find it (try in the directory the executable runs from, etc, etc).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bradley1234" <so*****@yahoo.com> wrote in message
news:feKtd.644$Qp.308@trnddc01...
Hey thanks, that works so much better!

But... it cannot or will not add inpout32.dll

It cannot be added because its not a valid assembly... Okay I need to
compile it somehow? or run it by something in the command line?
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:%2******************@TK2MSFTNGP12.phx.gbl...
Bradley1234,

The declaration should be:

[DllImport("inpout32.dll", EntryPoint="Out32")]

Not:

[DllImport{"inpout32.dll", EntryPoint="Out32")]

Notice the bracket instead of the open parenthesis.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Bradley1234" <so*****@yahoo.com> wrote in message
news:REJtd.639$Qp.189@trnddc01...
> Thanks Nicholas,
>
> I found one site so far, http://www.codeproject.com/csharp/csppleds.asp > that claims a way to do this with their .dll (Im unable to copy text > from
> the site) but when I entered their code verbatim? Errors,
>
> using System.Runtime.InteropServices;
>
> ... windows generated form1 + declarations
>
> public class portAccess
>
> {
>
>
> [DllImport{"inpout32.dll", EntryPoint="Out32")]
>
> * *
>
> // syntax error, "]" expected and "{" is invalid token, "=" invalid > token
>
>
> public static extern void Output(int adress, int value);
>
> }
>
>
>
> There is no help available for "DllImport" or its syntax that I could

find
>
>
>
> "Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com>
> wrote
> in
> message news:%2****************@TK2MSFTNGP12.phx.gbl...
>> Bradley1234,
>>
>> AFAIK, there is nothing in .NET to access it. You might have to
>> actually use CreateFileEx and pass LPT1 (assuming your printer is
> connected
>> to that) in order to write to the printer port (there might also be a >> more
>> elegant way, but I am not sure).
>>
>> However, you will most likely have to access the API in order to
>> read/write bits directly to the printer attached to a port.
>>
>> Hope this helps.
>>
>>
>> --
>> - Nicholas Paldino [.NET/C# MVP]
>> - mv*@spam.guard.caspershouse.com
>>
>>
>> "Bradley1234" <so*****@yahoo.com> wrote in message
>> news:fcJtd.2513$N%6.101@trnddc05...
>> > What is the way to send/read bits to the printer port at the hex
>> > 3F8-3FF
>> > or
>> > any other legacy io space??
>> >
>> > Does C# include the methods to drive the printer or other ports?
>> >
>> > tia
>> >
>> >
>>
>>
>
>



Nov 16 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.