UPOTREBA BIBLIOTEKE IO.DLL

 

Biblioteku VBIO.DLL moguće je koristiti samo na Windows98 i WindowsMe platforma, dok biblioteka IO.DLL može da se koristi na svim Windows operativnim sistemima. Kao primer upotrebe ove biblioteke dajemo primere programa za rad sa ovom bibliotekom za upravljane svim portovima paralelenog porta.Biblioteka IO.DLL sadrži sledeće funkcije i podprograme:

 

Private Declare Sub PortOut Lib "IO.DLL" (ByVal Port As Integer, ByVal Data As Byte)

Private Declare Sub PortWordOut Lib "IO.DLL" (ByVal Port As Integer, ByVal Data As Integer)

Private Declare Sub PortDWordOut Lib "IO.DLL" (ByVal Port As Integer, ByVal Data As Long)

Private Declare Function PortIn Lib "IO.DLL" (ByVal Port As Integer) As Byte

Private Declare Function PortWordIn Lib "IO.DLL" (ByVal Port As Integer) As Integer

Private Declare Function PortDWordIn Lib "IO.DLL" (ByVal Port As Integer) As Long

Private Declare Sub SetPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte)

Private Declare Sub ClrPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte)

Private Declare Sub NotPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte)

Private Declare Function GetPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte) As Boolean

Private Declare Function RightPortShift Lib "IO.DLL" (ByVal Port As Integer, ByVal Val As Boolean) As Boolean

Private Declare Function LeftPortShift Lib "IO.DLL" (ByVal Port As Integer, ByVal Val As Boolean) As Boolean

Private Declare Function IsDriverInstalled Lib "IO.DLL" () As Boolean

Public Broj, LPTadresa As Integer

 

Objasnićemo ukratko njihove značenje:

 

PortOut:

Šalje na specifirani port dati bajt. Npr. komandom Call PortOut(&H378, 15) biće poslat broj 15 na Data port.

 

PortWordOut:

Šalje na specifirani port datu reč(16 bita).

 

PortDWordOut:

Šalje na specifirani port datu dvostruku reč(32 bita).

 

PortIn:

Čita sa navedene adrese 1 bajt.

 

PortWordIn:

Čita sa navedene adrese 1 reč(16 bita).

 

PortDWordIn:

Čita sa navedene adrese dvostruku reč(32 bita).

 

GetPortBit:

Ova funkcija ispituje status zadatog bita unutar bajta. Ako je postavljen na 1 vraća vrednost True inače vraća vrednost False.

 

SetPortBit:

Postavlja na datoj adresi, navedeni broj bita na 1. Npr. komandom Call SetPortBit(&H378, 4) biće postavljen četvrti bit  Data porta na 1.

 

ClrPortBit:

Postavlja na datoj adresi, navedeni broj bita na 0. Npr. komandom Call ClrPortBit(&H378, 3) biće postavljen treći bit  Data porta na 0.

 

NotPortBit:

Invertuje zadati bit na datoj adresi. Npr. komandom Call NotPortBit(&H378, 4) biće promenjeno stanje četvrtog bita  Data porta.

 

RightPortShift:

Vrši pomeranje u desno sadržaja na datoj adresi. Ako je u funkciji drugi parametar postavljen na True na najvećoj poziciji biće postavljeno 1 inače ako je

False neće biće postavljeno 0.

 

LeftPortShift:

Vrši pomeranje u levo sadržaja na datoj adresi. Ako je u funkciji drugi parametar postavljen na True na najnižoj poziciji biće postavljeno 1 inače ako je

False neće biće postavljeno 0.

 

IsDriverInstalled:

Ova funkcija vraća vrednost True ako IO.DLL postoji inače vraća False.

 

 PROGRAM ZA KONTROLU DATA PORTA

 

Izgled ekrana ovog programa prikazan je na slici 1 (PORT02X).

 

 

Slika 1

 

          Klikom mišom na neku od dioda D0-D7 menjamo njeno stanje, odnosno ako je crvena onda će ona biti uključena inače ako je bela biće isključena. Nakon postavljanja stanja dioda pritiskom na Upisi biće prenesno stanje dioda sa ekrana na naše testno kolo. Moguće je takođe promeniti adresu Data porta na LPT1, LPT2 ili LPT3 pri čemu se podrazumeva adresa 378H ako ništa ne menjamo.

          Sam program u Visual Basicu je:

 

 

 

 

'

'   Generalna delaracija za upotrebu funkcija IO.DLL

'

Private Declare Sub PortOut Lib "IO.DLL" (ByVal Port As Integer, ByVal Data As Byte)

Private Declare Sub PortWordOut Lib "IO.DLL" (ByVal Port As Integer, ByVal Data As Integer)

Private Declare Sub PortDWordOut Lib "IO.DLL" (ByVal Port As Integer, ByVal Data As Long)

Private Declare Function PortIn Lib "IO.DLL" (ByVal Port As Integer) As Byte

Private Declare Function PortWordIn Lib "IO.DLL" (ByVal Port As Integer) As Integer

Private Declare Function PortDWordIn Lib "IO.DLL" (ByVal Port As Integer) As Long

Private Declare Sub SetPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte)

Private Declare Sub ClrPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte)

Private Declare Sub NotPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte)

Private Declare Function GetPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte) As Boolean

Private Declare Function RightPortShift Lib "IO.DLL" (ByVal Port As Integer, ByVal Val As Boolean) As Boolean

Private Declare Function LeftPortShift Lib "IO.DLL" (ByVal Port As Integer, ByVal Val As Boolean) As Boolean

Private Declare Function IsDriverInstalled Lib "IO.DLL" () As Boolean

Public Broj, LPTadresa As Integer

_____________________________________________________________________________

Private Sub Command2_Click()  

    Call PortOut(LPTadresa, Broj)

End Sub

____________________________________________________________________________

Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

Dim i, j As Integer

        i = 9

        If (X >= 230) And (X < 840) And (Y > 1440) And (Y < 1775) Then i = 7

        If (X >= 840) And (X < 1440) And (Y > 1440) And (Y < 1775) Then i = 6

        If (X >= 1440) And (X < 2040) And (Y > 1440) And (Y < 1775) Then i = 5

        If (X >= 2040) And (X < 2640) And (Y > 1440) And (Y < 1775) Then i = 4

        If (X >= 2640) And (X < 3240) And (Y > 1440) And (Y < 1775) Then i = 3

        If (X >= 3240) And (X < 3840) And (Y > 1440) And (Y < 1775) Then i = 2

        If (X >= 3840) And (X < 4440) And (Y > 1440) And (Y < 1775) Then i = 1

        If (X >= 4440) And (X < 5040) And (Y > 1440) And (Y < 1775) Then i = 0

          

        If i <> 9 Then

          

         If (Shape1(i).BackColor = RGB(255, 255, 255)) Then

            Shape1(i).BackColor = RGB(255, 0, 0)

            Else: Shape1(i).BackColor = RGB(255, 255, 255)

            End If

       

        End If

     

          Broj = 0

       

          For i = 0 To 7

           

            j = 0

            If (Shape1(i).BackColor = RGB(255, 0, 0)) Then j = 1

         

            Broj = Broj + 2 ^ i * j

          Next i

         

          Lpt1h = Hex(Broj)

          Text1.Text = Lpt1h

 

End Sub

_____________________________________________________________________

Private Sub Form_Load()

    LPTadresa = &H378  

    Text1.Text = 0

    If Not (IsDriverInstalled) Then MsgBox "IO.DLL ne postoji u \windows\system folderu"

    Call PortOut(LPTadresa, 0)

End Sub

______________________________________________________________________

Private Sub Option1_Click()

If Option1 Then LPTadresa = &H378

End Sub

______________________________________________________________________

Private Sub Option2_Click()

    If Option2 Then LPTadresa = &H278

End Sub

______________________________________________________________________

Private Sub Option3_Click()

    If Option3 Then LPTadresa = &H3BC

End Sub

 

 

 

          Suština ovog programa sastoji se u tome da se prikazane diode  posmatraju kao 8 bitni binarni broj. Pri tome se svakoj od dioda pripiše odgovarajući težinski faktor prema donjoj tabeli.

 

Dioda

Težinski faktor

D0

20

D1

21

D2

22

D3

23

D4

24

D5

25

D6

26

D7

27

 

          Zatim se na osnovu toga sračunava decimalna vrednost broja. Tako naprimer binarni broj prikazan u donjoj tabeli imaće decimalnu vrednost :

 

Dioda

D7

D6

D5

D4

D3

D2

D1

D0

Pozicija

27

26

25

24

23

22

21

20

Bin.broj

0

1

1

0

1

1

1

0

 

broj=21+22+23+25+26=2+4+8+32+64=110

 

         Ovaj se princip u programu rešava u okviru for ciklusa podprograma Form_MouseDown na taj način što se ispituje pozicija diode (zavisno od promenljive i) i ako je ona crvena (RGB (255, 0, 0)) množi se sa odgovarajućim težinskim faktorom (2^i) i sabir u broj.

         Opisaćemo ukratko pojedine podprograme :

 

Private Sub Form_Load()

 

         Ovaj se podprogram startuje automatski učitavanjem forme a zatim se adresi LPT portra priduži vrednost 378H (LPT1). Nakon tog se na Data port komandom Call PortOut(LPTadresa, 0) gase sve dioda, slanjem broja 0 i postavlja heksa vrednost boja na 0 Text1.Text = 0.

 

Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y)

 

         U okviru ovog podprograma se rešava postavljanje dioda na crvenu ili belu boju upotrebom podprograma koji se aktivira na pritisak miša. U njemu se ispituje pozicija kursora i zavisno od toga na kojoj se diodi on nalazi menja boja. Za određivanje pozicije kursora koristimo niz if naredbi pri čemu ispitujemo X i Y kordinatu. Nakon toga se sračunava decimalna vrednost broja, njegova heksa prezentacija i prikazivanje.

 

Private Sub Command2_Click()

 

         U okviru ovog podprograma se dobijeni decimalni broj upisuje na Data port primenom IO funkcije PortOut pritiskom na taster upiši.

 

Private Sub Option1_Click()

         Ovom se kontrolom bira adresa LPT porta i to LPT1, dok se sa ostale dve Option2 i Option3 biraju adrese LPT2 i LPT3.

 

 PROGRAM ZA KONTROLU CONTROL PORTA

 

Izgled ekrana ovog programa prikazan je na slici 2 (PORT03X).

 

 

Slika 2

 

          Princip njegovog rada je sličan prethodnom programu. Kod ovog programa je sledeći:

 

 

 

'

'   Generalna delaracija za upotrebu funkcija IO.DLL

'

Private Declare Sub PortOut Lib "IO.DLL" (ByVal Port As Integer, ByVal Data As Byte)

Private Declare Sub PortWordOut Lib "IO.DLL" (ByVal Port As Integer, ByVal Data As Integer)

Private Declare Sub PortDWordOut Lib "IO.DLL" (ByVal Port As Integer, ByVal Data As Long)

Private Declare Function PortIn Lib "IO.DLL" (ByVal Port As Integer) As Byte

Private Declare Function PortWordIn Lib "IO.DLL" (ByVal Port As Integer) As Integer

Private Declare Function PortDWordIn Lib "IO.DLL" (ByVal Port As Integer) As Long

Private Declare Sub SetPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte)

Private Declare Sub ClrPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte)

Private Declare Sub NotPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte)

Private Declare Function GetPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte) As Boolean

Private Declare Function RightPortShift Lib "IO.DLL" (ByVal Port As Integer, ByVal Val As Boolean) As Boolean

Private Declare Function LeftPortShift Lib "IO.DLL" (ByVal Port As Integer, ByVal Val As Boolean) As Boolean

Private Declare Function IsDriverInstalled Lib "IO.DLL" () As Boolean

Public Broj, LPTadresa, CPTAdresa As Integer

______________________________________________________________________

Private Sub Command2_Click()  

    Call PortOut(CPTAdresa, Broj)

End Sub

______________________________________________________________________

Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

Dim i, j As Integer

         

        i = 5

             

       

        If (X >= 2640) And (X < 3240) And (Y > 1440) And (Y < 1775) Then i = 3   

        If (X >= 3240) And (X < 3840) And (Y > 1440) And (Y < 1775) Then i = 2       

        If (X >= 3840) And (X < 4440) And (Y > 1440) And (Y < 1775) Then i = 1       

        If (X >= 4440) And (X < 5040) And (Y > 1440) And (Y < 1775) Then i = 0

          

        If i <> 5 Then

          

         If (Shape1(i).BackColor = RGB(255, 255, 255)) Then

            Shape1(i).BackColor = RGB(0, 255, 0)

            Else: Shape1(i).BackColor = RGB(255, 255, 255)

            End If

       

        End If

     

          Broj = 0

       

          For i = 0 To 4

           

            j = 0

            If (Shape1(i).BackColor = RGB(0, 255, 0)) Then j = 1

         

            Broj = Broj + 2 ^ i * j

          Next i

         

          Lpt1h = Hex(Broj)

          Text1.Text = Lpt1h

          Broj = Broj Xor 11

 

End Sub

______________________________________________________________________

Private Sub Form_Load()

    If Not (IsDriverInstalled) Then MsgBox "IO.DLL ne postoji u \windows\system folderu"

    LPTadresa = &H378

    CPTAdresa = LPTadresa + 2

   

    Text1.Text = 0

   

    Call PortOut(CPTAdresa, 11)

       

End Sub

______________________________________________________________________

Private Sub Option1_Click()

If Option1 Then LPTadresa = &H378

    CPTAdresa = LPTadresa + 2

End Sub

______________________________________________________________________

Private Sub Option2_Click()

    If Option2 Then LPTadresa = &H278

    CPTAdresa = LPTadresa + 2

End Sub

______________________________________________________________________

Private Sub Option3_Click()

    If Option3 Then LPTadresa = &H3BC

    CPTAdresa = LPTadresa + 2

End Sub

 

 

          U okviru programa za kontrolu kontrol Control porta postoje neke specifičnosti a to su:

 

  • adresa Control porta je za dva veća od Data porta pa je njegova adresa : CPTAdresa=LPTadresa+2
  • budući da su signali C0, C1 i C3 invertovani to smo morali pre prikaza ove bite invertovati što  smo uradili komandom:  Broj=Broj Xor 11

 

 PROGRAM ZA KONTROLU STATUS PORTA

 

Izgled ekrana ovog programa dat je na slici 3 (PORT04X).

 

 

Slika 3

 

          Program za kontrolu Status porta je sledeći:

 

 

'

'   Generalna delaracija za upotrebu funkcija IO.DLL

'

Private Declare Sub PortOut Lib "IO.DLL" (ByVal Port As Integer, ByVal Data As Byte)

Private Declare Sub PortWordOut Lib "IO.DLL" (ByVal Port As Integer, ByVal Data As Integer)

Private Declare Sub PortDWordOut Lib "IO.DLL" (ByVal Port As Integer, ByVal Data As Long)

Private Declare Function PortIn Lib "IO.DLL" (ByVal Port As Integer) As Byte

Private Declare Function PortWordIn Lib "IO.DLL" (ByVal Port As Integer) As Integer

Private Declare Function PortDWordIn Lib "IO.DLL" (ByVal Port As Integer) As Long

Private Declare Sub SetPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte)

Private Declare Sub ClrPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte)

Private Declare Sub NotPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte)

Private Declare Function GetPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte) As Boolean

Private Declare Function RightPortShift Lib "IO.DLL" (ByVal Port As Integer, ByVal Val As Boolean) As Boolean

Private Declare Function LeftPortShift Lib "IO.DLL" (ByVal Port As Integer, ByVal Val As Boolean) As Boolean

Private Declare Function IsDriverInstalled Lib "IO.DLL" () As Boolean

Public Broj, LPTadresa, SPTAdresa As Integer

______________________________________________________________________

Private Sub Command2_Click()

Dim j As Integer

Dim Broj As Byte

Dim i As Byte

 

  Broj = PortIn(SPTAdresa)

  Broj = Broj Xor 128

   

  For i = 3 To 7

    If GetPortBit(SPTAdresa, i) Then

      Shape1(i).BackColor = RGB(0, 0, 255)

      Else

      Shape1(i).BackColor = RGB(255, 255, 255)

     End If

  Next i

  End Sub

______________________________________________________________________

Private Sub Form_Load()

    If Not (IsDriverInstalled) Then MsgBox "IO.DLL ne postoji u \windows\system folderu"

    LPTadresa = &H378

    SPTAdresa = LPTadresa + 1

End Sub

______________________________________________________________________

Private Sub Option1_Click()

If Option1 Then LPTadresa = &H378

    SPTAdresa = LPTadresa + 1

End Sub

______________________________________________________________________

Private Sub Option2_Click()

    If Option2 Then LPTadresa = &H278

    SPTAdresa = LPTadresa + 1

End Sub

______________________________________________________________________

Private Sub Option3_Click()

    If Option3 Then LPTadresa = &H3BC

    SPTAdresa = LPTadresa + 1

End Sub

 

 

Specifičnosti ovog programa su sledeće:

 

 

  • Adresa Status porta je za 1 veća od LPTadresa pa je SPTAdresa=LPTadresa+1
  • Očitavanje statusa prekidača vrši se u podprogramu Sub Command2_Click koji se automatski poziva pritiskom na Ocitaj.

 

Primetite da smo za ispitivanje statusa pojedinačnih bita unutar Status porta koristili funkciji GetPortBit.

 

Moguće je objediniti sva tri programa u jedan pa se dobije ekran kao na slici 4 (PORT05X)

 

 

Slika 4

 

http://vojo.milanovic.org
© Copyright, 2004 Milanović Vojo

All Rights Reserved.