'Visual Basic 3.0 code to interface to ADC on printer port. 'Copyright 2002 by D.M. Gualtieri, Commercial rights reserved 'Individuals may use freely, but no warranty is given or implied. 'See disclaimer. 'Note - inpout.dll will only work with Windows 3.0, 3.1, 95, and 98. 'The newer versions of Windows, such as Windows NT, 2000, etc. 'make it very hard to communicate with the outside world. 'My advice - use Linux and the gcc compiler, instead! Declare Function Inp Lib "inpout.dll" (ByVal Port%) As Integer Declare Sub Out Lib "inpout.dll" (ByVal Port%, ByVal Value%) Global Port_Address As Integer Global Port_Choice As Integer Global Port_Out As Integer Global Port_In As Integer Sub AD_Read (Channel As Integer) 'Reads AD volatge from channel 0 or 1 'D0 on Port_Out is CLK, D1 is NOT(CS), and D2 is Data In 'D3 on Port_In is serial data Dim K As Integer Dim Scratch As Integer Port_Out = Port_Out And &HFE 'set clock bit initially to low Port_Out = Port_Out Or &H4 'set data bit to high Port_Out = Port_Out And &HFD 'set Not(CS) bit to low Call Out(Port_Address, Port_Out) 'Send the new byte to the port 'Send AD clock pulse (1 msec typical) AD_Clock_Pulse Port_Out = Port_Out Or &H4 'set data bit to high 'for single-ended dual channel Call Out(Port_Address, Port_Out) 'Send the new byte to the port 'Send AD clock pulse (1 msec typical) AD_Clock_Pulse 'set data bit for channel If Channel = 0 Then Port_Out = Port_Out And &HFB 'set data bit to low Else Port_Out = Port_Out Or &H4 'set data bit to high End If Call Out(Port_Address, Port_Out) 'Send the new byte to the port 'Send AD clock pulse (1 msec typical) AD_Clock_Pulse Port_Out = Port_Out Or &H4 'set data bit to high as final setup bit Call Out(Port_Address, Port_Out) 'Send the new byte to the port 'Send AD clock pulse (1 msec typical) AD_Clock_Pulse AD_Data(Channel) = 0 'set data register initially to zero For K = 0 To 12 Scratch = Inp(Port_Address + 1) Scratch = Scratch And &H8 'Isolate input data bit (S3) AD_Data(Channel) = AD_Data(Channel) * 2 'shift left If Scratch <> 0 Then AD_Data(Channel) = AD_Data(Channel) + 1 AD_Clock_Pulse 'Send AD clock pulse (1 msec typical) Next K Port_Out = Port_Out Or &H2 'set Not(CS) bit to high Call Out(Port_Address, Port_Out) 'Send the new byte to the port 'debug statement - MsgBox Str$(AD_Data(Channel)) End Sub Sub AD_Clock_Pulse () 'Send AD clock pulse (1 msec typical) Dim Pulse_Delay As Integer Dim Delay_Loop_Counter As Integer Pulse_Delay = 1000 'Number of loops for 1 msec delay, change as needed For Delay_Loop_Counter = 0 To Pulse_Delay Next Delay_Loop_Counter Port_Out = Port_Out Or &H1 'set clock bit to high Call Out(Port_Address, Port_Out) 'Send the new byte to the port For Delay_Loop_Counter = 0 To Pulse_Delay Next Delay_Loop_Counter Port_Out = Port_Out And &HFE 'reset clock bit to low Call Out(Port_Address, Port_Out) 'Send the new byte to the port End Sub Sub Find_Ports () 'Finds parallel ports by writing AA to the three default port locations '(0x3BC, 0x378 and 0x278) and looking for the same on read-back. '0x3BC exists only for monochrome display adapter (MDPA) systems. Const Data_Byte = &HAA Dim Read_Back As Integer Call Out(&H278, Data_Byte) Read_Back = Inp(&H278) If Read_Back = Data_Byte Then Port_Address = &H278 Port_Choice = 0 End If Call Out(&H378, Data_Byte) Read_Back = Inp(&H378) If Read_Back = Data_Byte Then Port_Address = &H378 Port_Choice = 1 End If Call Out(&H3BC, Data_Byte) Read_Back = Inp(&H3BC) If Read_Back = Data_Byte Then Port_Address = &H3BC Port_Choice = 2 End If End Sub