Home > Software engineering >  Write a simple serial port, the use of text box to send and receive, but received is not a value typ
Write a simple serial port, the use of text box to send and receive, but received is not a value typ

Time:10-04


At runtime, the result of the returns the ASCII value, rather than numerical

I am not the programming interface is a serial port, there will be other, serial port to send and receive data just want to simple

Application:
Private Sub Command18_Click ()
If Text8. Text="" Then
Pp=MsgBox (" sending data can't be empty!" , 16)
The Exit Sub
End the If

MSComm1. The Output=Trim (Text8. Text)

End Sub

Private Sub MSComm1_OnComm ()

Dim inx () As Byte

Dim gb_temp As Integer


Dim k As Byte

Dim y As Byte


Select Case mEvent MSComm1.Com

Case comEvReceive 'judgment to accept events

Gb_temp=MSComm1. InBufferSize

Gb_temp=MSComm1. InBufferCount


MSComm1. InputLen=CmdLenth 'set up Input one time from the receive buffer read word for


Inx=MSComm1. Input





MSComm1. InBufferCount=0


If tongxun_State=0 Then

For y=0 To CmdLenth - 1


Text9. Text=Text9. Text & amp; "" & amp; Hex (inx (y))



Next y
End the Select


End Sub

CodePudding user response:

LZ receiving code is in bytes (Byte) flow of receiving, need according to the communication protocol specification data formats for data processing,

CodePudding user response:

The concrete should be how to deal with?
I also tried to use a=Split (Text8. Text, ", ") but from the string into a numerical b (I)=Val (a) (I) said type mismatch
Definition is
Dim a
A=Split (Text8. Text, ", ")
Dim b
ReDim b (0 To UBound (a)) As Long

For I=0 To UBound (b)

B (I)=Val (a (I))

MSComm1. The Output=b

Lane for a long time is no good, if one character can be gb=Asc (a (0)) - & amp; H30 output gb, but not a string of characters that ~

CodePudding user response:

reference 1st floor zdingyun response:
LZ receiving code is in bytes (Byte) flow of receiving, need according to the communication protocol specification data formats for data processing,

The concrete should be how to deal with?
I also tried to use a=Split (Text8. Text, ", ") but from the string into a numerical b (I)=Val (a) (I) said type mismatch
Definition is
Dim a
A=Split (Text8. Text, ", ")
Dim b
ReDim b (0 To UBound (a)) As Long

For I=0 To UBound (b)

B (I)=Val (a (I))

MSComm1. The Output=b

Lane for a long time is no good, if one character can be gb=Asc (a (0)) - & amp; H30 output gb, but not a string of characters that ~

CodePudding user response:

Dim strTmp As String

Inx=MSComm1. Input
StrTmp=StrConv (inx vbUnicode)
MSComm1. InBufferCount=0

If tongxun_State=0 Then
For y=0 To CmdLenth - 1
Text9. Text=Text9. Text & amp; "" & amp; Mid (strTmp, y, 1)
Next y
End If

CodePudding user response:

It is good to oneself handle,

CodePudding user response:

ASC () with the good
  • Related