Guidance
指路人
g.yi.org
software / rapidq / Examples / Devices / Printer & Parallel Port / lptport.bas

Register 
新用户注册
Search 搜索
首页 
Home Home
Software
Upload

  
'===========================================================================
' Subject: ACCESSING LPT PORT                Date: 05-31-00 (10:25)
' Author:  Stephan Verrips                   Code: RAPIDQ
' Origin:  Stephan@verrips.com             Packet: RAPIDQ.ABC
'===========================================================================
'***********************************************
'* LPTport for Windows 95/98 and Linux         *
'*                                             *
'* Written by Stephan Verrips,                 *
'* The netherlands                             *
'*                                             *
'* This program is public domain !             *
'*                                             *
'* You can use this program for making         *
'* a interface card on the LPT port.           *
'* Pen 18 = massa                              *
'*                                             *
'* Example:                                    *
'*                                             *
'* Switch D0 - pen 2 on with this              *
'* program, then Pen 2 (D0) and pen 18 (Massa) *
'* are 5 volt DC                               *
'*                                             *
'*     Pen 2--------- +5v ---------pen 18      *
'***********************************************

     DECLARE SUB pen1
     DECLARE SUB pen2
     DECLARE SUB pen3
     DECLARE SUB pen4
     DECLARE SUB pen5
     DECLARE SUB pen6
     DECLARE SUB pen7
     DECLARE SUB pen8
     DECLARE SUB pen9
     DECLARE SUB pen10
     DECLARE SUB pen11
     DECLARE SUB pen12
     DECLARE SUB pen13
     DECLARE SUB pen14
     DECLARE SUB pen15
     DECLARE SUB pen16
     DECLARE SUB pen17
     DECLARE SUB ready

     DECLARE SUB status

     DECLARE SUB P378
     DECLARE SUB P3BC
     DECLARE SUB P278

     DIM Timer1 AS QTIMER
     DIM port AS INTEGER

'***************
'* Create Form *
'***************

     CREATE Form AS QFORM
      CAPTION = "LPTport for Windows"
      Width = 271
      Height = 387
      Center
      CREATE Label1 AS QLABEL
       CAPTION = "OUTPUTS"
       Left = 21
       Top = 10
       Width = 52
       Transparent = 1
      END CREATE
      CREATE Label2 AS QLABEL
       CAPTION = "LPT PORT"
       Left = 142
       Top = 10
       Width = 52
       Transparent = 1
      END CREATE
      CREATE Label3 AS QLABEL
       CAPTION = "INPUTS"
       Left = 142
       Top = 130
       Width = 42
       Transparent = 1
      END CREATE
      CREATE RadioButton2 AS QRADIOBUTTON
       CAPTION = "LP&T2 - H3BC"
       OnClick= P3BC
       Left = 142
       Top = 70
       TabOrder = 1
      END CREATE
      CREATE CheckBox1 AS QCHECKBOX
       CAPTION = "D&0 - pen 2"
       OnClick = pen2
       Left = 21
       Top = 49
       TabOrder = 3
      END CREATE
      CREATE CheckBox2 AS QCHECKBOX
       CAPTION = "D&1 - pen 3"
       OnClick = pen3
       Left = 21
       Top = 72
       TabOrder = 4
      END CREATE
      CREATE CheckBox3 AS QCHECKBOX
       CAPTION = "D&2 - pen 4"
       OnClick = pen4
       Left = 21
       Top = 95
       TabOrder = 5
      END CREATE
      CREATE CheckBox4 AS QCHECKBOX
       CAPTION = "D&3 - pen 5"
       OnClick = pen5
       Left = 21
       Top = 118
       TabOrder = 6
      END CREATE
      CREATE CheckBox5 AS QCHECKBOX
       CAPTION = "D&4 - pen 6"
       OnClick = pen6
       Left = 21
       Top = 143
       TabOrder = 7
      END CREATE
      CREATE CheckBox6 AS QCHECKBOX
       CAPTION = "D&5 - pen 7"
       OnClick = pen7
       Left = 21
       Top = 167
       TabOrder = 8
      END CREATE
      CREATE CheckBox7 AS QCHECKBOX
       CAPTION = "D&6 - pen 8"
       OnClick = pen8
       Left = 21
       Top = 191
       TabOrder = 9
      END CREATE
      CREATE CheckBox8 AS QCHECKBOX
       CAPTION = "D&7 - pen 9"
       OnClick = pen9
       Left = 21
       Top = 216
       TabOrder = 10
      END CREATE
      CREATE CheckBox9 AS QCHECKBOX
       CAPTION = "&Strobe - pen 1"
       OnClick = pen1
       Left = 21
       Top = 252
       TabOrder = 11
      END CREATE
      CREATE CheckBox10 AS QCHECKBOX
       CAPTION = "&Auto F - pen 14"
       OnClick = pen14
       Left = 21
       Top = 275
       TabOrder = 12
      END CREATE
      CREATE CheckBox11 AS QCHECKBOX
       CAPTION = "&Init - pen 16"
       OnClick = pen16
       Left = 21
       Top = 297
       TabOrder = 13
      END CREATE
      CREATE CheckBox12 AS QCHECKBOX
       CAPTION = "Sel I&n - pen 17"
       OnClick = pen17
       Left = 21
       Top = 322
       TabOrder = 14
      END CREATE
      CREATE CheckBox13 AS QCHECKBOX
       CAPTION = "C Error - pen 15"
       Left = 142
       Top = 168
       TabOrder = 15
      END CREATE
      CREATE CheckBox14 AS QCHECKBOX
       CAPTION = "C Sel - pen 13"
       Left = 142
       Top = 191
       TabOrder = 16
      END CREATE
      CREATE CheckBox15 AS QCHECKBOX
       CAPTION = "C Pe - pen 12"
       Left = 142
       Top = 214
       TabOrder = 17
      END CREATE
      CREATE CheckBox16 AS QCHECKBOX
       CAPTION = "C Ack - pen 10"
       Left = 142
       Top = 238
       TabOrder = 18
      END CREATE
      CREATE Button1 AS QBUTTON
       CAPTION = "&Ready"
       OnClick = ready
       Left = 142
       Top = 316
       TabOrder = 19
      END CREATE
      CREATE RadioButton3 AS QRADIOBUTTON
       CAPTION = "LPT3 - &H278"
       OnClick= P278
       Left = 142
       Top = 94
       TabOrder = 2
      END CREATE
      CREATE RadioButton1 AS QRADIOBUTTON
       CAPTION = "&LPT1 - H378"
       OnClick= P378
       Left = 142
       Top = 46
      END CREATE
      CREATE CheckBox17 AS QCHECKBOX
       CAPTION = "C Busy - pen 11"
       Left = 142
       Top = 264
       TabOrder = 20
      END CREATE
     END CREATE

'******************
'* Strobe - pen 1 *
'******************

     SUB pen1
      IF CheckBox9.Checked THEN
       OUT port+2, (INP(port+2) AND 254)
      ELSE
       OUT port+2, (INP(port+2) OR 1)
      END IF
     END SUB

'*******************
'* Auto F - pen 14 *
'*******************

     SUB pen14
      IF CheckBox10.Checked THEN
       OUT port+2, (INP(port+2) AND 253)
      ELSE
       OUT port+2, (INP(port+2) OR 2)
      END IF
     END SUB

'*****************
'* Init - pen 16 *
'*****************

     SUB pen16
      IF CheckBox11.Checked THEN
       OUT port+2, (INP(port+2) OR 4)
      ELSE
       OUT port+2, (INP(port+2) AND 251)
      END IF
     END SUB

'*******************
'* Sel In - pen 17 *
'*******************

     SUB pen17
      IF CheckBox12.Checked THEN
       OUT port+2, (INP(port+2) AND 247)
      ELSE
       OUT port+2, (INP(port+2) OR 8)
      END IF
     END SUB

'**************
'* D0 - pen 2 *
'**************

     SUB pen2
      IF CheckBox1.Checked THEN
       OUT port, (INP(port) OR 1)
      ELSE
       OUT port, (INP(port) AND 254)
      END IF
     END SUB

'**************
'* D1 - pen 3 *
'**************

     SUB pen3
      IF CheckBox2.Checked THEN
       OUT port, (INP(port) OR 2)
      ELSE
       OUT port, (INP(port) AND 253)
      END IF
     END SUB

'**************
'* D2 - pen 4 *
'***************

     SUB pen4
      IF CheckBox3.Checked THEN
       OUT port, (INP(port) OR 4)
      ELSE
       OUT port, (INP(port) AND 251)
      END IF
     END SUB

'**************
'* D3 - pen 5 *
'**************

     SUB pen5
      IF CheckBox4.Checked THEN
       OUT port, (INP(port) OR 8)
      ELSE
       OUT port, (INP(port) AND 247)
      END IF
     END SUB

'**************
'* D4 - pen 6 *
'**************

     SUB pen6
      IF CheckBox5.Checked THEN
       OUT port, (INP(port) OR 16)
      ELSE
       OUT port, (INP(port) AND 255-16)
      END IF
     END SUB

'**************
'* D5 - pen 7 *
'**************

     SUB pen7
      IF CheckBox6.Checked THEN
       OUT port, (INP(port) OR 32)
      ELSE
       OUT port, (INP(port) AND 255-32)
      END IF
     END SUB

'**************
'* D6 - pen 8 *
'**************

     SUB pen8
      IF CheckBox7.Checked THEN
       OUT port, (INP(port) OR 64)
      ELSE
       OUT port, (INP(port) AND 255-64)
      END IF
     END SUB

'**************
'* D7 - pen 9 *
'**************

     SUB pen9
      IF CheckBox8.Checked THEN
       OUT port, (INP(port) OR 128)
      ELSE
       OUT port, (INP(port) AND 255-128)
      END IF
     END SUB

'********
'* LPT1 *
'********

     SUB P378
      port=&H378
      status
     END SUB

'**********
'* LPT1/2 *
'**********

     SUB P3BC
      port=&H3BC
      status
     END SUB

'********
'* LPT3 *
'********

     SUB P278
      port=&H278
      status
     END SUB

'******************
'* End of program *
'******************

     SUB ready
      Form.CLOSE
     END SUB

'**************************
'* Refresh data on screen *
'**************************

     SUB status

'***********
'* Outputs *
'***********

      CheckBox1.Checked=((INP(port) AND 1)/1)
      CheckBox2.Checked=((INP(port) AND 2)/2)
      CheckBox3.Checked=((INP(port) AND 4)/4)
      CheckBox4.Checked=((INP(port) AND 8)/8)
      CheckBox5.Checked=((INP(port) AND 16)/16)
      CheckBox6.Checked=((INP(port) AND 32)/32)
      CheckBox7.Checked=((INP(port) AND 64)/64)
      CheckBox8.Checked=((INP(port) AND 128)/128)

      CheckBox13.Checked=((INP(port+1) AND 8)/8)
      CheckBox14.Checked=((INP(port+1) AND 16)/16)
      CheckBox15.Checked=((INP(port+1) AND 32)/32)
      CheckBox16.Checked=((INP(port+1) AND 64)/64)
      CheckBox17.Checked=(1-((INP(port+1) AND 128)/128))

'*********
'*Inputs *
'*********

      CheckBox9.Checked=(1-(INP(port+2) AND 1)/1)
      CheckBox10.Checked=(1-(INP(port+2) AND 2)/2)
      CheckBox11.Checked=((INP(port+2) AND 4)/4)
      CheckBox12.Checked=(1-(INP(port+2) AND 8)/8)
     END SUB

'***************************************
'* Timer for refesh the data on screen *
'***************************************

     SUB TimerOver
      Timer1.Interval = 400

  '**************************
  '* refresh data on screen *
  '**************************

      status
     END SUB

'*************************
'* Default on LPT1 &H378 *
'*************************

     port=&H378
     RadioButton1.Checked=1

'************************************
'* Timer for refresh data on screen *
'************************************

     Timer1.Interval = 400
     Timer1.Enabled = 1
     Timer1.OnTimer = TimerOver

'*****************
'* Start program *
'*****************

     Form.SHOWMODAL
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Thu 2021-10-21  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2002-07-26 17:35:12