| |

VerySource

 Forgot password?
 Register
Search
View: 2310|Reply: 11

Questions about serial debugging wizard and VB6

[Copy link]

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-2-20 19:30:02
| Show all posts |Read mode
Serial port settings:
Forced M100 -OFF: 02 30 30 37 31 30 34 36 34 03 39 39
Force M100-ON: 02 30 30 37 30 30 34 36 34 03 39 38
 
It should be noted that H cannot be added after the command and the serial port debugging wizard "Hex Send" should be selected.

This is the command format that I use to send commands to the PLC (programmable controller) using the serial port debugging wizard;
And debug successfully.

Later, I used the MSCOMM control of VB6 as the host computer and sent it using MSCOMM. Somehow, I could not debug.

The VB program is as follows: All other parameters are set correctly.

mscomm1.output = "02 30 30 37 31 30 34 36 34 03 39 39"
or
mscomm1.output = "02&H 30&H 30&H 37&H 31&H 30&H 34&H 36&H 34&H 03&H 39&H 39&H"

I would like to ask you, master, the hex sending in the serial port debugging wizard, how to write with MSCOMM.OUTPUT?












PLC-VB debugging program:
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-7-4 22:45:01
| Show all posts
Generally, the "hexadecimal sending" method of these tools is to convert the ordinary string hexadecimal data (such as 12 34) into high-low bits in decimal bytes (such as 18 52) and then into a byte array Send it again. . .
There are many examples online. . .
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-7-31 10:15:01
| Show all posts
Public Function SendHexDataString() As Boolean
    Dim SendData As String
    Dim buf() As Byte
    Dim m, n, p As Long
    Dim i, j, k As Long, cs
   
    On Error Resume Next

    SendHexDataString = False
    SendData = "029c"
   
    'SendData = strSendData'Trim(Text2.Text) '½«Òª•¢Ë͵Ä&Aumc0;&Aumc0;&Aumc;&Aumc;&Auml0 ;¿Õ¸ñÈ¥³ý£¬²¢Ç&Oedil3;¸¸¸¸¸&cedil
    If frmMain.MSComm1.PortOpen = False Then
        frmMain.MSComm1.PortOpen = True
        'MsgBox "Çë´ò¿ª´®¿Ú", vbOKOnly, "´íÎó"
        'Exit Function
    End If


    If Len(SendData) = 0 Then 'Èç¹ûÎı¾¿òÄÚ&Atiluoyuo;´&Atiluoyue0;0uoe0acute0circle;0uoy0acute0;&
        MsgBox "ÇëÊäÈëÊý¾Ý", vbOKOnly, "´íÎó"
        Exit Function
    End If


    'If Check2.Value = 0 Then 'Èç¹ûûÓÐÑ¡Ô0uouo&uuo160e0circ;&uo16uotil0ecircle0;&uuo16uotilde;&ecircle ;ÖÆ•¢ËÍ
        'p = Len(SendData)
        'ReDim buf(p-1) As Byte
        'For i = 1 To p
        'buf(i-1) = Asc(Mid(SendData, i, 1)) '½«Ã¿¸ö×Ö•ûÒ&Ocirc0;&Ocirc0 #8226;¢ËÍ
        'Next i
    'Else 'Èç¹ûÑ¡ÔñÒÔ16½øÖø&AE0226
        SendData = Replace(SendData, "", "")
        SendData = Replace(SendData, vbCrLf, "")
        p = Len(SendData)\2-1
        ReDim buf(p) As Byte
        For i = 0 To p
            buf(i) = CLng("&H"&Mid(SendData, i * 2 + 1, 2)) 'ÒÔ16½øÖÆÊý•0uoE0l; ;
        Next i
    'End If

    'ͨ¹ý´®¿Ú•¢ËÍÊý¾Ý¾Ý
    frmMain.MSComm1.InputMode = comInputModeBinary
    frmMain.MSComm1.Output = buf()
   
    'Sleep (100)
    'ProcGetData
   
    SendHexDataString = True
   
    Exit Function

'³ö´í´¦Àí
DoErr:
    If Err.Number = 13 Then
        MsgBox "Êý¾Ý¸ñʽ²»¶Ô", vbOKOnly, "´"´"
    Else
        MsgBox Err.Description
    End If
End Function
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-7-31 10:30:01
| Show all posts
The garbled characters are Chinese annotations and do not affect
The first is to send ASCII, the second is to send Hex
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-9 22:45:01
| Show all posts
'**********************************
The hexadecimal number represented by the'character is converted to the corresponding integer
'Return -1 on error
'**********************************

Function ConvertHexChr(str As String) As Integer
   
    Dim test As Integer
   
    test = Asc(str)
    If test >= Asc("0") And test <= Asc("9") Then
        test = test-Asc("0")
    ElseIf test >= Asc("a") And test <= Asc("f") Then
        test = test-Asc("a") + 10
    ElseIf test >= Asc("A") And test <= Asc("F") Then
        test = test-Asc("A") + 10
    Else
        test = -1'error message
    End If
    ConvertHexChr = test
   
End Function


'**********************************
'The hexadecimal data represented by the string is converted into the corresponding byte string
'Return the number of bytes after conversion
'**********************************

Function strHexToByteArray(strText As String, bytByte() As Byte) As Integer
   
    Dim HexData As Integer'Hexadecimal (binary) data byte corresponding value
    Dim hstr As String * 1'High character
    Dim lstr As String * 1'low character
    Dim HighHexData As Integer'High Value
    Dim LowHexData As Integer'low value
    Dim HexDataLen As Integer'Number of bytes
    Dim StringLen As Integer'string length
    Dim Account As Integer'Count
        
    strTestn = ""'Set initial value
    HexDataLen = 0
    strHexToByteArray = 0
   
    StringLen = Len(strText)
    Account = StringLen\2
    ReDim bytByte(Account)
   
    For n = 1 To StringLen
   
        Do'clear spaces
            hstr = Mid(strText, n, 1)
            n = n + 1
            If (n-1)> StringLen Then
                HexDataLen = HexDataLen-1
               
                Exit For
            End If
        Loop While hstr = ""
        
        Do
            lstr = Mid(strText, n, 1)
            n = n + 1
            If (n-1)> StringLen Then
                HexDataLen = HexDataLen-1
               
                Exit For
            End If
        Loop While lstr = ""
        n = n-1
        If n> StringLen Then
            HexDataLen = HexDataLen-1
            Exit For
        End If
        
        HighHexData = ConvertHexChr(hstr)
        LowHexData = ConvertHexChr(lstr)
        
        If HighHexData = -1 Or LowHexData = -1 Then'Interrupt conversion when encountering illegal characters
            HexDataLen = HexDataLen-1
            
            Exit For
        Else
            
            HexData = HighHexData * 16 + LowHexData
            bytByte(HexDataLen) = HexData
            HexDataLen = HexDataLen + 1
            
            
        End If
                        
    Next n
   
    If HexDataLen> 0 Then'Fix the value changed in the last cycle
        HexDataLen = HexDataLen-1
        ReDim Preserve bytByte(HexDataLen)
    Else
        ReDim Preserve bytByte(0)
    End If
   
   
    If StringLen = 0 Then'If it is an empty string, it will not enter the loop body
        strHexToByteArray = 0
    Else
        strHexToByteArray = HexDataLen + 1
    End If
   
   
End Function
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-9 23:00:01
| Show all posts
Send after converting hexadecimal
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-10 13:00:01
| Show all posts
Just use byte arrays, don't have to be complicated.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-13 07:00:01
| Show all posts
Form1.MSComm1.Settings = "9600,n,8,1"

  aa(0) = 2
  aa(1) = 1
  xordata = 0 Xor aa(1)
  aa(2) = change(Text1.Text)
  xordata = xordata Xor aa(2)
  aa(3) = change(Text2(0).Text)
  xordata = xordata Xor aa(3)
  aa(4) = change(Text2(1).Text)
  xordata = xordata Xor aa(4)
  aa(5) = change(Text2(2).Text)
  xordata = xordata Xor aa(5)
  aa(6) = change(Text3(0).Text)
  xordata = xordata Xor aa(6)
  aa(7) = change(Text3(1).Text)
  xordata = xordata Xor aa(7)
  aa(8) = change(Text3(2).Text)
  
  xordata = xordata Xor aa(8)
  
  
  aa(9) = change(Text3(3).Text)
  xordata = xordata Xor aa(9)
  aa(10) = 3
  xordata = xordata Xor aa(10)
  aa(11) = xordata
  aa(12) = 14
  
  

  
  Form1.MSComm1.InputMode = 0
  Form1.MSComm1.Output = aa
Send in hexadecimal, replace the element in aa in the above code with the data you want to send
Reply

Use magic Report

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-8-13 19:45:01
| Show all posts
I was so touched that I saw the help of so many people.

Private Sub Command1_Click()

Dim bdata(1 To 12) As Byte
bdata(1) =&H2
bdata(2) =&H30
bdata(3) =&H30
bdata(4) =&H37
bdata(5) =&H31
bdata(6) =&H30
bdata(7) =&H34
bdata(8) =&H36
bdata(9) =&H34
bdata(10) =&H3
bdata(11) =&H39
bdata(12) =&H39
MSComm1.Output = bdata
End Sub


Private Sub Command2_Click()
Dim bdata(1 To 12) As Byte
bdata(1) =&H2
bdata(2) =&H30
bdata(3) =&H30
bdata(4) =&H37
bdata(5) =&H30
bdata(6) =&H30
bdata(7) =&H34
bdata(8) =&H36
bdata(9) =&H34
bdata(10) =&H3
bdata(11) =&H39
bdata(12) =&H38

MSComm1.Output = bdata
End Sub

Private Sub Command3_Click()
Unload Me
End Sub

Private Sub Form_Load()
MSComm1.PortOpen = True

End Sub



Tested ok
Reply

Use magic Report

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 United States

 Author| Post time: 2020-8-13 20:00:02
| Show all posts
Thank you again, everyone. I do PLC configuration for industrial automation. Computer is my second major.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list