comp.lang.ada
 help / color / mirror / Atom feed
* Port LPT + ADA
@ 2004-12-03 13:56 S�awo - MIR
  2004-12-03 14:40 ` Martin Krischik
                   ` (3 more replies)
  0 siblings, 4 replies; 20+ messages in thread
From: S�awo - MIR @ 2004-12-03 13:56 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 650 bytes --]

Hi !

I try to read data in ADA from input register (pins: 10,11,12,13,15) of LPT
port and I can't do this :-(, with using a handle and function CreateFile(),
and then ReadFile() from Win32.Winbase.
The connection is probably made, but register is located in memmory address
379h, and I can't get there :-(
I know that way it can be read from COM port, but can I make it with the LPT
port too???
I don't know if I can do it with this functions CreateFile and ReadFile from
library Win32.Winbase. Maybe someone help me with LPT ?!? ;-( maybe someone
help me and send me a few lines of code? ;-)

PS Please, forgive me my English :/

S�awo - MIR





^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Port LPT + ADA
  2004-12-03 13:56 Port LPT + ADA S�awo - MIR
@ 2004-12-03 14:40 ` Martin Krischik
  2004-12-03 15:29   ` Slawo - MIR
  2004-12-03 18:43 ` tmoran
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 20+ messages in thread
From: Martin Krischik @ 2004-12-03 14:40 UTC (permalink / raw)


Sï¿œawo - MIR wrote:

> Hi !
> 
> I try to read data in ADA from input register (pins: 10,11,12,13,15) of
> LPT port and I can't do this :-(, with using a handle and function
> CreateFile(), and then ReadFile() from Win32.Winbase.
> The connection is probably made, but register is located in memmory
> address 379h, and I can't get there :-(

type Byte is mod 256;
Port : Byte;
for Port'Address use 16#379#;

> I know that way it can be read from COM port, but can I make it with the
> LPT port too???
> I don't know if I can do it with this functions CreateFile and ReadFile
> from library Win32.Winbase. Maybe someone help me with LPT ?!? ;-( maybe
> someone help me and send me a few lines of code? ;-)
> 
> PS Please, forgive me my English :/
> 
> Sï¿œawo - MIR

With Regards

Martin
-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Port LPT + ADA
  2004-12-03 14:40 ` Martin Krischik
@ 2004-12-03 15:29   ` Slawo - MIR
  2004-12-03 18:46     ` Martin Krischik
  0 siblings, 1 reply; 20+ messages in thread
From: Slawo - MIR @ 2004-12-03 15:29 UTC (permalink / raw)


> type Byte is mod 256;
> Port : Byte;
> for Port'Address use 16#379#;


Yes, but how to tie this whit function ReadFile( ) ??





^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Port LPT + ADA
  2004-12-03 13:56 Port LPT + ADA S�awo - MIR
  2004-12-03 14:40 ` Martin Krischik
@ 2004-12-03 18:43 ` tmoran
       [not found] ` <u111r0db4fsoj9u3hlkachspjt0r2vvup7@4ax.com>
  2004-12-04 18:05 ` Port LPT + ADA (whta do I wrong?) S�awo - MIR
  3 siblings, 0 replies; 20+ messages in thread
From: tmoran @ 2004-12-03 18:43 UTC (permalink / raw)


>register is located in memmory address 379h,
  No it's not.  It's located in IO address 379h, which can be referenced
by an IN or OUT machine instruction.  If you use Ada under MSDOS this is
trivial, but current versions of Windows block direct access to IO ports
so you'll have to call some kind of driver software.  Windows is not
designed for low level programming.



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Port LPT + ADA
  2004-12-03 15:29   ` Slawo - MIR
@ 2004-12-03 18:46     ` Martin Krischik
  0 siblings, 0 replies; 20+ messages in thread
From: Martin Krischik @ 2004-12-03 18:46 UTC (permalink / raw)


Slawo - MIR wrote:

>> type Byte is mod 256;
>> Port : Byte;
>> for Port'Address use 16#379#;

> Yes, but how to tie this whit function ReadFile( ) ??

You said you wanted to access a particular memory address and that is the
answer to it.

However, I am wondering if you don't need device driver to access a
particular memory location.

In fact: is the LPT port not output only and any input from it need to be
done by a specialized device driver?

If you have some C example we can convert it into Ada - that should not be a
problem.

Apart from that this might not be an Ada problem as such but a Operating
System.

With Regards

Martin
-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Port LPT + ADA
       [not found] ` <u111r0db4fsoj9u3hlkachspjt0r2vvup7@4ax.com>
@ 2004-12-03 23:03   ` Adrien Plisson
  2004-12-03 23:51     ` Slawo - MIR
  2004-12-04  0:51     ` Jeffrey Carter
  0 siblings, 2 replies; 20+ messages in thread
From: Adrien Plisson @ 2004-12-03 23:03 UTC (permalink / raw)


Dennis Lee Bieber wrote:
> 	As I recall, the ports are available under W9x, but not under
> the WinNT (includes XP) series.
> 
> 	Under WinNT, you pretty much need a system level driver designed
> to give such low-level access.

at a higher level you might try opening a file named "LPT1"...

using the CreateFile function passing "LPT1" as the file name, 
OPEN_EXISTING as dwCreationDisposition, and... well let's quote the MSDN:

Communications Resources
The CreateFile function can create a handle to a communications 
resource, such as the serial port COM1. For communications resources, 
the dwCreationDisposition parameter must be OPEN_EXISTING, and the 
hTemplate parameter must be NULL. Read, write, or read/write access can 
be specified, and the handle can be opened for overlapped I/O. For more 
information about communications, see Communications.

this is from the msdn library documentation for function CreateFile, 
available at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/createfile.asp

the communications chapter is available at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/communications_resources.asp

now, RTHM (with H as Huge), try, and come back to ask any (eventually 
Ada related) question if needed...

-- 
rien




^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Port LPT + ADA
  2004-12-03 23:03   ` Adrien Plisson
@ 2004-12-03 23:51     ` Slawo - MIR
  2004-12-04  0:51     ` Jeffrey Carter
  1 sibling, 0 replies; 20+ messages in thread
From: Slawo - MIR @ 2004-12-03 23:51 UTC (permalink / raw)



Thank you, probably only you really understood what I meant ;-)
I check it tomorrow.


> at a higher level you might try opening a file named "LPT1"...
>
> using the CreateFile function passing "LPT1" as the file name,
> OPEN_EXISTING as dwCreationDisposition, and... well let's quote the MSDN:
>
> Communications Resources
> The CreateFile function can create a handle to a communications
> resource, such as the serial port COM1. For communications resources,
> the dwCreationDisposition parameter must be OPEN_EXISTING, and the
> hTemplate parameter must be NULL. Read, write, or read/write access can
> be specified, and the handle can be opened for overlapped I/O. For more
> information about communications, see Communications.





^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Port LPT + ADA
  2004-12-03 23:03   ` Adrien Plisson
  2004-12-03 23:51     ` Slawo - MIR
@ 2004-12-04  0:51     ` Jeffrey Carter
  1 sibling, 0 replies; 20+ messages in thread
From: Jeffrey Carter @ 2004-12-04  0:51 UTC (permalink / raw)


Adrien Plisson wrote:

> at a higher level you might try opening a file named "LPT1"...
> 
> using the CreateFile function passing "LPT1" as the file name, 
> OPEN_EXISTING as dwCreationDisposition, and... well let's quote the MSDN:

At a higher level, you could use Ada's I/O facilities to open this file. 
I've written to LPT1 using Ada.Text_IO and creating the file; I've never 
tried reading from it.

-- 
Jeff Carter
"Don't knock masturbation. It's sex with someone I love."
Annie Hall
45




^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Port LPT + ADA (whta do I wrong?)
  2004-12-03 13:56 Port LPT + ADA S�awo - MIR
                   ` (2 preceding siblings ...)
       [not found] ` <u111r0db4fsoj9u3hlkachspjt0r2vvup7@4ax.com>
@ 2004-12-04 18:05 ` S�awo - MIR
  2004-12-04 20:20   ` Dmitry A. Kazakov
  2004-12-05  6:45   ` Brian May
  3 siblings, 2 replies; 20+ messages in thread
From: S�awo - MIR @ 2004-12-04 18:05 UTC (permalink / raw)


Hello!

Maybe someone tell me what do I wrong (??), or maybe everything is wrong ;-)
:/
These are the fragments of my code:

Variables:

hLPT : Win32.Winnt.HANDLE;
struktura : Win32.Winbase.LPOVERLAPPED;
read : aliased DWORD;

type LPT1_Bajt is record
        Busy : boolean;
        ACK : boolean;
        Paper : boolean;
        Sel : boolean;
        Error : boolean;
        Trzy_z : boolean;
end record;

for LPT1_Bajt use record
        Busy at 0 range 7..7;       --pin 11 (zanegowany)
        ACK at 0 range 6..6;        --pin 10
        Paper at 0 range 5..5;      --pin 12
        Sel at 0 range 4..4;        --pim 13
        Error at 0 range 3..3;      --pin 15
        Trzy_z at 0 range 0..2;     --trzy zera na poczatku
end record;


Reading from LPT Port:

st : aliased LPT1_Bajt;

struktura.OffsetHigh := 16#379#;

!!!! In this place (after compiling, building and runnig it) appears an
error: "CONSTRAINT_ERROR access check failed" !!!!

if Win32.Winbase.Readfile(hLPT, st'address, Dword(1), read'access,
struktura) =

Win32.False then
     Put_Line ("Nie udalo sie odpalic LPT");
     raise LPT_Error;
end if;


Opening LPT port:

hLPT := Win32.Winbase.CreateFile ( CP ("LPT1" & ASCII.Nul),
                                   Win32.Winnt.GENERIC_READ,
                                   0,
                                   null,
                                   Win32.Winbase.OPEN_EXISTING,
                                   Win32.Winbase.FILE_FLAG_OVERLAPPED,
                                   System.Null_Address);





^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Port LPT + ADA (whta do I wrong?)
  2004-12-04 18:05 ` Port LPT + ADA (whta do I wrong?) S�awo - MIR
@ 2004-12-04 20:20   ` Dmitry A. Kazakov
  2004-12-07 18:13     ` Slawo - MIR
  2004-12-05  6:45   ` Brian May
  1 sibling, 1 reply; 20+ messages in thread
From: Dmitry A. Kazakov @ 2004-12-04 20:20 UTC (permalink / raw)


On Sat, 4 Dec 2004 19:05:44 +0100, S�awo - MIR wrote:

> Maybe someone tell me what do I wrong (??), or maybe everything is wrong ;-)

Only Hungarian notation is wrong! (:-))

> These are the fragments of my code:
> 
> Variables:
> 
> hLPT : Win32.Winnt.HANDLE;
> struktura : Win32.Winbase.LPOVERLAPPED;
                                  ^^^^^^^^^^^^^^
                                  This is a pointer!
I presume (depending on the Win32 bindings, you are using) it should be:

struktura : aliased Win32.Winbase.OVERLAPPED;

> read : aliased DWORD;
> 
> type LPT1_Bajt is record
>         Busy : boolean;
>         ACK : boolean;
>         Paper : boolean;
>         Sel : boolean;
>         Error : boolean;
>         Trzy_z : boolean;
> end record;
> 
> for LPT1_Bajt use record
>         Busy at 0 range 7..7;       --pin 11 (zanegowany)
>         ACK at 0 range 6..6;        --pin 10
>         Paper at 0 range 5..5;      --pin 12
>         Sel at 0 range 4..4;        --pim 13
>         Error at 0 range 3..3;      --pin 15
>         Trzy_z at 0 range 0..2;     --trzy zera na poczatku
> end record;
> 
> Reading from LPT Port:
> 
> st : aliased LPT1_Bajt;
> 
> struktura.OffsetHigh := 16#379#;
>
> !!!! In this place (after compiling, building and runnig it) appears an
> error: "CONSTRAINT_ERROR access check failed" !!!!

Yes, because structura = null
 
> if Win32.Winbase.Readfile(hLPT, st'address, Dword(1), read'access,
> struktura) =

That should be structura'Access, accordingly.

> Win32.False then
>      Put_Line ("Nie udalo sie odpalic LPT");
>      raise LPT_Error;
> end if;
> 
> Opening LPT port:
> 
> hLPT := Win32.Winbase.CreateFile ( CP ("LPT1" & ASCII.Nul),
>                                    Win32.Winnt.GENERIC_READ,
>                                    0,
>                                    null,
>                                    Win32.Winbase.OPEN_EXISTING,
>                                    Win32.Winbase.FILE_FLAG_OVERLAPPED,
>                                    System.Null_Address);


-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Port LPT + ADA (whta do I wrong?)
  2004-12-04 18:05 ` Port LPT + ADA (whta do I wrong?) S�awo - MIR
  2004-12-04 20:20   ` Dmitry A. Kazakov
@ 2004-12-05  6:45   ` Brian May
  1 sibling, 0 replies; 20+ messages in thread
From: Brian May @ 2004-12-05  6:45 UTC (permalink / raw)


>>>>> ""S�awo" == "S�awo  <- MIR" <mszajac@poczta.onet.pl>> writes:

    "S�awo> Hello!  Maybe someone tell me what do I wrong (??), or
    "S�awo> maybe everything is wrong ;-) :/ These are the fragments
    "S�awo> of my code:

Hello.

You seem to be getting high level access confused with low level
access. Possibly a source of this confusion is that the one word
"port" can mean different things (e.g. 1. connection from CPU to IO
card for low level access and 2. physical socket printer plugs
into). Both high level and low level access methods are very
incompatible with each other, and you definitely cannot mix the two as
you have. I am not going to describe the difference here; I suspect
that may not be beneficial at this stage. I recommend reading a good
book on operating systems and operating system drivers.

What operating system are you using? I assume this is not an embedded
system? I assume that it is a Windows based OS (since you are using
Windows definitions)?

I can only assume you require access to the LPT1 printer port.  What
you need to use the high level Windows API. Windows will talk to the
hardware for you.

I have never done this myself for LPT1 (my COM serial routines might
be similar, not sure), but I suspect it involves opening "LPT1" as a
file, and reading/writing to this handle you get. There will be other
functions to call to get status information. You do not need to map
directly to any address.

I highly recommend asking the question again, but rephrase it as "How
do I access the LPT port under <insert windows OS here>?". With this
question, I think others will be able to help you better. It is often
better to ask for what you need as opposed to proposing a solution
that may not meet you requirements.

Hope this helps.
-- 
Brian May <bam@snoopy.apana.org.au>



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Port LPT + ADA (whta do I wrong?)
  2004-12-04 20:20   ` Dmitry A. Kazakov
@ 2004-12-07 18:13     ` Slawo - MIR
  2004-12-07 20:55       ` Dmitry A. Kazakov
       [not found]       ` <rt8dr09tuvgbqaeq9vmujd1pqtb72hbamv@4ax.com>
  0 siblings, 2 replies; 20+ messages in thread
From: Slawo - MIR @ 2004-12-07 18:13 UTC (permalink / raw)


Hello !

O.K., but it still doesn't read :|
I did it all you wrote, and now the LPT_Error is raised :-(, and nothing is
read from LPT port :(

struktura: aliased Win32.Winbase.OVERLAPPED;

struktura.Offset := 16#01#;


if
Win32.Winbase.Readfile(hLPT,st'address,Dword(1),read'access,struktura'access
) = Win32.False then

        Put_Line ("Nie udalo sie odczytac z LPT");

        raise LPT_Error;    --this exception is raised

end if;



stan := st;



I try to assingn to variable (field of record) "struktura.Offset" and  to
"struktura.OffsetHigh" some different values - 16#379# (address of input
register), 16#01#... and it didn't work :(



Help, someone ! :(






^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Port LPT + ADA (whta do I wrong?)
  2004-12-07 18:13     ` Slawo - MIR
@ 2004-12-07 20:55       ` Dmitry A. Kazakov
  2004-12-08  4:28         ` Steve
       [not found]       ` <rt8dr09tuvgbqaeq9vmujd1pqtb72hbamv@4ax.com>
  1 sibling, 1 reply; 20+ messages in thread
From: Dmitry A. Kazakov @ 2004-12-07 20:55 UTC (permalink / raw)


On Tue, 7 Dec 2004 19:13:52 +0100, Slawo - MIR wrote:

> O.K., but it still doesn't read :|
> I did it all you wrote, and now the LPT_Error is raised :-(, and nothing is
> read from LPT port :(

This is another error. Unlike the previous one it has nothing to do with
Ada. Refer Windows API for the error reason.

> struktura: aliased Win32.Winbase.OVERLAPPED;
> 
> struktura.Offset := 16#01#;
> 
> if
> Win32.Winbase.Readfile(hLPT,st'address,Dword(1),read'access,struktura'access
> ) = Win32.False then
> 
>         Put_Line ("Nie udalo sie odczytac z LPT");
> 
>         raise LPT_Error;    --this exception is raised
> 
> end if;
> 
> stan := st;
> 
> I try to assingn to variable (field of record) "struktura.Offset" and  to
> "struktura.OffsetHigh" some different values - 16#379# (address of input
> register), 16#01#... and it didn't work :(
> 
> Help, someone ! :(

Calm down, you'll get it! (:-))

1. Do you really need overlapped I/O? This requires a lot of understanding
of how Windows works. Note that overlapped I/O is asynchronous to the
calling thread. It means that ReadFile will not wait for any data. It will
end immediately. After that you should periodically check the fields of the
OVERLAPPED structure for the results. Alternatively you can provide an
event object and enter wait for I/O completion (see WaitForSingleObject).
Note also that overlapped I/O fails at the file end (i.e. whne nobody
writes into the port). Maybe that's the case. Carefully read what MSDN
tells about ReadFile and OVERLAPPED.

2. When a Windows API fails, you should query for the failure reason using
GetLastError. Do it! Further, apply FormatMessage to the result of
GetLastError. Then you will exactly know what's going on.

Good luck!

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Port LPT + ADA (whta do I wrong?)
  2004-12-07 20:55       ` Dmitry A. Kazakov
@ 2004-12-08  4:28         ` Steve
  2004-12-08  8:27           ` Dmitry A. Kazakov
                             ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Steve @ 2004-12-08  4:28 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
news:1olbt9ia2fuuo$.qbyglb1cl3g8.dlg@40tude.net...
> On Tue, 7 Dec 2004 19:13:52 +0100, Slawo - MIR wrote:
[snip]
>
> Calm down, you'll get it! (:-))
>
> 1. Do you really need overlapped I/O? This requires a lot of understanding
> of how Windows works. Note that overlapped I/O is asynchronous to the
> calling thread. It means that ReadFile will not wait for any data. It will
> end immediately. After that you should periodically check the fields of 
> the
> OVERLAPPED structure for the results. Alternatively you can provide an
> event object and enter wait for I/O completion (see WaitForSingleObject).
> Note also that overlapped I/O fails at the file end (i.e. whne nobody
> writes into the port). Maybe that's the case. Carefully read what MSDN
> tells about ReadFile and OVERLAPPED.

Unless you're speaking about something specific to handling of the parallel 
port, I can say for certain that with serial I/O you must use OVERLAPPED I/O 
if you want to do full duplex communication.  This is not obvious from the 
documentation, but if you dig far enough (and try it) you'll find that this 
is the case.

Using overlapped I/O does NOT mean that ReadFile will not wait for any data 
before returning.  It does mean that if ReadFile returns FALSE, then you'll 
have to call "WinBase.GetLastError" to get the error code, and if the error 
code is "ERROR_IO_PENDING" than you'll have to read again.  In my serial 
driver I do exactly that.

Before using OVERLAPPED operations I found the little ideosyncracy that if I 
had one thread waiting on a read, another thread couldn't do a write until 
the read finished.  Using overlapped the write causes the read to wake up, 
the write does it's thing.  When my code detects that the read hasn't 
finished, it goes back and reads again.  A pain in the butt, but it works.

I remember finding an article on Microsofts site describing overlapped I/O 
and how it was a new and special feature that they had implemented.  That 
was news to me since I have written communications applications on other 
operating systems where you don't have to do anything special to have a read 
task and a write task work on the same communications port.

This isn't really an Ada question, you should try searching microsoft's site 
for specific information regarding the parallel port.

If you use google you can make your search something like:

  <your search string> site:microsoft.com

and it will restrict the search to the microsoft site.  Sometimes this saves 
sifting through a bunch of garbage (sometimes not).

I hope this helps,
Steve
(The Duck)

>
> 2. When a Windows API fails, you should query for the failure reason using
> GetLastError. Do it! Further, apply FormatMessage to the result of
> GetLastError. Then you will exactly know what's going on.
>
> Good luck!
>
> -- 
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de 





^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Port LPT + ADA (whta do I wrong?)
  2004-12-08  4:28         ` Steve
@ 2004-12-08  8:27           ` Dmitry A. Kazakov
  2004-12-12 22:25           ` Brian May
  2004-12-12 22:46           ` Brian May
  2 siblings, 0 replies; 20+ messages in thread
From: Dmitry A. Kazakov @ 2004-12-08  8:27 UTC (permalink / raw)


On Tue, 7 Dec 2004 20:28:11 -0800, Steve wrote:

> Before using OVERLAPPED operations I found the little ideosyncracy that if I 
> had one thread waiting on a read, another thread couldn't do a write until 
> the read finished.  Using overlapped the write causes the read to wake up, 
> the write does it's thing.  When my code detects that the read hasn't 
> finished, it goes back and reads again.  A pain in the butt, but it works.
>
> I remember finding an article on Microsofts site describing overlapped I/O 
> and how it was a new and special feature that they had implemented.  That 
> was news to me since I have written communications applications on other 
> operating systems where you don't have to do anything special to have a read 
> task and a write task work on the same communications port.

For those who knew RSX-11 and VMS overlapped I/O is quite natural. In fact
when I first saw how UNIX SysV dealt with full duplex stuff I was upset!

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Port LPT + ADA (whta do I wrong?)
       [not found]       ` <rt8dr09tuvgbqaeq9vmujd1pqtb72hbamv@4ax.com>
@ 2004-12-09  8:17         ` Jerry van Dijk
  0 siblings, 0 replies; 20+ messages in thread
From: Jerry van Dijk @ 2004-12-09  8:17 UTC (permalink / raw)



Dennis Lee Bieber <wlfraed@ix.netcom.com> writes:

> On Tue, 7 Dec 2004 19:13:52 +0100, "Slawo - MIR"
> <mszajac@poczta.onet.pl> declaimed the following in comp.lang.ada:
> 
> 	I don't know enough about the arguments you are using, but...
> 
> > I try to assingn to variable (field of record) "struktura.Offset" and  to
> > "struktura.OffsetHigh" some different values - 16#379# (address of input
> > register), 16#01#... and it didn't work :(
> >
> 	...If you mean for 16#379# to be the physical I/O address for a
> parallel port, I suspect it isn't going to work at all.

The problem is not only that the the addresses in question are I/O addresses
instead of memory addresses, but also that NT, W2K and XP do not allow a 
user-lever program to access them. 

The easiest solution to this program is to use one of the the generic I/O port
device drivers, for example see:

        http://www.beyondlogic.org/porttalk/porttalk.htm

succes,
Jerry.

-- 
--  Jerry van Dijk
--  Leiden, Holland
--
--  'Tradition is not the worship of ashes, but the preservation of fire.'
--                                               Gustav Mahler (1860-1911)



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Port LPT + ADA (whta do I wrong?)
  2004-12-08  4:28         ` Steve
  2004-12-08  8:27           ` Dmitry A. Kazakov
@ 2004-12-12 22:25           ` Brian May
  2004-12-14  2:41             ` Steve
  2004-12-12 22:46           ` Brian May
  2 siblings, 1 reply; 20+ messages in thread
From: Brian May @ 2004-12-12 22:25 UTC (permalink / raw)


>>>>> "Steve" == Steve  <nospam_steved94@comcast.net> writes:

    Steve> Unless you're speaking about something specific to handling
    Steve> of the parallel port, I can say for certain that with
    Steve> serial I/O you must use OVERLAPPED I/O if you want to do
    Steve> full duplex communication.  This is not obvious from the
    Steve> documentation, but if you dig far enough (and try it)
    Steve> you'll find that this is the case.

Ok, this might be my problem I have encountered with serial I/O, where
I read from a serial port in one thread and write to it in another
thread...

I found sample code that does this (Ada Terminal Emulator at
http://www.members.optusnet.com.au/rosshigson/terminal.htm), according
to the comment:

   -- 1. Windows NT is unable to read and write at the same
   --    time. Attempts to do so result in one or the other 
   --    being blocked. Therefore, by default we use a mutex to 
   --    serialize read and write calls. Windows 95/98 can read 
   --    and write at the same time, so we can use the option
   --    "/nomutex".

This seems kind of dodgy to me, and presumably means if something is
to be written it cannot be written until the read call returns.

    Steve> Before using OVERLAPPED operations I found the little
    Steve> ideosyncracy that if I had one thread waiting on a read,
    Steve> another thread couldn't do a write until the read finished.
    Steve> Using overlapped the write causes the read to wake up, the
    Steve> write does it's thing.  When my code detects that the read
    Steve> hasn't finished, it goes back and reads again.  A pain in
    Steve> the butt, but it works.

Does anyone have sample Ada code that uses OVERLAPPED operations?
-- 
Brian May <bam@snoopy.apana.org.au>



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Port LPT + ADA (whta do I wrong?)
  2004-12-08  4:28         ` Steve
  2004-12-08  8:27           ` Dmitry A. Kazakov
  2004-12-12 22:25           ` Brian May
@ 2004-12-12 22:46           ` Brian May
  2004-12-12 23:03             ` Adrien Plisson
  2 siblings, 1 reply; 20+ messages in thread
From: Brian May @ 2004-12-12 22:46 UTC (permalink / raw)


>>>>> "Steve" == Steve  <nospam_steved94@comcast.net> writes:

    Steve> Using overlapped I/O does NOT mean that ReadFile will not
    Steve> wait for any data before returning.  It does mean that if
    Steve> ReadFile returns FALSE, then you'll have to call
    Steve> "WinBase.GetLastError" to get the error code, and if the
    Steve> error code is "ERROR_IO_PENDING" than you'll have to read
    Steve> again.  In my serial driver I do exactly that.

Are you sure about this?

Looking at the documentation on Microsoft's website, I get the opinion:

overlapped IO == asynchronous IO

Some quotes at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/synchronization_and_overlapped_input_and_output.asp:

"[...] Functions called for overlapped operation can return
immediately, even though the operation has not been completed. [...]
For example, a single thread can perform simultaneous I/O operations
on different handles, or even simultaneous read and write operations
on the same handle."

"To synchronize its execution with the completion of the overlapped
operation, the calling thread uses the GetOverlappedResult function or
one of the wait functions to determine when the overlapped operation
has been completed. You can also use the HasOverlappedIoCompleted
macro to poll for completion."

It doesn't say anything about an ERROR_IO_PENDING or that you should
make the same IO call again.
-- 
Brian May <bam@snoopy.apana.org.au>



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Port LPT + ADA (whta do I wrong?)
  2004-12-12 22:46           ` Brian May
@ 2004-12-12 23:03             ` Adrien Plisson
  0 siblings, 0 replies; 20+ messages in thread
From: Adrien Plisson @ 2004-12-12 23:03 UTC (permalink / raw)


Brian May wrote:
> Some quotes at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/synchronization_and_overlapped_input_and_output.asp:
> 
> "[...] Functions called for overlapped operation can return
> immediately, even though the operation has not been completed. [...]
> For example, a single thread can perform simultaneous I/O operations
> on different handles, or even simultaneous read and write operations
> on the same handle."
> 
> "To synchronize its execution with the completion of the overlapped
> operation, the calling thread uses the GetOverlappedResult function or
> one of the wait functions to determine when the overlapped operation
> has been completed. You can also use the HasOverlappedIoCompleted
> macro to poll for completion."
> 
> It doesn't say anything about an ERROR_IO_PENDING or that you should
> make the same IO call again.

three pargraphs down:

"When a function is called to perform an overlapped operation, it is 
possible that the operation will be completed before the function 
returns. When this happens, the results are handled as if the operation 
had been performed synchronously. If the operation was not completed, 
however, the function's return value is FALSE, and the GetLastError 
function returns ERROR_IO_PENDING."

-- 
rien




^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Port LPT + ADA (whta do I wrong?)
  2004-12-12 22:25           ` Brian May
@ 2004-12-14  2:41             ` Steve
  0 siblings, 0 replies; 20+ messages in thread
From: Steve @ 2004-12-14  2:41 UTC (permalink / raw)


I'll send you my serial driver sources via email.

Steve
(The Duck)

"Brian May" <bam@snoopy.apana.org.au> wrote in message 
news:sa48y83qhm1.fsf@snoopy.apana.org.au...
>>>>>> "Steve" == Steve  <nospam_steved94@comcast.net> writes:
>
>    Steve> Unless you're speaking about something specific to handling
>    Steve> of the parallel port, I can say for certain that with
>    Steve> serial I/O you must use OVERLAPPED I/O if you want to do
>    Steve> full duplex communication.  This is not obvious from the
>    Steve> documentation, but if you dig far enough (and try it)
>    Steve> you'll find that this is the case.
>
> Ok, this might be my problem I have encountered with serial I/O, where
> I read from a serial port in one thread and write to it in another
> thread...
>
> I found sample code that does this (Ada Terminal Emulator at
> http://www.members.optusnet.com.au/rosshigson/terminal.htm), according
> to the comment:
>
>   -- 1. Windows NT is unable to read and write at the same
>   --    time. Attempts to do so result in one or the other
>   --    being blocked. Therefore, by default we use a mutex to
>   --    serialize read and write calls. Windows 95/98 can read
>   --    and write at the same time, so we can use the option
>   --    "/nomutex".
>
> This seems kind of dodgy to me, and presumably means if something is
> to be written it cannot be written until the read call returns.
>
>    Steve> Before using OVERLAPPED operations I found the little
>    Steve> ideosyncracy that if I had one thread waiting on a read,
>    Steve> another thread couldn't do a write until the read finished.
>    Steve> Using overlapped the write causes the read to wake up, the
>    Steve> write does it's thing.  When my code detects that the read
>    Steve> hasn't finished, it goes back and reads again.  A pain in
>    Steve> the butt, but it works.
>
> Does anyone have sample Ada code that uses OVERLAPPED operations?
> -- 
> Brian May <bam@snoopy.apana.org.au> 





^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2004-12-14  2:41 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-03 13:56 Port LPT + ADA S�awo - MIR
2004-12-03 14:40 ` Martin Krischik
2004-12-03 15:29   ` Slawo - MIR
2004-12-03 18:46     ` Martin Krischik
2004-12-03 18:43 ` tmoran
     [not found] ` <u111r0db4fsoj9u3hlkachspjt0r2vvup7@4ax.com>
2004-12-03 23:03   ` Adrien Plisson
2004-12-03 23:51     ` Slawo - MIR
2004-12-04  0:51     ` Jeffrey Carter
2004-12-04 18:05 ` Port LPT + ADA (whta do I wrong?) S�awo - MIR
2004-12-04 20:20   ` Dmitry A. Kazakov
2004-12-07 18:13     ` Slawo - MIR
2004-12-07 20:55       ` Dmitry A. Kazakov
2004-12-08  4:28         ` Steve
2004-12-08  8:27           ` Dmitry A. Kazakov
2004-12-12 22:25           ` Brian May
2004-12-14  2:41             ` Steve
2004-12-12 22:46           ` Brian May
2004-12-12 23:03             ` Adrien Plisson
     [not found]       ` <rt8dr09tuvgbqaeq9vmujd1pqtb72hbamv@4ax.com>
2004-12-09  8:17         ` Jerry van Dijk
2004-12-05  6:45   ` Brian May

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox