Přístupnost k portům

Funkce:

'Test, zda je daný COM přístupný
Function IsComPortAvailable(ByVal portNum As Integer) As Boolean

    Dim fnum As Integer

    On Error Resume Next
    fnum = FreeFile
    Open "COM" & CStr(portNum) For Binary Shared As #fnum
    If Err = 0 Then
        Close #fnum
        IsComPortAvailable = True
    End If

End Function

'Test, zda je daný LPT port přístupný
Function IsLptPortAvailable(ByVal portNum As Integer) As Boolean

    Dim fnum As Integer

    On Error Resume Next
    fnum = FreeFile
    Open "LPT" & CStr(portNum) For Binary Shared As #fnum
    If Err = 0 Then
        Close #fnum
        IsLptPortAvailable = True
    End If

End Function

Zpět

Autor: The Bozena