A partir d'un programme, trouvé sur le forum autoit http://www.autoitscript.com/forum/index ... c=31708&st, qui gère le port parallèle, j'ai ajouté une Gui avec 16 boutons,
8 pour les données et 8 pour les controles .
Les valeurs des 8 bits de données et 8 bits de controles sont prédéfinies dans un fichier ini .
Lorsque j'appuie sur un bouton, pour l'instant j'arrive à lire la valeur de chaque bits ,visualisée par un indicateur vert=1 ou rouge=0.
Je voudrais :
1-que dés l'ouverture de la Gui , les indicateurs me donnent l'état de chaque bit.
2-pouvoir changer la valeur de chaque bit en appuyant dés la première fois (l'indicateur doit suivre par un changement de couleur), mais juste en mémoire.
3-Il y a une commande qui permet de mettre les bits data en bidirectionnel, mais peut on les placer en entée ou sortie bit par bit ?
4-sauvegarder les données dans le fichier ini à l'appuie du bouton "OK" .
5-la fonction "ChildrenGui()" fera partie d'un programme qui sera appelé à partir d'un menu se trouvant dans la barre de taches.
Je voudrais pouvoir, aprés appuie sur le bouton OK ou CANCEL sortir de ma fen^tre sans que cela bloque mon programme .
Actuellemnt , je sort avec GuiDelete($Gui) , cela bloque l'utilisation du programme principal !
► Afficher le texte
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
;test if INI file exist
If Not FileExists("parallelport.ini") Then
IniWrite("parallelport.ini","PortAddress","PORT","0x378")
IniWrite("parallelport.ini","DataRegister","DATA","0,0,1,1,1,1,1,1")
IniWrite("parallelport.ini","ControlRegister","CONTROL","1,1,1,1,1,1,1,1")
EndIf
Dim $StatusRegisterAddress, $ControlRegisterAddress
$DLLFileAndPath = @ScriptDir & "/inpout32.dll"; remove the @ScriptDir & leading backslash if you prefer to keep the DLL in your system directory
$PortAddress = IniRead("parallelport.ini","PortAddress","PORT","")
ChildrenGui();lancement de la fenêtre fille
Func ChildrenGui()
$Gui= GUICreate("Custom Manual Setup",286,200,-1,-1)
$Annuler = GUICtrlCreateButton("CANCEL",220,160,60,30)
$Ok = GUICtrlCreateButton("OK",150,160,40,30)
GUICtrlCreateLabel("DATA <D0..D7>",90,5,150,30)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Led0 = GUICtrlCreatePic("", 15, 25, 10, 10)
$Led1 = GUICtrlCreatePic("", 50, 25, 10, 10)
$Led2 = GUICtrlCreatePic("", 85, 25, 10, 10)
$Led3 = GUICtrlCreatePic("", 120, 25, 10, 10)
$Led4 = GUICtrlCreatePic("", 155, 25, 10, 10)
$Led5 = GUICtrlCreatePic("", 190, 25, 10, 10)
$Led6 = GUICtrlCreatePic("", 225, 25, 10, 10)
$Led7 = GUICtrlCreatePic("", 260, 25, 10, 10)
$b0 = GUICtrlCreateButton("B0",5,40,30,30)
$b1 = GUICtrlCreateButton("B1",40,40,30,30)
$b2 = GUICtrlCreateButton("B2",75,40,30,30)
$b3 = GUICtrlCreateButton("B3",110,40,30,30)
$b4 = GUICtrlCreateButton("B4",145,40,30,30)
$b5 = GUICtrlCreateButton("B5",180,40,30,30)
$b6 = GUICtrlCreateButton("B6",215,40,30,30)
$b7 = GUICtrlCreateButton("B7",250,40,30,30)
GUICtrlCreateLabel("CONTROL <C0..C7>",75,80,150,30)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Ledc0 = GUICtrlCreatePic("", 15, 100, 10, 10)
$Ledc1 = GUICtrlCreatePic("", 50, 100, 10, 10)
$Ledc2 = GUICtrlCreatePic("", 85, 100, 10, 10)
$Ledc3 = GUICtrlCreatePic("", 120, 100, 10, 10)
$Ledc4 = GUICtrlCreatePic("", 155, 100, 10, 10)
$Ledc5 = GUICtrlCreatePic("", 190, 100, 10, 10)
$Ledc6 = GUICtrlCreatePic("", 225, 100, 10, 10)
$Ledc7 = GUICtrlCreatePic("", 260, 100, 10, 10)
$c0 = GUICtrlCreateButton("B0",5,115,30,30)
$c1 = GUICtrlCreateButton("B1",40,115,30,30)
$c2 = GUICtrlCreateButton("B2",75,115,30,30)
$c3 = GUICtrlCreateButton("B3",110,115,30,30)
$c4 = GUICtrlCreateButton("B4",145,115,30,30)
$c5 = GUICtrlCreateButton("B5",180,115,30,30)
$c6 = GUICtrlCreateButton("B6",215,115,30,30)
$c7 = GUICtrlCreateButton("B7",250,115,30,30)
GUISetState(@SW_SHOW)
;Read Data register
$DataRegisterArray = ReadPortStatus($PortAddress)
$dt0 = $DataRegisterArray[0]
$dt1 = $DataRegisterArray[1]
$dt2 = $DataRegisterArray[2]
$dt3 = $DataRegisterArray[3]
$dt4 = $DataRegisterArray[4]
$dt5 = $DataRegisterArray[5]
$dt6 = $DataRegisterArray[6]
$dt7 = $DataRegisterArray[7]
;Read Control register
$ControlRegisterArray = ReadPortStatus($ControlRegisterAddress)
;$ControlRegisterDisplayString = "Control Register @ " & $ControlRegisterAddress & @CRLF & " (BCD = " & $ControlRegisterArray[8] & ")" & @CRLF & "Bit0 = " & $ControlRegisterArray[0] & " (Pin 1, Strobe {Inverted})" & @CRLF & "Bit1 = " & $ControlRegisterArray[1] & " (Pin 14, Linefeed {Inverted})" & @CRLF & "Bit2 = " & $ControlRegisterArray[2] & " (Pin 16, nInitialise)" & @CRLF & "Bit3 = " & $ControlRegisterArray[3] & " (Pin 17, nSelectPrinter {Inverted})" & @CRLF & "Bit4 = " & $ControlRegisterArray[4] & " (No pin)" & @CRLF & "Bit5 = " & $ControlRegisterArray[5] & " (No pin, BiDirectional Mode)" & @CRLF & "Bit6 = " & $ControlRegisterArray[6] & " (No pin)" & @CRLF & "Bit7 = " & $ControlRegisterArray[7] & " (No pin)"
$ct0 = $ControlRegisterArray[0]
$ct1 = $ControlRegisterArray[1]
$ct2 = $ControlRegisterArray[2]
$ct3 = $ControlRegisterArray[3]
$ct4 = $ControlRegisterArray[4]
$ct5 = $ControlRegisterArray[5]
$ct6 = $ControlRegisterArray[6]
$ct7 = $ControlRegisterArray[7]
;set bidirectional flag
if $ControlRegisterArray[5] = 0 Then
$BiDirectionalCommunication = "Off"
Else
$BiDirectionalCommunication = "On"
EndIf
While 1 ; Boucle de message (voir la section création d'une GUI pour comprendre le fonctionnement)
$nMsg = GUIGetMsg()
Switch $nMsg
; Case $nMsg = 0
; ContinueLoop
Case $GUI_EVENT_CLOSE, $Annuler ; Si la fenêtre est fermée ou si le bouton annulé est cliqué.
GUIDelete($Gui)
Case $b0
$CustomSettings = IniRead("parallelport.ini","DataRegister","DATA","")
$BitArray = StringSplit($CustomSettings, ",")
If $BitArray[1] = 1 Then
GUICtrlSetImage($Led0, "Green-on-16.jpg")
$dt0 = 0
Else
GUICtrlSetImage($Led0, "Red-on-16.jpg")
$dt0 = 1
EndIf
Case $b1
$CustomSettings = IniRead("parallelport.ini","DataRegister","DATA","")
$BitArray = StringSplit($CustomSettings, ",")
If $BitArray[2] = 1 Then
GUICtrlSetImage($Led1, "Green-on-16.jpg")
Else
GUICtrlSetImage($Led1, "Red-on-16.jpg")
EndIf
Case $b2
$CustomSettings = IniRead("parallelport.ini","DataRegister","DATA","")
$BitArray = StringSplit($CustomSettings, ",")
If $BitArray[3] = 1 Then
GUICtrlSetImage($Led2, "Green-on-16.jpg")
Else
GUICtrlSetImage($Led2, "Red-on-16.jpg")
EndIf
Case $b3
$CustomSettings = IniRead("parallelport.ini","DataRegister","DATA","")
$BitArray = StringSplit($CustomSettings, ",")
If $BitArray[4] = 1 Then
GUICtrlSetImage($Led3, "Green-on-16.jpg")
Else
GUICtrlSetImage($Led3, "Red-on-16.jpg")
EndIf
Case $b4
$CustomSettings = IniRead("parallelport.ini","DataRegister","DATA","")
$BitArray = StringSplit($CustomSettings, ",")
If $BitArray[5] = 1 Then
GUICtrlSetImage($Led4, "Green-on-16.jpg")
Else
GUICtrlSetImage($Led4, "Red-on-16.jpg")
EndIf
Case $b5
$CustomSettings = IniRead("parallelport.ini","DataRegister","DATA","")
$BitArray = StringSplit($CustomSettings, ",")
If $BitArray[6] = 1 Then
GUICtrlSetImage($Led5, "Green-on-16.jpg")
Else
GUICtrlSetImage($Led5, "Red-on-16.jpg")
EndIf
Case $b6
$CustomSettings = IniRead("parallelport.ini","DataRegister","DATA","")
$BitArray = StringSplit($CustomSettings, ",")
If $BitArray[7] = 1 Then
GUICtrlSetImage($Led6, "Green-on-16.jpg")
Else
GUICtrlSetImage($Led6, "Red-on-16.jpg")
EndIf
Case $b7
$CustomSettings = IniRead("parallelport.ini","DataRegister","DATA","")
$BitArray = StringSplit($CustomSettings, ",")
If $BitArray[8] = 1 Then
GUICtrlSetImage($Led7, "Green-on-16.jpg")
Else
GUICtrlSetImage($Led7, "Red-on-16.jpg")
EndIf
Case $c0
$CustomSettings = IniRead("parallelport.ini","ControlRegister","CONTROL","")
$BitArray = StringSplit($CustomSettings, ",")
If $BitArray[1] = 1 Then
GUICtrlSetImage($Ledc0, "Green-on-16.jpg")
Else
GUICtrlSetImage($Ledc0, "Red-on-16.jpg")
EndIf
Case $c1
$CustomSettings = IniRead("parallelport.ini","ControlRegister","CONTROL","")
$BitArray = StringSplit($CustomSettings, ",")
If $BitArray[2] = 1 Then
GUICtrlSetImage($Ledc1, "Green-on-16.jpg")
Else
GUICtrlSetImage($Ledc1, "Red-on-16.jpg")
EndIf
Case $c2
$CustomSettings = IniRead("parallelport.ini","ControlRegister","CONTROL","")
$BitArray = StringSplit($CustomSettings, ",")
If $BitArray[3] = 1 Then
GUICtrlSetImage($Ledc2, "Green-on-16.jpg")
Else
GUICtrlSetImage($Ledc2, "Red-on-16.jpg")
EndIf
Case $c3
$CustomSettings = IniRead("parallelport.ini","ControlRegister","CONTROL","")
$BitArray = StringSplit($CustomSettings, ",")
If $BitArray[4] = 1 Then
GUICtrlSetImage($Ledc3, "Green-on-16.jpg")
Else
GUICtrlSetImage($Ledc3, "Red-on-16.jpg")
EndIf
Case $c4
$CustomSettings = IniRead("parallelport.ini","ControlRegister","CONTROL","")
$BitArray = StringSplit($CustomSettings, ",")
If $BitArray[5] = 1 Then
GUICtrlSetImage($Ledc4, "Green-on-16.jpg")
Else
GUICtrlSetImage($Ledc4, "Red-on-16.jpg")
EndIf
Case $c5
$CustomSettings = IniRead("parallelport.ini","ControlRegister","CONTROL","")
$BitArray = StringSplit($CustomSettings, ",")
If $BitArray[6] = 1 Then
GUICtrlSetImage($Ledc5, "Green-on-16.jpg")
Else
GUICtrlSetImage($Ledc5, "Red-on-16.jpg")
EndIf
Case $c6
$CustomSettings = IniRead("parallelport.ini","ControlRegister","CONTROL","")
$BitArray = StringSplit($CustomSettings, ",")
If $BitArray[7] = 1 Then
GUICtrlSetImage($Ledc6, "Green-on-16.jpg")
Else
GUICtrlSetImage($Ledc6, "Red-on-16.jpg")
EndIf
Case $c7
$CustomSettings = IniRead("parallelport.ini","ControlRegister","CONTROL","")
$BitArray = StringSplit($CustomSettings, ",")
If $BitArray[8] = 1 Then
GUICtrlSetImage($Ledc7, "Green-on-16.jpg")
Else
GUICtrlSetImage($Ledc7, "Red-on-16.jpg")
EndIf
Case $Ok
$CustomSettings = InputBox("Custom Bit Settings", "Enter data bit settings required" & @CRLF & @CRLF & "Bits are in order, Bit0 -> Bit 7" & @CRLF & @CRLF & "Enter values as 0 (Low) or 1 (High)", IniRead("parallelport.ini","DataRegister","DATA",""))
$BitArray = StringSplit($CustomSettings, ",")
SetLPTPortPins($PortAddress, $BitArray[1], $BitArray[2], $BitArray[3], $BitArray[4], $BitArray[5], $BitArray[6], $BitArray[7], $BitArray[8])
; IniWrite("parallelport.ini","DataRegister","DATA",$CustomSettings)
; IniWrite("parallelport.ini","DataRegister","DATA",$8datas)
; IniWrite("parallelport.ini","ControlRegister","CONTROL",$8controls)
EndSwitch
WEnd
EndFunc
Func ReadPortStatus($ReadAddress)
;Read the port register (returns a BCD value)
$CurrentPortStatusArray = DllCall($DLLFileAndPath, "int", "Inp32", "int", $ReadAddress)
$StatusToDecode = $CurrentPortStatusArray[0]
;convert to bit status & store in array
Dim $BitsReadArray[9]; [0] -> [7] the decoded bits, [8] the raw BCD value
$BitsReadArray[8] = $CurrentPortStatusArray[0]
$CurrentBitValue = 128
For $BitCounter = 7 To 0 Step - 1
If $StatusToDecode >= $CurrentBitValue Then
$BitsReadArray[$BitCounter] = 1
$StatusToDecode = $StatusToDecode - $CurrentBitValue
Else
$BitsReadArray[$BitCounter] = 0
EndIf
$CurrentBitValue = $CurrentBitValue / 2
Next
;test if good decode obtained
If $StatusToDecode <> 0 Then
MsgBox(0, "Decoding error", "Error in decoding port '" & $PortAddress & "' register '" & $ReadAddress & " status '" & $CurrentPortStatusArray[0] & "' to bits. Do not rely on the results.")
EndIf
Return $BitsReadArray
EndFunc ;==>ReadPortStatus
Func CalculateRegisterAddresses($BaseAddress)
;check for correct hex prefix
If Not (StringLeft($BaseAddress, 2) = "0x" Or StringLeft($BaseAddress, 2) = "0X") Then
MsgBox(0, "Invalid Hex Notation", "The port address " & $BaseAddress & "' entered was not in valid Hexadecimal notation. It must start with '0x'")
Exit
EndIf
;check for valid hex characters in suffix
If StringIsXDigit(StringTrimLeft($BaseAddress, 2)) = 0 Then
MsgBox(0, "Invalid Hex Notation", "The port address " & $BaseAddress & "' entered was not in valid Hexadecimal notation. The characters after the '0x' must be only 0-9 and A-F")
Exit
EndIf
;calculate status register address
;Msgbox (0,"Debug","$BaseAddress = "& $BaseAddress & @CRLF & "StringTrimLeft($BaseAddress, 2) = " & StringTrimLeft($BaseAddress, 2) & @CRLF & "Dec(StringTrimLeft($BaseAddress, 2)) = " & Dec(StringTrimLeft($BaseAddress, 2)) & @CRLF & "Hex(Dec(StringTrimLeft($BaseAddress, 2)) + 1) = " & Hex(Dec(StringTrimLeft($BaseAddress, 2)) + 1))
$RawHex = Hex(Dec(StringTrimLeft($BaseAddress, 2)) + 1)
;trim leading zeros
While 1
If StringLeft($RawHex, 1) = "0" Then
$RawHex = StringTrimLeft($RawHex, 1)
Else
ExitLoop
EndIf
WEnd
$StatusRegisterAddress = "0x" & $RawHex
;calculate control register address
$RawHex = Hex(Dec(StringTrimLeft($BaseAddress, 2)) + 2)
;trim leading zeros
While 1
If StringLeft($RawHex, 1) = "0" Then
$RawHex = StringTrimLeft($RawHex, 1)
Else
ExitLoop
EndIf
WEnd
$ControlRegisterAddress = "0x" & $RawHex
EndFunc ;==>CalculateRegisterAddresses
;Functions -> where the action happens!
Func SetLPTPortPins($WriteAddress, $Bit0, $Bit1, $Bit2, $Bit3, $Bit4, $Bit5, $Bit6, $Bit7)
;Convert bits to BCD
$BCD = 0
If $Bit0 = 1 Then $BCD = $BCD + 1
If $Bit1 = 1 Then $BCD = $BCD + 2
If $Bit2 = 1 Then $BCD = $BCD + 4
If $Bit3 = 1 Then $BCD = $BCD + 8
If $Bit4 = 1 Then $BCD = $BCD + 16
If $Bit5 = 1 Then $BCD = $BCD + 32
If $Bit6 = 1 Then $BCD = $BCD + 64
If $Bit7 = 1 Then $BCD = $BCD + 128
;pass the call to inpout32.dll
DllCall( $DLLFileAndPath, "int", "Out32", "int", $WriteAddress, "int", $BCD)
EndFunc ;==>SetLPTPortPinsMerci par avance de votre aide


