[elektro] Terminal v.1.9b

Kovács József kj at faldeko.hu
Sun Nov 20 23:15:27 CET 2011



> Apropó, azt hogyan lehet megtudni, az USB-k milyen COM-porton vannak?
> Ja, XP.
>
> Gyula


VB6 alatt pl. így... lásd alább.
Más nyelvre a Type-ok és Function-ok értelemszerűen deklarálhatók.

Lefordítva itt az exe, hátha műxik Nálad is.
http://www.faldeko.hu/com_ports_vb6.exe
(vb6 runtime kell hozzá, ha nincs)


KJ

---- egy modulba ez ----

Type DCB
    DCBlength As Long
    BaudRate As Long
    fBitFields As Long
    wReserved As Integer
    XonLim As Integer
    XoffLim As Integer
    ByteSize As Byte
    Parity As Byte
    StopBits As Byte
    XonChar As Byte
    XoffChar As Byte
    ErrorChar As Byte
    EofChar As Byte
    EvtChar As Byte
    wReserved1 As Integer
End Type

Type COMMCONFIG
    dwSize As Long
    wVersion As Integer
    wReserved As Integer
    dcbx As DCB
    dwProviderSubType As Long
    dwProviderOffset As Long
    dwProviderSize As Long
    wcProviderData As Byte
End Type

Declare Function GetDefaultCommConfig Lib "kernel32" Alias 
"GetDefaultCommConfigA" (ByVal lpszName As String, lpCC As COMMCONFIG, 
lpdwSize As Long) As Long

Public Function EnumSerPorts(port As Integer) As Long
'returns non-zero value if the port exists
    Dim cc As COMMCONFIG, ccsize As Long
    ccsize = LenB(cc)     'gets the size of COMMCONFIG structure
    EnumSerPorts = GetDefaultCommConfig("COM" + Trim(Str(port)) + 
Chr(0), cc, ccsize)

End Function


--- egy formba, amin van Label2 ez ----

Option Explicit

Dim PortNum As Integer
Dim PortNumMin As Integer
Dim PortNumMax As Integer

Private Sub Form_Load()

    Beep

    PortNumMin = 0
    PortNumMax = 30

    Me.Show

    PortNum = PortNumMin

    'Start port kereses
    While PortNum < PortNumMax
       PortNum = PortNum + 1
       If EnumSerPorts(PortNum) Then
         Label2 = Label2 & "COM" & PortNum & IIf(PortNum < 10, "    ", " 
  ") & "VAN" & vbCrLf
       Else
          Label2 = Label2 & "COM" & PortNum & IIf(PortNum < 10, "    ", 
"  ") & "-------" & vbCrLf
       End If

    Wend

    Beep

End Sub



More information about the Elektro mailing list