Good day,
I am an average programmer, but have only just entered the Visual Basic world. I am happy to say it all makes good sense and am progressing quickly.
One problem is that I can't get any comm port to open in my system! I am using the most simple of codes to see if I can simply open and send data. The "dumbed up" code is as follows:
Private Sub Command1_Click()
Dim iPort As Long
iPort = 3 ' I place the port to check here
If COMCheckPort(iPort) Then
MSComm1.CommPort = iPort
MSComm1.Settings = "9600,N,8,1"
MSComm1.DTREnable = False
MSComm1.PortOpen = True
Else
End
End If
End Sub
Private Sub Command2_Click()
MSComm1.Output = Chr$(255)
End Sub
Private Function COMCheckPort(Port As Long) As Boolean
'Returns false if port cannot be opened or does not exist
'Returns true if port is available and can be opened
'Handle all errors
On Error GoTo OpenCom_Error
'Set port number for test
MSComm1.CommPort = Port
If MSComm1.PortOpen = True Then
COMCheckPort = False
Exit Function
Else
'Test the port by opening and closing it
MSComm1.PortOpen = True
MSComm1.PortOpen = False
COMCheckPort = True
Exit Function
End If
OpenCom_Error:
COMCheckPort = False
End Function
I suspect many will give me code improvements. I appreciate that. However I have a more basic question? What could keep my system from successfully opening any Com Port? I know they are not already open because when I try to "Send a byte", I get a run time error saying the port is not open.
Any help/diagnostic method would be much appreciated!
I am an average programmer, but have only just entered the Visual Basic world. I am happy to say it all makes good sense and am progressing quickly.
One problem is that I can't get any comm port to open in my system! I am using the most simple of codes to see if I can simply open and send data. The "dumbed up" code is as follows:
Private Sub Command1_Click()
Dim iPort As Long
iPort = 3 ' I place the port to check here
If COMCheckPort(iPort) Then
MSComm1.CommPort = iPort
MSComm1.Settings = "9600,N,8,1"
MSComm1.DTREnable = False
MSComm1.PortOpen = True
Else
End
End If
End Sub
Private Sub Command2_Click()
MSComm1.Output = Chr$(255)
End Sub
Private Function COMCheckPort(Port As Long) As Boolean
'Returns false if port cannot be opened or does not exist
'Returns true if port is available and can be opened
'Handle all errors
On Error GoTo OpenCom_Error
'Set port number for test
MSComm1.CommPort = Port
If MSComm1.PortOpen = True Then
COMCheckPort = False
Exit Function
Else
'Test the port by opening and closing it
MSComm1.PortOpen = True
MSComm1.PortOpen = False
COMCheckPort = True
Exit Function
End If
OpenCom_Error:
COMCheckPort = False
End Function
I suspect many will give me code improvements. I appreciate that. However I have a more basic question? What could keep my system from successfully opening any Com Port? I know they are not already open because when I try to "Send a byte", I get a run time error saying the port is not open.
Any help/diagnostic method would be much appreciated!