综合

img aj025

紧急求教

发表于2004/10/29 12:29:00  349人阅读

我用VB6做了一个和某个装置进行串口通讯的界面,装置用的是80C196KC的单片机,现在的问题是单片机能收到我的命令,可是我却收不到它的数据,这是为什么呀??下面是我的发送程序
Private Sub Command1_Click(Index As Integer)
MSComm2.OutBufferCount = 0
MSComm2.InBufferCount = 0

Dim send_node(8) As Byte
If MSComm2.PortOpen Then MSComm2.PortOpen = False
Dim d() As Byte
Dim crc() As Byte

For Ind = 0 To 3
If Form2.Option1(Ind) = True Then
  MSComm2.CommPort = Ind + 1
End If
Next Ind


MSComm2.RThreshold = 1
MSComm2.PortOpen = True


Select Case Index
  Case 0
   
    ReDim d(5) As Byte
    ReDim crc(1) As Byte
    d(0) = 0
    d(1) = 6
    d(2) = 0
    d(3) = 0
    d(4) = (Hex((Text3(7).Text)) Or &HFF00) / 256
    d(5) = Hex((Text3(7).Text)) Or &HFF
    crc = CRC16(d)

    send_node(0) = 0
    send_node(1) = 0
    send_node(2) = 6
    send_node(3) = 0
    send_node(4) = 0
    send_node(5) = (Hex((Text3(7).Text)) Or &HFF00) / 256
   
    send_node(6) = Hex((Text3(7).Text)) Or &HFF
    send_node(7) = crc(1)
    send_node(8) = crc(0)

  
    MSComm2.Output = send_node
        
  Case 2
   
    ReDim d(5) As Byte
    ReDim crc(1) As Byte
   
   
    d(0) = Val(Text3(7).Text)
    d(1) = 3
    d(2) = 0
    d(3) = 0
    d(4) = 0
    d(5) = 36
   
    crc = CRC16(d)

    send_node(0) = 0
    send_node(1) = Val(Text3(7).Text)
    send_node(2) = 3
    send_node(3) = 0
    send_node(4) = 0
    send_node(5) = 0
    send_node(6) = 36
    send_node(7) = crc(1)
    send_node(8) = crc(0)

    MSComm2.Output = send_node
   
End Select
End Sub

MSComm2的其它参数我在属性窗口中设置了,另外我把串口的2,3脚短接,进行自发自收时,一切都是正常的。谢谢

阅读全文
0 0

相关文章推荐

img
取 消
img