Home > Software engineering >  VB and PLC communication applications, problems: to accept the information can't echo to text2,
VB and PLC communication applications, problems: to accept the information can't echo to text2,

Time:10-09

 Private Sub MSComm1_OnComm () 

Dim temp () As Byte
Dim RCV () As Byte
Dim rcvlenth As Integer
Rcvlenth=1

If Command2. Caption="stop accepting" Then
The Select Case CommEvent
Case comEvReceive
Temp=MSComm1. Input
ReDim Preserve temp (UBound (temp)) As Byte
For I=LBound (temp) To UBound (temp)
Rcvlenth=rcvlenth + 1
RCV (I)=temp (I)
Next I

ReDim Preserve RCV (rcvlenth) As Byte
For I=LBound (RCV) To UBound (RCV)
Text2=Text2 & amp; STR $(RCV) (I) & amp; "
"Next I
End the Select
End the If

MSComm1. InBufferCount=0
MSComm1. OutBufferCount=0

End Sub





Code as above, please help to look at thank you ~ ~

CodePudding user response:

Temp=MSComm1. Input
ReDim Preserve temp (UBound (temp)) As Byte

Suppose you first sentence has been accepted to the data, the second sentence redefine what length for?
Besides, it with the as redim Byte, it can only change the length, can't change the type of the (even before and the definition of the same type)

CodePudding user response:

reference 1st floor WallesCai response:
temp=MSComm1. Input
ReDim Preserve temp (UBound (temp)) As Byte

Suppose you first sentence has been accepted to the data, the second sentence redefine what length for?
Besides, it with the as redim Byte, it can only change the length, can't change the type (even before the definition of the same type) and


ReDim Preserve function is redefined, but keep the contents of the array before, only can extend the length of the array,

In Case comEvReceive set breakpoints here, whether can you stop?
Whether set mscomm1. Rthreshold=1 (or other non-zero values), you must not set, because I set up,,,
In addition in the first cycle
Rcvlenth=rcvlenth + 1
RCV (I)=temp (I)
RCV array is not defined here,

CodePudding user response:

 Dim temp As the Variant 
Dim RCV () As Byte
Dim rcvlenth As Integer
Rcvlenth=1

If Command2. Caption="stop accepting" Then
The Select Case CommEvent
Case comEvReceive
Temp=MSComm1. Input
Rcvlenth=UBound (temp)
Redim RCV (rcvlenth)
For I=0 To rcvlenth
RCV (I)=temp (I)
Next I

For I=0 To rcvlenth
Text2=Text2 & amp; CStr (RCV) (I) & amp; "
"Next I
End the Select
End the If

CodePudding user response:

Thanks for your help, the last research down PLC loopback format might be the problem, first the VB100, until VB102 are bytes, and the first character and so on, VB103 real data area began to special thanks of123 great god, and two post to answer and give me great help. Thanks
  • Related