Accessing game or pareller port via Windows
I´m on my way doing little electronic machine which is controlable by program. Have to I use windows fuctions recv() via Socket structure to acces port data. Please reply
If you are working under a windows environment (95,98 not NT) then you can access the paralell port with _outp and _inp. All you need is the base address of the port.
As far as the game port, it''s probably easier to use DirectInput, as windows dowsn''t like to share the port very well.. Plus it really isn''t that hard to do.
-Zims
As far as the game port, it''s probably easier to use DirectInput, as windows dowsn''t like to share the port very well.. Plus it really isn''t that hard to do.
-Zims
Well then i´ll use paraller port.
What´s the address of paraller port.
Does someone have link in pocket for related thing i´d be very happy from any assistance I´m making motion detecter which is controlled by computer program interface would be pareller port.
Pareller port have some number of input pins. Does _inp() return value from pareller port.
0.Is pareller port input pin
|.Guess it
\.switch
0 0 0
| | |
\ \ \
| | |
So if 1,3 are on(true switched on) does _inp return 101 binary.
Please reply still.
Thank you Zimans
What´s the address of paraller port.
Does someone have link in pocket for related thing i´d be very happy from any assistance I´m making motion detecter which is controlled by computer program interface would be pareller port.
Pareller port have some number of input pins. Does _inp() return value from pareller port.
0.Is pareller port input pin
|.Guess it
\.switch
0 0 0
| | |
\ \ \
| | |
So if 1,3 are on(true switched on) does _inp return 101 binary.
Please reply still.
Thank you Zimans
The following info is taken from PC Intern:
First the parallel port connector:
Ok you may have noticed that pin 14 was not used, this will be explained in a moment.
To get the port address of LPT1 access memory location 0040:0008H
To get the port address of LPT2 access memory location 0040:000AH
To get the port address of LPT3 access memory location 0040:000CH
To get the port address of LPT4 access memory location 0040:000EH
say you want to send info to your device, send the 4bit code to the port number that you retreived from the above memory location.
i.e. LPT1 is 378h (do not quote me on this figure!!)
to read information back from your device use the next port up, so for LPT1 this would be 0x379, and shift the resulting value right by 3
PORT 0x379:
to send 1001 to the device use _outp( 0x378, 9 ); I may have the code wrong here.
use _inp( 0x379 ) >> 3; to get the information back from your device.
As I mentioned above this came from PC Intern, a good book that I suggest you try and get a copy of, ethier from your local library or buy it. It''s written by Michael Tischer, published by Abacus, ISDN : 1-55755-282-7 (this is from the 5th edition)
If you require any more indepth info from the book contact me. I tried somthing like this before with varied results, though at the time I was programming Pascal and in dos ( at least it''s better than COBOL!!!)
First the parallel port connector:
Output pins Input pins2 153 134 125 116 10
Ok you may have noticed that pin 14 was not used, this will be explained in a moment.
To get the port address of LPT1 access memory location 0040:0008H
To get the port address of LPT2 access memory location 0040:000AH
To get the port address of LPT3 access memory location 0040:000CH
To get the port address of LPT4 access memory location 0040:000EH
say you want to send info to your device, send the 4bit code to the port number that you retreived from the above memory location.
i.e. LPT1 is 378h (do not quote me on this figure!!)
to read information back from your device use the next port up, so for LPT1 this would be 0x379, and shift the resulting value right by 3
PORT 0x379:
bit What is is Pin7 Error (neg logic) 156 Slct 135 PE 124 ACK (negitive logic) 103 BUSY (negitive logic) 112 Not used1 Not used0 Not used
to send 1001 to the device use _outp( 0x378, 9 ); I may have the code wrong here.
use _inp( 0x379 ) >> 3; to get the information back from your device.
As I mentioned above this came from PC Intern, a good book that I suggest you try and get a copy of, ethier from your local library or buy it. It''s written by Michael Tischer, published by Abacus, ISDN : 1-55755-282-7 (this is from the 5th edition)
If you require any more indepth info from the book contact me. I tried somthing like this before with varied results, though at the time I was programming Pascal and in dos ( at least it''s better than COBOL!!!)
When I find my code in tons of trouble,Friends and colleages come to me,Speaking words of wisdom:"Write in C."My Web Site
What´s this kind of hex 0040:0008H in plain 0x000.
So +1 to address to get input I that´s why port address jumped by two.
In input result bits up from 7 are data.
But for input thera are pins 10,11,12,13,15 paraller port
so after binary shifting they are 10=7 pin.
Correct me if I´m wrong. I need info more about how does _inp read data.is data buffered or should program loop until it returns something (that´s bad for windows).
Thanks Steven you helped me awfully lot
So +1 to address to get input I that´s why port address jumped by two.
In input result bits up from 7 are data.
But for input thera are pins 10,11,12,13,15 paraller port
so after binary shifting they are 10=7 pin.
Correct me if I´m wrong. I need info more about how does _inp read data.is data buffered or should program loop until it returns something (that´s bad for windows).
Thanks Steven you helped me awfully lot
the hex 0040:0008H is a physical memory address under dos, I''m not sure how to get this location under windows, you will need a Windows Guru for this.
no, the input will return a value (say 0xf8, indicating all on) that you have to bit shift right by 3 (which is the 3 unsued bits of the port return value).
to read data from the port you will have to read it in a loop, as I meantioned in my last port I was doing this under dos and the program ran perfectly fine under windows. The best thing I can think of to implement this under windows would be to use a game loop (instead of using GetMessage() use the PeekMessage() function) and this would allow you to query your application every time your application waits for input, or you could hook into the WM_IDLE (check for this message, not sure if its correct) and do your polling there. But you have to check the information all the time, you should make an interface with your hardware equipment that includes a data lock, so if your equipment fires an alarm and your app is not checking the port at the time the alert went off your hardware device holds that state until the program reads the information and then you send the reset code down to the data latch on the hardware which then resets and a few nanoseconds later does it''s own sensor sweep to see if it needs to set another alert for your application to read.
No problem helping you, I only know this stuff because I tried 50 times to explain how this works to someone at college and in the end I wrote the test app (I added a few messages to let the lecturer know that I wrote the prog too 8) ).
If you need any further explination or the pages from the book scanned just let me know.
no, the input will return a value (say 0xf8, indicating all on) that you have to bit shift right by 3 (which is the 3 unsued bits of the port return value).
to read data from the port you will have to read it in a loop, as I meantioned in my last port I was doing this under dos and the program ran perfectly fine under windows. The best thing I can think of to implement this under windows would be to use a game loop (instead of using GetMessage() use the PeekMessage() function) and this would allow you to query your application every time your application waits for input, or you could hook into the WM_IDLE (check for this message, not sure if its correct) and do your polling there. But you have to check the information all the time, you should make an interface with your hardware equipment that includes a data lock, so if your equipment fires an alarm and your app is not checking the port at the time the alert went off your hardware device holds that state until the program reads the information and then you send the reset code down to the data latch on the hardware which then resets and a few nanoseconds later does it''s own sensor sweep to see if it needs to set another alert for your application to read.
No problem helping you, I only know this stuff because I tried 50 times to explain how this works to someone at college and in the end I wrote the test app (I added a few messages to let the lecturer know that I wrote the prog too 8) ).
If you need any further explination or the pages from the book scanned just let me know.
When I find my code in tons of trouble,Friends and colleages come to me,Speaking words of wisdom:"Write in C."My Web Site
I don''t know how to use ports under Windows. (_inp & _outp might not be so nice).
But there are a lot of printer (parallel port) functions in Windows.
For example:
EnumPorts()
AddPort()
ConfigurePort()
WritePrinter()
...and loads more...
Again, I don''t know if this will work for what you''re looking for. But if you got some good help files, you could look em up...
But there are a lot of printer (parallel port) functions in Windows.
For example:
Again, I don''t know if this will work for what you''re looking for. But if you got some good help files, you could look em up...
quote: Original post by Jaxks
What´s this kind of hex 0040:0008H in plain 0x000.
That''s a memory address in 16 bit. In 16 bit, we used to have something called a segmented memory model. The first part, 0040 is the segment while the second part 0008 is the offset. My guess is that this wouldn''t work under Win32 because it is 16 bit and win32 is 32 bit(sic). I''m interested to know how you convert a 16 bit memory address to 32 bit under Windows. I know how to do that under DJGPP.
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
quote: Original post by Jaxks
What´s this kind of hex 0040:0008H in plain 0x000.
That''s a memory address in 16 bit. In 16 bit, we used to have something called a segmented memory model. The first part, 0040 is the segment while the second part 0008 is the offset. My guess is that this wouldn''t work under Win32 because it is 16 bit and win32 is 32 bit(sic). I''m interested to know how you convert a 16 bit memory address to 32 bit under Windows. I know how to do that under DJGPP.
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
0040:0008H....
The first part (0040) is a memory segment. Segments are on every 16 byte boundry.
The second part (0008) is the address.
TotalAddress = SegmentPart * 16 + AddressPart;
This way 0 <= TotalAddress <= 1 MB
But beware! Protected mode 32bit uses it''s own memory model!
Address 0x00010000 in 32bit doesn''t have to be the same as Address 0x00010000 in 16bit mode!!!
Are they the same in Windows? I don''t know.
The first part (0040) is a memory segment. Segments are on every 16 byte boundry.
The second part (0008) is the address.
TotalAddress = SegmentPart * 16 + AddressPart;
This way 0 <= TotalAddress <= 1 MB
But beware! Protected mode 32bit uses it''s own memory model!
Address 0x00010000 in 32bit doesn''t have to be the same as Address 0x00010000 in 16bit mode!!!
Are they the same in Windows? I don''t know.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement