Macro spéciale
Bonsoir le forum,
Je vous joint un fichier qui sert manuellement à trouver le port disponible pour générer l'ouverture d'un tiroir caisse, il fonctionnne mais je souhaiterais faire une boucle dans le code pour qui cherche et trouve le port disponible automatiquement actuellement sur mon PC le port 4 est le bon. Si quelqu'un et des connaissances dans se type de code je le remerci d'avance pour son aide.
Cordialement
Glt
Bonjour,
Pas facile à dire car je ne peux pas tester sur ma machine l'ouverture du code, essaye à tout hasard de mettre ça dans ton code :
Private Sub CommandButton1_Click()
'All Relays ON button
On Error Resume Next 'Error handler
For i = 1 To 10
NETComm1.CommPort = i
If NETComm1.PortOpen = False Then 'check if the serial port is open
NETComm1.PortOpen = True 'check if the serial port is open
End If
If Err Then
MsgBox Error$, 48 'Display error in message box
Exit Sub
End If
Next
'Set all outputs to High (serial relay board commands)
NETComm1.Output = Chr(27) & Chr(52)
'Close serial port on exit
On Error Resume Next 'Error handler
If NETComm1.PortOpen = True Then 'check if the serial port is open
NETComm1.PortOpen = False 'close the serial port
End If
If Err Then MsgBox Error$, 48 'Display error in message box
End Sub
Tu n'as plus à cliquer sur les boutons d'options car For/Next teste les ports de 1 à 10.
A+
dachevid, le forum bonjour,
Merci pour l'intéret que tu as porté à ma demande,un ami Exelite à trouvé le code
Sub Ouverture_Tiroir()
Dim I As Integer
On Error Resume Next
For I = 1 To 10
NETComm1.CommPort = I
If NETComm1.PortOpen = False Then ' Vérif si le port est Fermé
NETComm1.PortOpen = True ' Ouvre le port
End If
If Err = 0 Then Exit For ' Pas d'erreur lors de l'ouverture alors on sort
Err.Clear ' On efface l'erreur
Next I
'MsgBox Err & " " & I
If NETComm1.PortOpen = False Then ' Vérif si le port est Fermé
MsgBox "Erreur d'ouverture caisse" & vbCr & _
" Veuillez contacter de toute urgence le responsable ", _
vbCritical + vbOKOnly, "Erreur fatale"
'MsgBox Error$, vbCritical + vbQuestion
Exit Sub
End If
NETComm1.Output = Chr(27) & Chr(52) ' Ouverture tiroir
If NETComm1.PortOpen = True Then ' Le port est Ouvert ?
NETComm1.PortOpen = False ' Oui alors on le ferme
End If
If Err Then MsgBox Error$, vbCritical + vbQuestion ' Erreur lors de la fermeture
On Error GoTo 0 ' Rétablit la gestion des erreurs (Inutile je pense à ce niveau)
End Sub
Peut-être que cela peut rendre service
bonne journée
Glt