First, operating in Visual Basic I / O ports
We will be able to come in Visual Basic through dynamic link library indirect operation I / O port has. In Visual Basic dynamic link library must be stated in advance, its default in the public domain process or function. Its format: "Declare Sub process of Lib 'of the' [Alias' alias'] [(parameter table)]" or "Declare Function process of Lib 'of the' [Alias' alias'] [(parameter table) ] As types. " For example:
Public Declare Function Outport Lib "vcDll.dll" (ByVal portid As Integer, ByVal value As Integer) As Integer / / IO output function
Public Declare Function Inport Lib "vcDll.dll" (ByVal portid As Integer) As Integer / / IO input function
This definition of the procedure can be directly used in the above definition of the function or process to operate the I / O port of.
Second, in operation in Visual Basic
Above on the I / O operation is a port from the I / O ports in a read signal after more bytes, and in the field of industrial control, each signal is often the acquisition or operation and therefore we need in Reading will be a signal to read the signal to leave, and would not require the output signal when the output of other shielding swap.
1. To read from the I / O port signal (digital signal need to read D0)
IOvalue = Inport (BASE) / / read the first BASE address I / O port signal
IOvaluer = IOvalue AND & 1H / / (seven other masked, leaving only a bit D0)
2. Shielding other digital signal and the corresponding output signal (D0 operating position 1)
IOvalue = Inport (BASE) / / read the first BASE address I / O port signal
IOvalue IOvalue OR = & 01H / / (B00000001, seven other masked, D0 position 1)
CALL Outport (BASE, IOvalue) / / output signals corresponding
In the above-operation, we use the logical operators AND and OR, logical analysis below.
AND 1 0
1 1 0
0 0 0
OR 1 0
1 1 1
0 1 0
AND operator can be used to designate the location of 0, for example: hex binary & H84: 10000100, which is the third one, to the third position 0, and the other in the same, you can use: HFB H84 AND & & = & H80, H80 & binary value B10000000.
OR operator can use to a designated location, such as: hexadecimal & H84 for the second 0, in order to position for a second, and the other of the same, can be used: & H84 OR = & H02 & H86, H86 & binary value B10000110.
Third, the use of computers LPT LPT I / O ports
LPT has three ports: data ports, port state control and ports, commonly used for LPT1 LPT, and its three ports addresses are as follows: H 378, 379H and 37 AH. Of which 378 H 37 AH-readable and writable, read-only ports for H 379.
And the other I / O cards, running DEBUG environment, to the mouth of the print test is as follows.
378H for data output. Type instructions - O 378 00 (01,02,04,08,10,20,40,80, FF), were detected with a multimeter 2 ~ 9 feet voltage (25 feet to Multimeter ""), can be measured and the corresponding bit line with the input data ( "1" corresponds 5 V, "0" corresponds 0 V). To illustrate the addresses of eight can be used as eight output lines.
379H for input. In order to provide input to the pin level, we first introduce an external 5 V power supply. LPT power to the ground 25 feet, and then access in 10,11,12,13,15 feet 5 V, 0V, while DEBUG circumstances - I 379 instructions, read this port data. Read the data should be consistent with the input signal.
I can only 37AH for output. 378 H detection methods and the same.
Test results:
378 output to calm command signal line, D0-D8-can be done at the output port;
37A output to calm command signal the contrary, D0 to D3-can be done at the output port;
379 Members vacant state: 11 feet for the "0", 10,12,13,15 to "1", the use D3 to do D6-port input.
In sum, normally used LPT I / O ports in a total of 12 export and import of four.
4, under Windows 2000/XP/NT I / O port operation
Windows 2000/XP/NT shielding on the hardware implementation of the I / O ports were strictly controlled, many in the Windows 9x under the normal operation of the user applications in Windows 2000/XP/NT direct access to hardware in the system would be abnormal, it is not under the direct access to Windows 2000/XP/NT I / O ports.
There are usually two ways to solve Windows 2000/XP/NT under the I / O port operator, to prepare a first-class operation in RING0 (Device Driver Driver level) virtual device driver (Virtual X Device, VSD ), it can have unrestricted access to hardware devices, capture I / O port operations and memory access, and so on, can be intercepted and even hardware interrupt, and this can be achieved in the USER mode under Windows 2000/XP/NT I / O ports visit operation. Another method is to modify the I / O allows bitmap settings, allowing access to a specific task for a specific I / O ports. This allows the procedure in the way USER RING3 level (application-level) in accordance with the I / O bitmap set up to allow unrestricted access to I / O ports.
This paper introduces in the next two Windows 2000/XP/NT under I / O port operations, and PortTalk WinIO.
WinIO libraries through the use of a kernel-mode device drivers, and several other underlying programming skills, bypassing the Windows system protection mechanisms, which allow the application under Windows 2000/XP/NT directly to the I / O port and physical memory to operate. It must be noted that in the Windows 2000/XP/NT, WinIO libraries only have administrator privileges allow the application call. WinIO library containing the corresponding driver source code and Visual BASIC routines, download Address: www.internals.com / utilities / winio.zip.
PortTalk the use of the above-mentioned second method, it allows you enough existing procedures in the windows 2000/XP/NT running, but it should be noted that, because of the need in RING0 and RING3 switch back down, will reduce the use of PortTalk procedures for operating efficiency. PortTalk device driver provides full source code, download Address: www.beyondlogic.org / porttalk / porttalk.zip. |