Private Sub lblDisplaySpeed_Click()
lblDisplaySpeed.Caption = "发送速率为:" & 9600 & "波特率"
Dim i%, Buf$
Buf = ""
InByte = MSComm1.Input
For i = LBound(InByte) To UBound(InByte)
Buf = Buf + InByte(i)
IF InByte(i) = 0x00 THEN
  Timer1.Interval = 50
  Timer1.Enabled = True
  REPEAT
 UNTIL (Timer1 > 50  OR New Byte Received)
      Case 1 To 4:   lblDisplaySpeed.Caption = "发送速率为:" & 600 & "波特率"
      Case 5 To 10:  lblDisplaySpeed.Caption = "发送速率为:" & 300 & "波特率"
      Case 11 To 15: lblDisplaySpeed.Caption = "发送速率为:" & 150 & "波特率"
      Case 16 To 22: lblDisplaySpeed.Caption = "发送速率为:" & 110 & "波特率"
      Case 23 To 32: lblDisplaySpeed.Caption = "发送速率为:" & 75 & "波特率"
      Case 33 To 49: lblDisplaySpeed.Caption = "发送速率为:" & 50 & "波特率"
    Else: END CASE;
Else IF InByte(i) >= 0xF1 THEN
    lblDisplaySpeed.Caption = "发送速率为:" & 19200 & "波特率"
Else
 CASE Byte IN
0 x0D:        9600
0 xE6:        4800
0 x78:        2400
0xE0,0xF0: 1800
0 x80:        1200
    ELSE: Line noise; reset
  END CASE
END IF■End Sub这是我看到一篇文章上的 但是不知道哪里有错误。

解决方案 »

  1.   

    大大 我是搞不懂它是什么意思
    原来书上是这样说的各种波特率都可以通过回车符的发送和接收信息来测定,算法实现的伪 代码在本文的最后给出。应用实践证明了这种方法的有效性。
    ; Pseudo code to determine what baud rate a transmitter is at,on the b asis of a single; RETURN (0x0D) character received from it.Initialise receive baud rate to 9600
    Wait for Byte to be received
    IF Byte = 0x00 THEN
       Start Timer
       REPEAT
       UNTIL (Timer > 50 ms OR New Byte Received)
       CASE Timer IN
        1 ms-4 ms: 600 Baud
        5 ms-10 ms: 300 Baud
          11 ms-15 ms: 150 Baud
          16 ms-22 ms: 110 Baud
          23 ms-32 ms: 75 Baud
          33 ms-49 ms: 50 Baud
           ELSE: Timed out; reset
      END CASE;
    ELSIF Byte >= 0xF1 THEN
       19200 Baud
    ELSE
      CASE Byte IN
        0x0D: 9600 Baud
        0xE6: 4800 Baud
        0x78: 2400 Baud
      0xE0,0xF0: 1800 Baud
        0x80: 1200 Baud
        ELSE: Line noise; reset
      END CASE
    END IF■
    这个Byte是什么类型呢?如果你测试出来了 
    能不能给个解释 谢谢!