Current location - Quotes Website - Collection of slogans - I wrote a program about serial communication with vb. When debugging, I found that as long as I opened the serial port, he would jump out of the message' invalid port number'.
I wrote a program about serial communication with vb. When debugging, I found that as long as I opened the serial port, he would jump out of the message' invalid port number'.
The code of LZ opens COM3 by default. I wonder what the virtual serial number of LZ is?

Look carefully at the name of the control selected by LZ's COM port. The number 1 is the letter L in the code, so the COM port cannot be selected.

Revise as follows:

Private? Sub? Combo 1_Click()

What if? MSComm 1。 PortOpen? =? Really? then

MSComm 1。 PortOpen? =? "False" closes the communication port.

End? if

MSComm 1。 CommPort? =? Combo 1。 ListIndex? +? 1

Text3? =? MSComm 1。 Communication port

End? submarine

Private? Sub? Command 1_Click()

Open? Mistakes? GoTo? U error

What if? Command 1. Title? =? "Close the serial port"? then

MSComm 1。 PortOpen? =? wrong

Command 1. Title? =? "Open serial port"

Shape 1。 FillColor? =? & ampHFFFFC0

other

MSComm 1。 PortOpen? =? real

Command 1. Title? =? "Close the window"

Shape 1。 FillColor? =? & ampHFF

End? if

Quit submarine

U error:

msg$? =? "Invalid port number"

Title $? =? "Serial Debugging Assistant"

x? =? MsgBox(msg$,? 48,? Title $)

End? submarine

Private? Sub? form_load()

What if? MSComm 1。 PortOpen? =? Really? then

MSComm 1。 PortOpen? =? wrong

other

End? if

Combo 1。 AddItem? " COM 1 "

Combo 1。 AddItem? " COM2 "

Combo 1。 AddItem? " COM3 "

Combo 1。 AddItem? " COM4 "

Combo 1。 AddItem? " COM5 "

Combo 1。 AddItem? " COM6 "

Combo 1。 AddItem? " COM7 "

Combo 1。 AddItem? " COM8 "

Combo 1。 ListIndex? =? 0

MSComm 1。 CommPort? =? Combo 1。 ListIndex? +? 1

MSComm 1。 Settings? =? 19200,n,8, 1

Command 1. Title? =? "Open serial port"

Shape 1。 FillColor? =? & ampHFFFFC0

Option 2. Value? =? real

Combination 2. AddItem? "256000"

Combination 2. AddItem? " 128000"

Combination 2. AddItem? " 1 15200"

Combination 2. AddItem? "57600"

Combination 2. AddItem? "38400"

Combination 2. AddItem? "28800"

Combination 2. AddItem? " 19200"

Combination 2. AddItem? "9600"

Combination 2. AddItem? "4800"

Combination 2. AddItem? "2400"

Combination 2. AddItem? " 1200"

Combo3。 AddItem? "No? None "

Combo3。 AddItem? "Strange? Weird "

Combo3。 AddItem? "even? Even "

Combo4。 AddItem? "4"

Combo4。 AddItem? "5"

Combo4。 AddItem? "5"

Combo4。 AddItem? "6"

Combo4。 AddItem? "7"

Combo4。 AddItem? "8"

Combination 5. AddItem? " 1"

Combination 5. AddItem? "2"

MSComm 1。 InBufferSize? =? 1024

MSComm 1。 External buffer size? =? 5 12

MSComm 1。 RThreshold? =? 1

End? submarine

Private? Sub? MSComm 1 _ on com()

Dim? BytReceived()? As? byte

Dim? Me? As? integer

Choice? Case? MSComm 1。 CommEvent

Case? comEventRxOver

Text 1。 Words? =? ""

Quit submarine

Case? comEvReceive

MSComm 1。 InputLen? =? 0

strBuff? =? MSComm 1。 invest

What if? MSComm 1。 InputMode? =? comInputModeBinary? then

BytReceived()? =? strBuff

For what? Me? =? 0? Where to? UBound (received bytes)

What if? Len(Hex(BytReceived(i)))? =? 1? then

strData? =? strData? & amp? "0"? & amp? Hex(BytReceived(i))? & amp? ""

other

strData? =? strData? & amp? Hex(BytReceived(i))? & amp? ""

End? if

then

Text 1? =? Text 1? & amp? strData

strData? =? ""

other

Text 1? =? Text 1? & amp? strBuff

End? if

End? choose

End? submarine

Private? Sub? Option 1_Click()

MSComm 1。 InputMode? =? comInputModeText

End? submarine

Private? Sub? Option2_Click()

MSComm 1。 InputMode? =? comInputModeBinary

End? submarine