Home > Software engineering >  Consult everybody, the problem of MSCOMM control, thank you
Consult everybody, the problem of MSCOMM control, thank you

Time:11-01

Do a test equipment, test object to send data hexadecimal data 3 b 86 to a computer, requires within 4 ms computer reply 58, said receiving success, MSCOMM control can do excuse me? I wrote a program with the ONCOMM tried, seems to be no,,,

CodePudding user response:

4 ms... It should be!

CodePudding user response:

If your PC COM port hardware no problem, and take the OnComm event, the code to handle properly, should be no problem.

CodePudding user response:

In terms of time, there is no problem,

CodePudding user response:

Tests show that USES PC bringing the COM, send x3b86 to receive 0 0 x58 time & lt; 10 ms, can meet the requirements seems to have a problem.
The code is as follows:
 Private Sub Command1_Click () 
Dim sendsj (1) the As Byte
Sendsj (0)=& amp; H3B
Sendsj (1)=& amp; H86
The Debug. Print 0, the Timer
MSComm1. The Output=sendsj
End Sub

Private Sub Form_Load ()
MPort=1
MSComm1.ComMPort=3
MSComm2.ComMSComm1. PortOpen=True
MSComm2. An InputMode=comInputModeBinary
MSComm1. An InputMode=comInputModeBinary
MSComm2. PortOpen=True
MSComm1. RThreshold=1
MSComm2. RThreshold=1
End Sub

Private Sub MSComm1_OnComm ()
Dim Bytsj () As Byte
Dim As Long I
Dim hexstr As String
Select Case mEvent MSComm1.Com
Case 2
The Debug. Print 2, Timer
Bytsj=MSComm1. Input
For I=0 To UBound (Bytsj)
Hexstr=hexstr & amp; Right (" 0 "& amp; Hex (Bytsj (I)), 2)
Next
If Mid (hexstr, 1, 2)="58" Then
Text1=58
End the If
End the Select
End Sub

Private Sub MSComm2_OnComm ()
Dim Bytsj () As Byte
Dim As Long I
Dim hexstr As String
Select Case mEvent MSComm2.Com
Case 2
The Debug. Print 1, Timer
Bytsj=MSComm2. Input
For I=0 To UBound (Bytsj)
Hexstr=hexstr & amp; Right (" 0 "& amp; Hex (Bytsj (I)), 2)
Next
If Mid (hexstr, 1, 4)="3 b86" Then
Dim sendsj (0) As Byte
Sendsj (0)=& amp; H58
MSComm2. The Output=sendsj
End the If
End the Select
End Sub


0
76475.411
76475.422, 76475.42


CodePudding user response:

Thank zdingyun, I had always do hardware, using VB to write a serial port programs for the first time, so many do not understand, I actually use oscilloscope to test, I received my object detection from programs written 3 b, 86, after application of judgment, after 35 ms to 58, obviously serious timeout, does not meet the needs of the 4 ms, and see your program I seem to be inspired somewhat, have what not understand also want to ask you,,,

CodePudding user response:

Vb time response is very slow, the fastest I've seen about 15 ms response time

CodePudding user response:


Conditions are too harsh, not necessarily can meet,

Assumptions and white parity bit, only one stop bits and bytes, with no delay between each byte need 10 bit; Assume your transmission baud rate is 9600 BPS and transmit only 3 bytes, you need to 3.125 milliseconds, plus you receive the response and processing time, is very tight, if multitasking operating system time in milliseconds, you will have a timeout,

CodePudding user response:

Agree to the eighth floor,
Even if the baud rate is great, regardless of the transmission time,
Under the multitasking system is no guarantee of 4 ms can awaken the task,
Is unable to meet this demand, considering the single task of SCM,
  • Related