Всем добрый день.
Как из VB 6.0 работать с COM портом?
Мне нужно передать в COM портом текстовою строку, и считать из него текстовою строку.
Как это сделать, подскажите пожалуста?
with MSComm1
.CommPort = 1
.DTREnable = True
.Handshaking = 2
.InBufferSize = 1024
.InputLen = 0
.InputMode = 0
.NullDiscard = True
.OutBufferSize = 512
.ParityReplace = "?"
.RThreshold = 1
.RTSEnable = True
.Settings = "9600,n,8,1"
.SThreshold = 1
.PortOpen=True
end with
Private Sub MSComm1_OnComm()
Dim InBuff As String
If mnuFileShowEvents.Checked = True Then
txtTerm.SelStart = Len(txtTerm.Text)
txtTerm.SelText = "OnComm event, comEv = " & MSComm1.CommEvent & " " & vbCrLf
End If
Select Case MSComm1.CommEvent
' Handle each event or error by placing
' code below each case statement
' Errors
Case comEventBreak ' A Break was received.
ErrMsg = "Break"
' These next three timeout values are no longer detected in Win32
Case comEventCDTO ' CD (RLSD) Timeout.
Case comEventCTSTO ' CTS Timeout.
Case comEventDSRTO ' DSR Timeout.
Case comEventFrame ' Framing Error
ErrMsg = "Framing"
Case comEventOverrun ' Data Lost.
ErrMsg = "Overrun"
Case comEventRxOver ' Receive buffer overflow.
ErrMsg = "OverFlow"
Case comEventRxParity ' Parity Error.
ErrMsg = "Parity"
Case comEventTxFull ' Transmit buffer full.
ErrMsg = "TX Full"
Case comEventDCB ' Unexpected error retrieving DCB]
ErrMsg = "DBC"
' Events
Case comEvCD ' Change in the CD line.
If MSComm1.CDHolding = True Then
StatusBar1.Panels("Status").Text = "Connected"
shpCD.FillColor = vbGreen
cmdSend.Visible = True
Connected = True
Else
StatusBar1.Panels("Status").Text = "Disconnected"
shpCD.FillColor = vbRed
cmdSend.Visible = False
Connected = False
End If
Case comEvCTS ' Change in the CTS line.
Me.bCTS = MSComm1.CTSHolding
If MSComm1.CTSHolding = True Then
shpCTS.FillColor = vbGreen
Else
shpCTS.FillColor = vbRed
End If
Case comEvDSR ' Change in the DSR line.
ErrMsg = ">>DSR Signal"
Case comEvRing ' Change in the Ring Indicator.
ErrMsg = ">>RING"
Case comEvReceive ' Received RThreshold # of chars.
Me.bReceive = True
shpReceive.FillColor = vbGreen
' On Error Resume Next
InBuff = MSComm1.Input
' Debug.Print Err.Number & ":" & Err.Description
Call ScanCom(InBuff)
shpReceive.FillColor = vbRed
Me.bReceive = False
Case comEvSend ' There are SThreshold number of
' characters in the transmit buffer.
Me.bSend = True
shpSend.FillColor = vbGreen
Do While MSComm1.OutBufferCount > 0
DoEvents
Loop
shpSend.FillColor = vbRed
Me.bSend = False
Case comEvEOF ' An EOF character was found in
' the input stream
SMS.SendPrompt = False
End Select
Сейчас этот форум просматривают: AhrefsBot, Google-бот, SemrushBot и гости: 5