Home > Software engineering >  Sincerely help vb serial port communication failure problem!!!!!!
Sincerely help vb serial port communication failure problem!!!!!!

Time:09-17

I use mscomm1 controls try via bluetooth microcontroller data read from a serial port (com3)
Run the tip real-time error 8002: invalid port number

 Private Sub Form_Load () 
If MSComm1. PortOpen=True Then MSComm1. PortOpen=False 'first to determine whether a serial port to open, If you open the first closed
MSComm1.Com mPort=3 'set port 1
MSComm1. Settings="115200, N, 8, 1" 'set the baud rate, parity, seven data bits, one stop bit
MSComm1. InBufferSize=1024 'sets the receive buffer of 1024 bytes
MSComm1. OutBufferSize=4096 'sets the send buffer of 4096 bytes
MSComm1. InBufferCount=0 'empty input buffer
MSComm1. OutBufferCount=0 'empty output buffer
MSComm1. SThreshold=1 'send buffer empty trigger to send events
MSComm1. RThreshold=1 'every X characters to receive buffer triggered receive events
MSComm1. OutBufferCount=0 'empty send buffer
MSComm1. InBufferCount=0 'empty receive buffer
MSComm1. PortOpen=True 'open the serial port
MSComm1. An InputMode=comInputModeText


The most strange is that with this program can be read by cable port (com6) normal single chip out data, to com3 is no
And with the arduino serial port monitor can be read normal two ports (com6 or com3) data

CodePudding user response:

Information not helped by the analysis of the problems
Invalid port number is invalid port number
This error is generally in a serial port does not exist, when it is
1) that can only be run to confirm you a serial port is exist,
2) Intel ME also like Com3, will there be a serial port of overlapping, really not in the device manager to change the serial number,

CodePudding user response:

The arduino and serial assistants can read so a serial port is the existence of certain
Serial number also changed numerous times and no success...
So I'm very helpless ah t. T

CodePudding user response:

A problem in
MSComm1. PortOpen=True
MSComm1 PortOpen always shows to false

CodePudding user response:

Try without serial port control, use the API to operate

CodePudding user response:

Connect other serial ports are closed, or try to restart the machine,

CodePudding user response:

refer to the second floor u012635375 response:
arduino and serial assistants can read so a serial port is the existence of certain
Serial number also changed numerous times and no success...
So I'm very helpless ah t. T

Please check in the equipment management of several COM exist, the existence of COM slogans,

CodePudding user response:


COM, existing in the device manager VBMsComm controls necessary to open,

CodePudding user response:

 
'link to a serial port
Private Sub Command3_Click ()
Dim I As an Integer, _
M_Port As Integer
M_Port=0
On the Error Resume Next
I=Int (Text1. Text) 'serial no. 1-255
MSComm1. PortOpen=False
If Err. Number & lt;> 0 Then
Err. Clear
End the If
MPort=I
MSComm1.ComMSComm1. Settings="57600, N, 8, 1", "
MSComm1. PortOpen=True
If Err. Number & lt;> 0 Then
Err. Clear
M_Port=0
GoTo protError
End the If
MSComm1. RThreshold=1
MSComm1. SThreshold=1
MSComm1. An InputMode=comInputModeBinary
Shape1. BackColor=& amp; HFFFF& 'get a link to success tips color
The Exit Sub
ProtError:
If m_Port=0 Then
Shape1. BackColor=& amp; HFF& 'get a link failure tip color
The Exit Sub
End the If
End Sub

'
a serial port receives the data event handling processPrivate Sub MSComm1_OnComm ()
Dim the Bytes () As Byte, _
The Size As Long, _
By_tmp As Byte, _
Str_out As String, _
As Long I

On the Error Resume Next
'through the event flags determine whether receive data
If MSComm1.Com mEvent=comEvReceive Then
Bytes=MSComm1.//the data Input 'receives the dynamic array
Size=UBound (Bytes) '//array maximum boundary number
'will receive a one byte of data processing, which can identify began circulating an array of bytes
For I=0 To Size
By_tmp=Bytes (I)
Str_out=str_out & amp; Right (" 0 "& amp; Hex (by_tmp), 2) & amp; "
"'here you can a byte a process information
'...
Next_data:
Next I
AddLog str_out
End the If
End Sub

CodePudding user response:

The device manager obvious hints Com1 Com6 COM3 why you still use?

CodePudding user response:

I=Int (Text1. Text) 'serial no. 1-255

Text1. Text to say VB6 in Val into numerical serial number will be limited to 1 to 16
  • Related