Menu

Retrieving modbus frame

Thomas
2022-03-05
2022-03-10
  • Thomas

    Thomas - 2022-03-05

    Hello,
    Is there any way to get a full modbus frame (RTU) received from slave? I can't find any solution in codesamples or in the forum.
    Anyone can share their code?
    Thanks a lot.

     
  • Thomas

    Thomas - 2022-03-06

    Good morning,

    I am looking for a solution to get full modbus package (not just a value received from the remote device). The best would be to store each byte from the package in the array.
    For now I found a C code in SRE EasyModbusAdvancedClient and converted to the VB.net.

    Seems sendData and receiveData are the arrays w with Modbus packages, but I can't get the value of the specific index.
    For now I change the package to string (as in original code) and use Substring to get exact "byte", but this is not a nice solution:

    Dim s As String = BitConverter.ToString(modbusClient.sendData).Substring(3, 2)
    txtByte.Text = s

    Any better ideas?

     modbusClient = New ModbusClient(cboCOMPort.Text)
     AddHandler modbusClient.ReceiveDataChanged, New EasyModbus.ModbusClient.ReceiveDataChangedHandler(AddressOf UpdateReceiveData)
    AddHandler modbusClient.SendDataChanged, New EasyModbus.ModbusClient.SendDataChangedHandler(AddressOf UpdateSendData)
    
                Delegate Sub UpdateReceiveDataCallback()
    
        Private Sub UpdateReceiveData(ByVal sender As [Object])
            receiveData = "Rx: " & BitConverter.ToString(modbusClient.receiveData).Replace("-", " ") & System.Environment.NewLine
            Dim thread As New Thread(AddressOf updateReceiveTextBox)
            thread.Start()
        End Sub
    
        Private Sub updateReceiveTextBox()
            If TextBox1.InvokeRequired Then
                Dim d As New UpdateReceiveDataCallback(AddressOf updateReceiveTextBox)
                Me.Invoke(d, New [Object]() {})
            Else
                TextBox1.AppendText(receiveData)
            End If
        End Sub
    
    
        Private Sub UpdateSendData(ByVal sender As [Object])
            'sendData = "Tx: " & BitConverter.ToString(modbusClient.sendData).Replace("-", " ") & System.Environment.NewLine
            sendData = BitConverter.ToString(modbusClient.sendData)
            Dim thread As New Thread(AddressOf updateSendTextBox)
            thread.Start()
    
        End Sub
    
        Private Sub updateSendTextBox()
            If TextBox1.InvokeRequired Then
                Dim d As New UpdateReceiveDataCallback(AddressOf updateSendTextBox)
                Me.Invoke(d, New [Object]() {})
            Else
                TextBox1.AppendText(sendData)
            End If
        End Sub
    
     
    • Nikoloz Qvrivishvili

      Good morning!

      Please have a look at:  https://control.com/forums/threads/homebrewed-software-to-communicate-with-measuring-device-via-modbus-tcp.49152/page-2

      The matters you’re interrogating right over there.
      N. Qv.

      Воскресенье, 6 марта 2022, 13:58 +04:00 от Thomas ztomaj@users.sourceforge.net:

      Good morning,
      I am looking for a solution to get full modbus package (not just a value received from the remote device). The best would be to store each byte from the package in the array.
      For now I found a C code in SRE EasyModbusAdvancedClient and converted to the VB.net.
      Seems sendData and receiveData are the arrays w with Modbus packages, but I can't get the value of the specific index.
      For now I change the package to string (as in original code) and use Substring to get exact "byte", but this is not a nice solution:
      Dim s As String = BitConverter.ToString(modbusClient.sendData).Substring(3, 2)
      txtByte.Text = s
      Any better ideas?
      modbusClient = New ModbusClient(cboCOMPort.Text)
      AddHandler modbusClient.ReceiveDataChanged, New EasyModbus.ModbusClient.ReceiveDataChangedHandler(AddressOf UpdateReceiveData)
      AddHandler modbusClient.SendDataChanged, New EasyModbus.ModbusClient.SendDataChangedHandler(AddressOf UpdateSendData)

             Delegate Sub UpdateReceiveDataCallback()
      

      Private Sub UpdateReceiveData(ByVal sender As [Object])
      receiveData = "Rx: " & BitConverter.ToString(modbusClient.receiveData).Replace("-", " ") & System.Environment.NewLine
      Dim thread As New Thread(AddressOf updateReceiveTextBox)
      thread.Start()
      End Sub

      Private Sub updateReceiveTextBox()
      If TextBox1.InvokeRequired Then
      Dim d As New UpdateReceiveDataCallback(AddressOf updateReceiveTextBox)
      Me.Invoke(d, New Object {})
      Else
      TextBox1.AppendText(receiveData)
      End If
      End Sub

      Private Sub UpdateSendData(ByVal sender As [Object])
      'sendData = "Tx: " & BitConverter.ToString(modbusClient.sendData).Replace("-", " ") & System.Environment.NewLine
      sendData = BitConverter.ToString(modbusClient.sendData)
      Dim thread As New Thread(AddressOf updateSendTextBox)
      thread.Start()

      End Sub

      Private Sub updateSendTextBox()
      If TextBox1.InvokeRequired Then
      Dim d As New UpdateReceiveDataCallback(AddressOf updateSendTextBox)
      Me.Invoke(d, New Object {})
      Else
      TextBox1.AppendText(sendData)
      End If
      End Sub


      Retrieving modbus frame

      Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/easymodbustcp/discussion/general/
      To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

      --
      Николоз Квривишвили
      Отправлено из Почты Mail.ru

       

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.