Home > Software engineering >  VB communication problems
VB communication problems

Time:10-04

Vb use two MSCOMM control, can receive different microcontroller sent data at the same time?

Procedure is as follows:

Private Sub Timercomm_Timer () time 50 ms

CurrentCommUnit=CurrentCommUnit + 1 'the next cycle, loop, add a
If CurrentCommUnit & gt; CommUnits Then 'is greater than the maximum return, is the current communication circuit loop back to the first
all the wayCurrentCommUnit=1
End the If

Buf_CommXH (0)=& amp; H64
Buf_CommXH (1)=CurrentCommUnit
Buf_CommXH (2)=Buf_CommXH (0) + Buf_CommXH calculation check code (1) '
MSComm1. RThreshold=6
MSComm1. OutBufferCount=0 'removal send buffer data
MSComm1. InBufferCount=0
MSComm1. SThreshold=1
MSComm1. The Output=Buf_CommXH 'send 3 bytes

CommUnitT=CommUnitT + 1 'the next cycle, loop, add a
If CommUnitT & gt; 2 Then 'is greater than the maximum return, is the current communication circuit loop back to the first
all the wayCommUnitT=1
End the If

Buf_Command (0)=& amp; HF1
Buf_Command (1)=CommUnitT
Jym_TX=CLng (Buf_Command (0)) + CLng (Buf_Command (1)) calculation check code
'CheckSum_TX=Jym_TX Mod 256
Buf_Command (2)=CheckSum_TX \ 16
Buf_Command (3)=CheckSum_TX Mod 16
MSComm2. RThreshold=2
MSComm2. OutBufferCount=0 'removal send buffer data
MSComm2. InBufferCount=0
MSComm2. SThreshold=1
MSComm2. The Output=Buf_Command 'send 4 bytes
End sub


Private Sub Form_Load ()
MSComm1. Settings="9600, n, 8, 1", "
MPort=1
MSComm1.ComMSComm1. InBufferSize=1024
MSComm1. InputLen=0 'sets or returns a number of bytes read from the receive buffer, 0 indicates a read all data
MSComm1. An InputMode=1 'reception mode, 0=text, 1=binary
MSComm1. OutBufferCount=0 'removal send buffer data
MSComm1. OutBufferSize=1024
MSComm1. PortOpen=True

MSComm2. Settings="9600, n, 8, 1", "
MPort=2
MSComm2.ComMSComm2. InBufferSize=1024
MSComm2. InputLen=0 'sets or returns a number of bytes read from the receive buffer, 0 indicates a read all data
MSComm2. An InputMode=1 'reception mode, 0=text, 1=binary
MSComm2. OutBufferCount=0 'removal send buffer data
MSComm2. OutBufferSize=1024
MSComm2. PortOpen=True
'-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
'9600 baud rate, TimerComm delay 50 ms, and each loop communication
'-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
TimerComm. Interval=50
TimerComm. Enabled=True
End Sub

CodePudding user response:

Can be used at the same time two MsComm control with two different single chip microcomputer communication,

CodePudding user response:

reference 1st floor zdingyun response:
can simultaneously use two MsComm control with two different single chip microcomputer communication,

Hope in their OnComm event to receive the single chip microcomputer the data returned,

CodePudding user response:

Thank you very much for your help!

I write this timer is there a problem?
OnComm event, be sure to receive single-chip microcomputer the data returned with two

CodePudding user response:

The
reference 3 floor xfl0779 response:
thank you very much for your help!

I write this timer is there a problem?
OnComm event, be sure to receive single-chip microcomputer the data returned with two

Code not found big problems, pay attention to use the variable declaration.
 Option Explicit 
Dim Buf_CommXH (2) the As Byte
Dim CurrentCommUnit As Integer
Dim CommUnits As Integer
Dim CommUnitT As Integer
Dim Buf_Command (3) As Byte
Dim Jym_TX As Byte
Dim CheckSum_TX

Private Sub Timercomm_Timer () 'timing 50 ms
CurrentCommUnit=CurrentCommUnit + 1 'the next cycle, loop, add a
If CurrentCommUnit & gt; CommUnits Then 'is greater than the maximum return, is the current communication circuit loop back to the first
all the wayCurrentCommUnit=1
End the If
Buf_CommXH (0)=& amp; H64
Buf_CommXH (1)=CurrentCommUnit
Buf_CommXH (2)=Buf_CommXH (0) + Buf_CommXH calculation check code (1) '
MSComm1. RThreshold=6
MSComm1. OutBufferCount=0 'removal send buffer data
MSComm1. InBufferCount=0
MSComm1. SThreshold=1
MSComm1. The Output=Buf_CommXH 'send 3 bytes

CommUnitT=CommUnitT + 1 'the next cycle, loop, add a
If CommUnitT & gt; 2 Then 'is greater than the maximum return, is the current communication circuit loop back to the first
all the wayCommUnitT=1
End the If
Buf_Command (0)=& amp; HF1
Buf_Command (1)=CommUnitT
Jym_TX=CLng (Buf_Command (0)) + CLng (Buf_Command (1)) calculation check code
'CheckSum_TX=Jym_TX Mod 256
Buf_Command (2)=CheckSum_TX \ 16
Buf_Command (3)=CheckSum_TX Mod 16
MSComm2. RThreshold=2
MSComm2. OutBufferCount=0 'removal send buffer data
MSComm2. InBufferCount=0
MSComm2. SThreshold=1
MSComm2. The Output=Buf_Command 'send 4 bytes
End Sub

Private Sub Form_Load ()
MSComm1. Settings="9600, n, 8, 1", "
MPort=1
MSComm1.ComMSComm1. InBufferSize=1024
MSComm1. InputLen=0 'sets or returns a number of bytes read from the receive buffer, 0 indicates a read all data
MSComm1. An InputMode=1 'reception mode, 0=text, 1=binary
MSComm1. OutBufferCount=0 'removal send buffer data
MSComm1. OutBufferSize=1024
MSComm1. PortOpen=True

MSComm2. Settings="9600, n, 8, 1", "
nullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related