Announcement

Collapse
No announcement yet.

Reading Default Comm Port Settings

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Reading Default Comm Port Settings

    It appears that the API Function GetDefaultCommConfig would return information about the specified Comm Port however I have been unable to get any response other than Error 87 (Invalid Parameter). I have searched the forums and it looks like no one has used this Function , or at least posted any code using it. Would someone post a working example of the use of this function?


    ------------------

  • #2
    Code:
    '----------------------------------------------------------------------------
    ' Commport handling. Read state and timing, change if needed and write back
    '                    See CommTimeOuts and DCB in Win32api.hlp for all avai-
    '                    lable parameters. Example gives baudrate.
    '----------------------------------------------------------------------------
    #Compile Exe
    #Include "Win32api.inc"
    
    Function PbMain() As Long
      Local lRet As Long, lDCB As DCB, lCTO As COMMTIMEOUTS, hComm As Long
      hComm = CreateFile ("COM1", _
                           %GENERIC_READ Or %GENERIC_WRITE, _
                           0, _
                           ByVal %NULL, _
                           %OPEN_EXISTING, _
                           0, _
                           ByVal %NULL)
      lRet          = GetCommState (hComm, lDCB)            'Get current settings
    ' lDCB.BaudRate = 19200                                  'Change if needed
      lRet          = SetCommState (hComm, lDCB)            'And write them back
      lRet     = GetCommTimeOuts (hComm, lCTO)              'Get current time-outs
    '  ............................                         'Change if needed
      lRet     = SetCommTimeOuts (hComm, lCTO)              'And write them back
      CloseHandle hComm                                     'Close port
      MsgBox "Baudrate COM1:" + Str$(lDCB.Baudrate)
    End Function
    ------------------
    Peter.
    mailto[email protected][email protected]</A>

    [This message has been edited by Peter Lameijn (edited October 25, 2000).]
    Regards,
    Peter

    Comment

    Working...
    X