i have following code but it is not working
Sub serial()
Dim intPortID As Integer ' Ex. 1, 2, 3, 4 for COM1 - COM4
Dim lngStatus As Long
Dim strData As String
Dim strData1 As String
intPortID = 6
' Open COM port
lngStatus = CommOpen(intPortID, "COM" & CStr(intPortID), _
"baud=9600 parity=N data=8 stop=1")
If (lngStatus) Then
MsgBox "Can not open port", vbCritical
Else
MsgBox "Port opened successfully!", vbInformation
End If
End Sub
Sub wserial()
Dim intPortID As Integer ' Ex. 1, 2, 3, 4 for COM1 - COM4
Dim lngStatus As Long
Dim strData As String
Dim strData1 As String
intPortID = 6
strData = "/r"
'Writa data
lngStatus = CommWrite(intPortID, strData)
If lngStatus Then
MsgBox "Can not write to port" + CStr(intPortID), vbExclamation
Else
MsgBox "Write " + strData + " to" + CStr(intPortID) + " sucessfully!", vbInformation
End If
' lngStatus = CommRead(intPortID, strData1, 1)
'If (lngStatus) Then
'MsgBox "Can not read", vbCritical
'Else
'MsgBox "read data successfully", vbInformation
'End If
'Range("A1").Value = strData1
End Sub
Sub rserial()
Dim intPortID As Integer ' Ex. 1, 2, 3, 4 for COM1 - COM4
Dim lngStatus As Long
Dim strData As String
Dim strData1 As String
intPortID = 6
lngStatus = CommRead(intPortID, strData1, 2)
If (lngStatus) Then
MsgBox "Can not read", vbCritical
Else
MsgBox "read data successfully", vbInformation
End If
Range("A1").Value = strData1
End Sub
Sub cserial()
Dim intPortID As Integer
intPortID = 6
Call CommClose(intPortID)
End Sub

New Topic/Question
Reply



MultiQuote





|