Home > Software engineering >  Vb usb to rs232 serial port communication
Vb usb to rs232 serial port communication

Time:10-08

Recently wrote a PC, send hexadecimal instructions to lower place machine and then receive!!! Use rsr232 communication is stable, but use USB turn the huge data interference, fetch back in front of the data to produce 2-4 interference data, and open the serial port will generate an error comevcts, familiar with this aspect of the expert help solve please, thank!

CodePudding user response:

Hardware or driver problem, common USB connector, if no accident, you are using a USB conversion head must be the sort of 15 or so, I suggest you change better,

CodePudding user response:


U go there are many types of chips, used in the string line is good and bad are intermingled, I used the best is the FT232 chips, stability,

CodePudding user response:

refer to the second floor of123 response:
there are many types of chips, used in the U turn string line is good and bad are intermingled, I used the best is the FT232 chips, stability,


My program, too, when using a serial program is stable and receiving data is normal, because the laptop without a serial port, with a usb serial port, so I also installed driver, can not program is receiving data, program nor any error, do not know why, after transferred application methods of communication have to change? Please answer, thank you!

CodePudding user response:

Don't have to change completely,

However, you may want to change the serial number according to the circumstance, see U turn series mapping virtual serial port, if the FT232 chips, can under the operating system directly change the serial number of virtual serial port, if conflict with inherent serial port on a PC is not,

CodePudding user response:

reference 4 floor of123 response:
don't have to change completely,

However, you may want to change the serial number according to the circumstance, have a look at U number list of mapping virtual serial port, if the FT232 chips, you can directly under the operating system to change the serial number of virtual serial port, if the inherent serial port on a PC without conflict,


I have change the serial number in the device manager, there is no conflict, by the way, turn the usb serial port after the program is not an error, but other equipment error, PLC can not run normally, use a serial port procedures and equipment when everything is normal, I guess is a usb serial port can't normal communication, after equipment the cache is full, so the PLC equipment running in the middle is an error, do not know why,

'* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
'initialize the MSCOMM control
'* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 Private Function uflInitRS () 
On Error GoTo ErrorTrap:
If Not comLaser. PortOpen Then
ComLaser. CDTimeout=0
ComLaser. CTSTimeout=0
ComLaser. DSRTimeout=0
ComLaser. RTSEnable=True
ComLaser. DTREnable=True
MPort=1
comLaser.ComComLaser. Settings="9600, N, 8, 1", "
ComLaser. InputLen=0
ComLaser. PortOpen=True
End the If
UflInitRS=0
The Exit Function
ErrorTrap:
UflInitRS=Err
End the Function

'* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
'close the MSCOMM
'* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Private Function uflQuitRS ()

If comLaser. PortOpen Then
ComLaser. PortOpen=False
End the If
End
End the Function


'* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
'application runtime MSCOMM read
'* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Private Sub Ceshi ()

Dim bufInput As String
Dim RecData As String

Do
If comLaser. InBufferCount & gt; 0 Then
RecDatahttps://bbs.csdn.net/topics/=""
ComLaser. InputLen=1 'to determine the input property reads the number of characters for 1
Do
If comLaser. InBufferCount & gt; If=0 Then 'data exist in the receive buffer is greater than or equal to zero
BufInput=comLaser. Input

The Select Case bufInput
Case CRH (10) 'newline
The Exit Do
Case CRH (13) 'enter
UCnt=uCnt + 1
The Exit Do
In Case the Else
RecData=https://bbs.csdn.net/topics/RecData & bufInput
End the Select
The Else
RecDatahttps://bbs.csdn.net/topics/=""
The Exit Do
End the If
Loop

Call Sleep (100)

'- the data format
'- P0: * * * * * * * * * * 19.7895 P5: * * * * * * * * * * * 0.0328 the length of the string, 40 CR number: 1

If the Format (Val (Mid (RecData, 4)), "0.0000") & lt;=0 Or Format (Val (Mid) (RecData, 24), "0.0000") & lt;=0 Then
GoTo AA:
End the If

If uCnt=1 Then
Call uflRegClear 'removal Inpt (uCnt). Gaik and Inpt (uCnt).
Fure dataLstResult (0). The AddItem Point OD "Offset" 'lstResult (0) is the ListBox control
LstResult (0). The AddItem Right (the Format (uCnt, "#"), 3) & amp; "" & amp; The Format (Val (Mid (RecData, 4)), "0.0000") & amp; "" & amp; The Format (Val (Mid) (RecData, 24), "0.0000")
The Else
LstResult (0). The AddItem Right (the Format (uCnt, "#"), 3) & amp; "" & amp; The Format (Val (Mid (RecData, 4)), "0.0000") & amp; "" & amp; The Format (Val (Mid) (RecData, 24), "0.0000")
End the If

Inpt (uCnt). Gaik=Format (Val (Mid (RecData, 4)), "0.0000") 'diameter value
Inpt (uCnt). Fure=Format (Val (Mid) (RecData, 24), "0.0000") 'eccentric value

If Val (lblPoint. Text)=uCnt Then 'points o have tested whether uCnt equals the indicators (lblPoint control is used to access a product's need to test points)
Num=Num + 1 'for the number of tested products
LblResCn (0). The Caption Num=
Call uflWriteLot
UCnt=0
End the If

End the If
AA:
DoEvents
Loop

End Sub

CodePudding user response:

Try to change back to the default serial number, keep in mind that the VB code to also want to change,

CodePudding user response:

You say this seems to be the first to exclude a hardware problem, I use PL2303, very stable across!
  • Related