Tài liệu Parallel Port Complete- P4 doc

20 253 0
Tài liệu Parallel Port Complete- P4 doc

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Chapter 3 cations a user decides to run. When a hardware interrupt occurs, a DOS program can jump quickly to an interrupt-service routine. Under Windows, the operating system has to decide which driver or virtual machine should service the interrupt and pass control to it, all the while handling the demands of whatever other appli- cations are running. All of that takes time, so under Windows, the interrupt latency, or the time before an interrupt is serviced, is much longer than under DOS, and isn't as predictable. Code Efficiency In addition to the programming language you use, how you write your programs can affect execution speed. A complete discussion on how to write efficient pro- gram code is well beyond the scope of this book, but a simple example illustrates the issues involved: You can generate a sine wave or other waveform by connecting a parallel port's outputs to the inputs of a digital-to-analog converter (DAC, and writing a repeat- ing series of bytes to the port. One way to generate the series of bytes would be to use a Sine function to calculate the value for each point in the waveform before writing it. Another, usually faster way is to calculate the values just once, store them, and write the stored values in sequence to the port. Data Compression For the fastest data transfers, compressing the data in software can reduce the number of bytes to write. Even though the number of port writes per second doesn't change, the effective transmission rate (the amount of uncompressed data sent per second) is greater. To use this method, you of course have to have soft- ware on the receiving end that knows how to decompress what it receives. Parallel ports in ECP mode can automatically decompress incoming data that uses ECP mode's protocol for data compression. Application-related Limits The simplest I/O operations just write data from a register to the port, or read the port into a register. But all programs have to do more than just this, and the extra ti me required for processing and moving data will also limit the rate at which you can access a port in an application. For example, a program might read an analog-to-digital converter's output in two nibbles, combine the nibbles into a byte, store the byte along with time and date information, display the information, and use the information to decide if the sys- tem needs to take an action such as sounding an alarm or adjusting a temperature control. All of this takes time! 50  Parallel Port Complete Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Programming Issues Ports that support ECP mode can use direct memory access (DMA), where data can transfer between memory and a port without intervention by the CPU. The DMA transfers use the system's expansion bus, but the CPU is free to perform other tasks during the DMA transfers, and this can speed up the overall perfor- mance of some applications. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Chapter 3 5 2  Parallel Port Complete Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. [...]... entered one Dim Index% Dim PortExists% Dim Count% Index = 0 'First, test address 3BCh Port( Index) Address = &H3BC PortExists TestPort(Index) 'If the port exists, increment the index If Not (Port( Index) Address) = 0 Then Index = Index + End If 'Test address 378h Port (Index) Address &x378 PortExists = TestPort(Index) 'If the port exists, increment the index If Not (Port( Index) Address) = 0 Then... End If 'Test address 278h Port (Index) Address &x278 PortExists = TestPort(Index) 'Disable option buttons of unused LPT ports For Count = Index + 1 To 2 optPortName(Count) Enabled = False Port( Count) Enabled = False Next Count If Not (Port (3) Address = 0) Then PortExists = TestPort(Index) Else optPortName(3) Enabled = False End If End Sub Private Sub cmdOK Click() frmSelectPort Hide End Sub Listing... and select ports (Sheet 2 of 4) Parallel Port Complete 63 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark Chapter 4 Private Sub cmdTestPort Click() Dim PortExists% Dim Index% 'Get the address of the selected port Index = -1 Do Index = Index + 1 Loop Until optPortName(Index) Value = True PortExists = TestPort(Index) Select Case PortExists Case True MsgBox "Passed : Port " +... these in a similar way to save port information Under Windows 95, two API functions enable programs to find and add system ports EnumPorts returns the LPT number and a brief description of each parallel port that Windows is aware of, and AddPort displays a dialog box that enables users to add a port to the list Finding, Selecting, and Testing Ports Because the parallel- port' s address can vary, programs... these in a similar way to save port information Under Windows 95, two API functions enable programs to find and add system ports EnumPorts returns the LPT number and a brief description of each parallel port that Windows is aware of, and AddPort displays a dialog box that enables users to add a port to the list Finding, Selecting, and Testing Ports Because the parallel- port' s address can vary, programs... "EPP" Next Index 'Enable the option buttons for existing ports For Index = 0 To 3 optPortName(Index) Enabled = Port( Index) Enabled Next Index UpdateLabels End Sub Private Sub optPortName Click(Index As Integer) 'Store the address and index of the selected port Dim Count% BaseAddress = Port( Index) Address IndexOfSelectedPort = Index EcpDataPortAddress = BaseAddress + &H400 EcrAddress = BaseAddress... cmdAddPort_Click() 'Display a text box to enable user to add a port , at a nonstandard address frmNewPortAddress Show End Sub Listing 4-2: Code for Figure 4-1's form that enables users to find, test, and select ports (Sheet 1 of 4) 62 Parallel Port Complete Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark Programming Tools Private Sub cmdFindPorts Click() 'Test the port. .. PortData : BitSet PortData, 4 and to read back this bit's value: Bit4 = BitRead(POrtData, 4) A Form Template Figure 4-1 shows a second tool for parallel- port programs : a set of Visual-Basic forms that you can use as a template, or starting point, for programs The startup form is blank except for a Setup menu with a Port submenu, which displays a form that enables users to select a port, find the ports... finding and testing ports, and getting and saving initialization data from an ini file (Sheet 1 of 14) Parallel Port Complete 67 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark Chapter 4 Type PortData Name As String Address As Integer PortType As String EcpModeDescription As String EcpModeValue As Integer Enabled As Integer End Type Global Port( 0 To 3) As PortData Global BaseAddress%... TestPort(Index) Select Case PortExists Case True MsgBox "Passed : Port " + Hex$(BaseAddress) "h is " + Port( Index) PortType + " ", 0 Case False MsgBox "Failed port test ", 0 End Select + End Sub Listing 4-2 : Code for Figure 4-11's form that enables users to find, test, and select ports (Sheet 3 of 4) 64 Parallel Port Complete Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark F Programming . time! 50  Parallel Port Complete Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Programming Issues Ports that support ECP. connecting a parallel port& apos;s outputs to the inputs of a digital-to-analog converter (DAC, and writing a repeat- ing series of bytes to the port. One

Ngày đăng: 24/12/2013, 19:15

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan