第一条帧格式:FE FE A1 10 XX XX YY YY KK.....LL 17
XX:发送数据长度      YY: 数据长度     KK:要发送的报文长度       ......:数据(被套的报文)  LL:校验码XX是以字为单位     
其他都是一字节为单位第二条帧格式:68 99 99 99 99 99 99 68 08 0D 00 00 11 48 4E 45 16 80 33 33 17 80 33 33 1A 16
如何将第2条报文放进第一条报文里??要计算三个数据长度,计算校验码!谢谢!尽量详细点!

解决方案 »

  1.   

    描述不清楚:
    1)XX XX 共2字节?
    2)YY YY 指哪个数据长度?
    3)XX XX 是指发送数据帧长度?
      

  2.   

    第一条帧有点不好理解.XX是2字节,YY是2字节.有高低位XX是以字为单位的,YY是以字节为单位的,其实他们指的是同一条报文的长度,比如:XX=13字那么YY=26字节.至于这个报文的长度就是:
    后面报文长度2字节 00 1A+68 99 99 99 99 99 99 68 08 0D 00 00 11 48 4E 45 16 80 33 33 17 80 33 33 1A 16 
    就是28个字节,14个字,也就是XX XX=00 0E,  YY YY=00 1C   
    如果这个报文是奇数的,就在其后面添加FE.一起放到第一条帧里!!如果是偶数的就不用加!检验和就是,第2条报文加进去以后,计算第一条报文校验和.
      

  3.   

    Option Explicit
        Dim sj1 As String
        Dim sjsend() As Byte
        Dim i As Integer
        Dim jyh As Integer
    Private Sub Command1_Click()
        Text3 = Right("0" & Hex(Len(sj1) / 2), 2)
        sj1 = "FEFEA110" & Right("000" & Hex(Len(sj1)), 4) & Right("000" & Hex(Len(sj1) / 2), 4) & sj1
        Text5 = sj1
        ReDim sjsend(Len(sj1) / 2 + 1)
        For i = 1 To Len(sj1) Step 2
            sjsend((i - 1) / 2) = Val("&H" & Mid(sj1, i, 2))
        Next
        For i = 0 To UBound(sjsend) - 2
            jyh = jyh + sjsend(i)
        Next
        sjsend(UBound(sjsend) - 1) = jyh Mod 256
        sjsend(UBound(sjsend)) = &H17
        MSComm1.Output = sjsend
    End SubPrivate Sub Form_Load()
        sj1 = "6899999999999968080D000011484E4516803333178033331A16"
        MSComm1.Settings = "9600,n,8,1"
        MSComm1.PortOpen = True
    End Sub
      

  4.   

    Option Explicit
        Dim sj1 As String
        Dim sj As String
        Dim sjsend() As Byte
        Dim i As Integer
        Dim jyh As Integer
    Private Sub Command1_Click()
        sj1 = "FEFEA110" & Right("000" & Hex(Len(sj) + 24), 4) & _
        Right("000" & Hex((Len(sj) + 24) / 2), 4) & _
        Right("000" & Hex(Len(sj) / 2), 4) & sj
        ReDim sjsend(Len(sj1) / 2 + 1)
        For i = 1 To Len(sj1) Step 2
            sjsend((i - 1) / 2) = Val("&H" & Mid(sj1, i, 2))
        Next
        For i = 0 To UBound(sjsend) - 2
            jyh = jyh + sjsend(i)
        Next
        sjsend(UBound(sjsend) - 1) = jyh Mod 256
        sjsend(UBound(sjsend)) = &H17
        MSComm1.Output = sjsend
    End SubPrivate Sub Form_Load()
        sj = "6899999999999968080D000011484E4516803333178033331A16"
        MSComm1.Settings = "9600,n,8,1"
        MSComm1.PortOpen = True
    End Sub
      

  5.   

    Option Explicit
        Dim sj1 As String
        Dim sj As String
        Dim sjsend() As Byte
        Dim i As Integer
        Dim jyh As Integer
    Private Sub Command1_Click()
        sj1 = "FEFEA110" & Right("000" & Hex(Len(sj) + 24), 4) & _
        Right("000" & Hex((Len(sj) + 24) / 2), 4) & _
        Right("000" & Hex(Len(sj) / 2), 4) & sj
        Text2 = sj1
        ReDim sjsend(Len(sj1) / 2 + 1)
        For i = 1 To Len(sj1) Step 2
            sjsend((i - 1) / 2) = Val("&H" & Mid(sj1, i, 2))
        Next
        For i = 0 To UBound(sjsend) - 2
            jyh = jyh + sjsend(i)
        Next
        sjsend(UBound(sjsend) - 1) = jyh Mod 256
        sjsend(UBound(sjsend)) = &H17
        MSComm1.Output = sjsend
    End SubPrivate Sub Form_Load()
        sj = "6899999999999968080D000011484E4516803333178033331A16"
        If Len(sj) / 2 Mod 2 <> 0 Then
            sj = sj & "FE"
        End If
        MSComm1.Settings = "9600,n,8,1"
        MSComm1.PortOpen = True
    End Sub