Delphi: 接近ing Port 金物類/武器類- Dt4j
HOME
- - - - - - -
TUTORIALS INDEX
- - - - - - - - - - - -
Other 構成要素 for programmers
Delphi: 接近ing Port 金物類/武器類 and how to use InpOut32.dll
This tutorial is ーするつもりであるd to help you understand some ソフトウェア which 簡単にするs 大(公)使館員ing electronics, even homemade electronics, to your PC 経由で the 平行の port. (Or, with more work, the serial port.) You may also want to read my answers to questions about the 金物類/武器類 問題/発行するs.
In particular, it helps you with using InpOut32.dll, an 外部の 資源 which some 肉親,親類d people have made 自由に 利用できる, to save you reinventing 確かな wheels. You don't need 事前の experience with DLLs.
If you just want a program to turn individual pins of your 平行の port on or off, and don't want to fool around with 令状ing your own, there's my freeware "SheepdogCurtainCloser". No sourcecode 利用できる, sorry. 作品 with XP.
There's also the .exe within the .zip 古記録 含む/封じ込めるing the source code for DD79, an 使用/適用 which is 始める,決める up more or いっそう少なく as the 使用/適用 述べるd in this tutorial. That too lets you turn bits on and off, and the sourcecode is 供給するd.
Does InpOut32 still work? WEll it did in December 2009, anyway, on an XP machine. Also, in March 09 I had a helpful email from another programmer 説 it worked 罰金 for him with Delphi 7 on a Windows XP (Professional, SP3) machine. But shhh... don't tell Mr.G about some goalposts he could move. Between Codegear's (to whom Borland sold Delphi) 欠如(する) of 利益/興味 in "the little guy", and other things, I'm beginning to like Linux/ Netbeans more and more.
And does it work 井戸/弁護士席? The same person told me he'd used it with an Excel VBA app every day since Sept 08 without hassle.
Thank you Logix4U, Programmer's Heaven and Everyday with Practical Electronics magazine! 支援する in October 2003 they made life easier for anyone wanting to 接近 their computer's 平行の or serial ports. At last! A 選び出す/独身 method that 作品 for 勝利,勝つ 9x, NT, 2000 and XP. Without much messy 総計費.
Three 簡潔な/要約する asides:
Aside 1: Most of the 構成要素 on the web speaks of InpOut32 as 存在 a way to 接近 the 平行の port... and it is. Working with the 平行の port is 比較して simple. InpOut32 should also 許す you to 接近 your serial port. The 推論する/理由 I 港/避難所't tried to do it is that the serial port is a bigger 苦痛 to work with. InpOut32 lets you send and read bytes to/ from the 演説(する)/住所s 割り当てるd to the 平行の port. Working with serial ports is done much the same way, so, if you care to master the 半導体素子s you will be talking to, I see no 推論する/理由 why you shouldn't 接近 them with InpOut32, too.
Aside 2a: This isn't really the place for it, but I want to get SOME 言及/関連 の上に my 場所/位置. While 研究ing just now, I (機の)カム across Erlich 産業の 開発's 広大な/多数の/重要な 場所/位置 which may be of 利益/興味 to the sort of person I 嫌疑者,容疑者/疑う will have come the page you are reading. It sells 教育の electronics 道具s which connect your computer to the outside world though a USB port. There seems to be a tie in with Jan Axelson, who will be known to some readers as a long-standing friend of the "do-it-yourself" electronics hobbyist. Do 公式文書,認める the little bit of bad news (?) at the 底(に届く) of EID's page about USB 製品 and vendor IDs.... the "big players" (could Microsoft have had a 手渡す?) are squeezing the little hobbyists out, again, in the 指名する of "緩和する of use"... though I have to 収容する/認める, I see some value in USB 製品/vendor ID systems... I just wonder why it is expensive to 得る one. Speaking of "big players", EID is no garage-based, one man 禁止(する)d. 調査する their 場所/位置, and be 感謝する that they have someone who has 始める,決める up the 明らかにする PCBs, 道具s, 構成要素s 分割, which must be a pretty minor distraction in their 全体にわたる 計画/陰謀. Disclaimer: I must 自白する: I have not yet tried anything from them. Too busy 令状ing tutorials for you!!
Aside 2b: If interfacing 経由で USB sounds good to you, there's also the Dallas MicroLan (aka 1-Wire 解答, about which I have 地位,任命するd many tutorials).
Before getting to The Good Stuff, a little background on two 問題/発行するs....
問題/発行する 1: 支援する in the late 1980s, if you 手配中の,お尋ね者 to wink some LEDs on and off, you wired them to a printer cable, and then wrote a program which changed the value 蓄える/店d in a 明確な/細部 memory 場所. In Basic, the 命令(する) was POKE, in Pascal, we used PORT. This worked even in 早期に 見解/翻訳/版s of Windows, and Delphi 1 still had a PORT 命令(する).
Then Windows got "better". Direct 接近 to 明確な/細部 memory 場所s became a bad idea, and from Delphi 2 the PORT 命令(する) was 行方不明の.
問題/発行する 2: One of the strengths, I think, of Delphi is that, in general, you don't use DLLs. As much as I like that, in the 事例/患者 of solving the read/令状 平行の port problem I was 用意が出来ている to look at using one... and I was delighted to find that things aren't very 複雑にするd. From that you should infer a 警告: I'm not experienced in 事柄s DLL... but the に引き続いて 作品 for me. Please educate me if anything in it is wrong or unwise!
As I understand DLLs, at least as far as is necessary to use the port reading/令状ing DLL from Logix4U, a DLL is a discrete とじ込み/提出する in your system which has a header which 許すs other programs to interact with it. The 本体,大部分/ばら積みの of this tutorial is about how to make a program written by you interact with someone else's DLL.
If you want a more gentle introduction to DLLs, you might want to read my introduction to DLLs, at least the first part, before 訴訟/進行. You don't need to know anything about 令状ing DLLs to use what is in this tutorial about 接近ing things 経由で your 平行の and serial
Moving on.... we're nearly to the part of the tutorial in which we'll 令状 a program to 接近 the 平行の port...
Lastly before getting to The Good Stuff there is one 詳細(に述べる) and two worries to 演説(する)/住所....
I like my system to stay nice and simple. Windows 衝突,墜落s often enough without any help from me. I've always disliked DLLs because I don't know what they're up to, because of the clutter they 追加する, and because of the 可能性のある for 混乱. Consider the に引き続いて: Suppose two 一括s EACH come with a DLL called FredsStuff..... but the stuff in the two DLLs is not the same. The answer, I'm told, is that if the FredsStuff.DLL that (機の)カム with 一括 A is 任命する/導入するd in the folder 持つ/拘留するing 一括 A's .exe とじ込み/提出する, and B's is in B's folder, then all is 井戸/弁護士席.
Now suppose you have three 一括s, living nicely each in their own folders, which all use a DLL with a 指名する that no one else is using. The three DLLs are 同一の in content 同様に as in 指名する. Do you need to have three copies of the DLL? No. You can put one copy in the Windows system folder (usually C:\Windows\System\), and all should be 井戸/弁護士席.
A 警告: Please be very careful when working with this ソフトウェア. Other than seeing, in general, how to use DLLs, there's no point unless you are also doing some 金物類/武器類 things.... and mistakes there CAN DAMAGE YOUR COMPUTER. See my page about using the 平行の port for more (警察などへの)密告,告訴(状) on the 危険s, and more advice on the things that "should" be okay.... but I ACCEPT NO LIABILITY FOR ANYTHING THAT ARISES from your use of this 構成要素. Now we can put the lawyer 支援する in his box, I hope.
Another chore before we start to program: You need to find the 演説(する)/住所 of your 平行の port. If this paragraph daunts you, just try $378 for the port 演説(する)/住所. In 勝利,勝つ 9x, 権利 click on "My Computer", click on "所有物/資産/財産s", and click on the "装置 Manage" tab. There should be a "ports" 入ること/参加(者) in the 名簿(に載せる)/表(にあげる). 拡大する that if it is 崩壊(する)d, 二塁打 click the "Printer Port" line. Select the 資源s tab. Look at the first "Input/生産(高) 範囲" line. Make a 公式文書,認める of the first number there. It will probably be 0378. That's your printer port's first 演説(する)/住所. It is 表明するd in hex. Just put a dollar 調印する in 前線 of it when you type it into your program, and all will be 井戸/弁護士席.
At last... The Good Stuff...
I've 地位,任命するd a zip 古記録 of the source code and the .exe of something like what is 述べるd below. It was written on an XP machine, using Delphi 4. Working 罰金 9 December 2009.
Start a new 事業/計画(する) (使用/適用). (I was using Delphi 2 under Win98SE when I developed this tutorial)
Put a label on the form, big enough for a 3 digit number.
追加する a scroll 妨げる/法廷,弁護士業. (ScrollBar 反対する is on the "基準" tab.)
Most of the default 所有物/資産/財産s are 罰金, but change the に引き続いて:
Max:255
Min:0
二塁打 click on the scroll 妨げる/法廷,弁護士業. This will create an empty "Change" event handler. Put the に引き続いて in between the "begin" and the "end":
Label1.caption:=inttostr(ScrollBar1.position);
Run the program. Moving the scroll 妨げる/法廷,弁護士業 thumb tab should 原因(となる) the number showing in the label to change.
(If you know about hex numbers, and how easily they 変える to binary in your 長,率いる, you might want to use...
Label1.caption:=inttohex(ScrollBar1.position,2);
... so that when we get the program 令状ing to the 平行の port you can more easily see if what you are getting is RIGHT! But if you don't see what I'm talking about, you can just ignore this.)
Put a copy of inpout32.dll from www.logix4u.逮捕する into the same folder as your 事業/計画(する). You can download a zip とじ込み/提出する with that and a whole bunch of 関係のある stuff from Logix4U by clicking here. (With WiunZip, you can pull just the DLL out of the 古記録 after you've downloaded it.
And, finally, make sure that your printer is NOT plugged into your printer port (!), and then...
改訂する all of ScrollBar1Change so that it becomes what you see below. If your 平行の port wasn't at $378 change the 言及/関連 to $378!
手続き TForm1.ScrollBar1Change(Sender: TObject);
var bWriteMe, bErr:byte;
機能(する)/行事 Out32(wAddr:word;bOut:byte):byte; stdcall; 外部の 'inpout32.dll';
begin
bWriteMe:=ScrollBar1.position;
Label1.caption:=inttostr(bWriteMe);
bErr:=(Out32($378,bWriteMe));
end;
... and when you run it, and move the scollbar thumb tab. The 明言する/公表する of the 平行の port's data pins should change. You can see them change with a voltmeter, or a simple 回路・連盟 with a few LEDs and resistors
If the code won't 収集する as shown (it will in Delphi 2), try moving the
機能(する)/行事 Out32(wAddr:word;bOut:byte):byte; stdcall; 外部の 'inpout32.dll';
line to just after the uses line 近づく the start of the program. It is a pity to have it become a 全世界の 資源 when it is only 関連した to ScrollBar1Change, but it may be necessary to have it 全世界の in 地位,任命する-見解/翻訳/版-2 見解/翻訳/版s of Delphi. (Feedback on this from readers would be 高く評価する/(相場などが)上がるd. Send me your 報告(する)/憶測, 含むing which 見解/翻訳/版 of Delphi you are using, please.)
A little mystery: On one system I was using, I did get changing 明言する/公表するs on the data pins... but they were 正確に/まさに the opposite of what I 推定する/予想するd.
In the code above, the TForm1. may be different in what will be 権利 for you. It 簡単に derived from the 指名する of the form, as usual. The Out32 has to be Out32 to 達成する the 関係 to the DLL. bWriteME and bErr could be changed to 指名するs of your preference.
If you get "Debugger kernel error. Error code:1", then look to
see if the .dll is in the 権利 place, or to see if you are trying
to call a 機能(する)/行事 not 現在の in the dll. Also, for either "problem", a simple typo may be the 推論する/理由 for the error message. The computer won't find Out32 if you've told it to look for Out23!!.
WARNING: While this 作品, I may have used the wrong data types for one or more of bWriteMe, bErr, and wAddr. I will try to get this 不確定 (疑いを)晴らすd up.
Putting the $378 in as it appears above is 罰金 in a tiny デモ program. In a bigger program, where there might be several 言及/関連s to the printer port 演説(する)/住所, it would be best to put....
const PrinterPortAddr=$378;
... 近づく the start of your program, and just use PrinterPortAddr when you want to 言及する to the printer port 演説(する)/住所. Half of you, gentle readers, will not need to be told this. The other half of you won't see why it is a good idea. 信用 me? Do it this way, and one day you'll thank me!
Yes... bErr should be 実験(する)d to see that all was 井戸/弁護士席. I'm not sure what value you should look for, though. The documentation at www.logix4u.逮捕する is good. You can find it there if you're going to 実験(する) bErr.
So much for sending things to the 平行の port.
Now for reading things from it. (Reading is not in DD79, the 使用/適用 供給(する)d in the .zip 古記録 you can download.)
Fancy modern ports can support bi-directional use of the main data pins. I'm not going to get into that here. I am going to show you how to get input across the 4 bits that have always been for input.
Inputs: If you read 演説(する)/住所 PrinterPortAddr+1 (i.e. $379 on most machines), you can discover the 明言する/公表する of 5
pins. They 決定する the 明言する/公表する of bits 3-7 of the byte at PrinterPortAddr+1. The bits are mapped and 指名するd as follows:
Bit Pin 指名する
3 15 Error
4 13 Select In
5 12 Paper Empty
6 10 認める
7 11 Busy
(A 罠(にかける) for the unwary... 'Busy' is inverted 'just inside' the
computer. Thus if you 適用する a '1' to all of the pins, you'll see
01111xxx when you read 889! Isn't 計算するing fun?)
追加する second label and a button to your form, and make the button do the に引き続いて when clicked:
手続き TForm1.Button1Click(Sender: TObject);
機能(する)/行事 Inp32(wAddr:word):byte; stdcall; 外部の 'inpout32.dll';
begin
label2.caption:='When last read, the port was showing '+
inttostr((Inp32($379)and $F8));
end;
(The "and $F8" stuff just hides the three bits that are not inputs and could each be 0 or 1.)
Again: The $379 will work on most machines, but if your printer port isn't at $378, then you just use a number which is one more than where your printer port is. Also again: You can't change the 指名する "Inp32", and I may have 割り当てるd the wrong types to things.
Again, the...
機能(する)/行事 Inp32(wAddr:word):byte; stdcall; 外部の 'inpout32.dll';
...may have to go just after the uses 条項.
Now: That wasn't too bad, was it? The good news: It will work, you could just use it. There is another way of calling 機能(する)/行事s from DLLs, which is probably better in some ways, though it is いっそう少なく transparent, and 要求するs some memory 管理/経営.
I 港/避難所't been able to 令状 this 代案/選択肢 up yet.... but everything you need to know is at the 広大な/多数の/重要な guide to calling things in DLL with Delphi at...
an article at Programmer's Heaven.
At the beginning of this, I thanked Logix4U, Programmer's Heaven and Everyday with Practical Electronics magazine. It was EPE that told me about the DLL's availability (pg. 698, Oct 2003). Logix4 are big heroes, of course, for 解放(する)ing the DLL and its source code as freeware. I learned how to use the 機能(する)/行事s in a DLL from the article at Programmer's Heaven.
Here's another thing about 平行の port 接近 as a footnote... and thanks to Martijn Haak in the Netherlands for 与える/捧げるing this....
The BIOS data segment (40h) in your PC has a (米)棚上げする/(英)提議する with the 演説(する)/住所(es) of the 平行の port(s) in your system.
0040:0008 has the 演説(する)/住所 of LPT1, usually 378h
0040:000A has the 演説(する)/住所 of LPT2
0040:000A has the 演説(する)/住所 of LPT3, and
0040:000A has the 演説(する)/住所 of LPT4
場所/位置 地図/計画する
What's New
Search
This search 単に looks for the words you enter. It won't answer "Where can I download InpOut32?"
Click here if you're feeling 肉親,親類d! (促進するs my 場所/位置 経由で "Top100Borland")
広告 from page's editor: Yes.. I do enjoy 収集するing these things for you. I hope they are helpful. However... this doesn't 支払う/賃金 my 法案s!!! Sheepdog ソフトウェア (tm) is supposed to help do that, so if you 設立する this stuff useful, (and you run a Windows or MS-DOS PC) please visit my freeware and shareware page, download something, and 循環させる it for me? Links on your page to this page would also be 高く評価する/(相場などが)上がるd!
Click here to visit editor's freeware, shareware page.
Link to Tutorials main page
How to email or 令状 this page's editor, Tom Boyd
Page WILL BE 実験(する)d for 同意/服従 with INDUSTRY (not MS-only) 基準s, using the 解放する/自由な, 公然と accessible validator at validator.w3.org
If this page 原因(となる)s a script to run, why? Because of things like Google パネル盤s, and the code for the search button. Why do I について言及する scripts? Be sure you know all you need to about spyware.
....... P a g e . . . E n d s .....