Guidance
指路人
g.yi.org
software / rapidq / Examples / Devices / RS232 Serial Port / comio / SampleCode.txt.bas

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
     DIM intPortID AS INTEGER ' Ex. 1, 2, 3, 4 for COM1 - COM4
     DIM lngStatus AS LONG
     DIM strError  AS STRING
     DIM strData   AS STRING


    ' Initialize Communications
     lngStatus = CommOpen(intPortID, "COM" & CStr(intPortID), _
      "baud=9600 parity=N data=8 stop=1")

     IF lngStatus <> 0 THEN
	' Handle error.
      lngStatus = CommGetError(strError)
      MsgBox "COM Error: " & strError
     END IF


    ' Set modem control lines.
     lngStatus = CommSetLine(intPortID, LINE_RTS, True)
     lngStatus = CommSetLine(intPortID, LINE_DTR, True)

    ' Write data to serial port.
     lngSize = LEN(strData)
     lngStatus = CommWrite(intPortID, strData)
     IF lngStatus <> lngSize THEN
	' Handle error.
     END IF



    ' Read maximum of 64 bytes from serial port.
     lngStatus = CommRead(intPortID, strData, 64)
     IF lngStatus > 0 THEN
        ' Process data.
     ELSEIF lngStatus < 0 THEN
        ' Handle error.
     END IF

    ' Reset modem control lines.
     lngStatus = CommSetLine(intPortID, LINE_RTS, False)
     lngStatus = CommSetLine(intPortID, LINE_DTR, False)



    ' Close communications.
     CALL CommClose(intPortID)
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Sat 2024-12-14  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2001-08-09 09:19:30