Author Topic: how to test the communication between plc and pc  (Read 1932 times)

oqapsking

  • Full Member
  • ***
  • Posts: 178
    • View Profile
how to test the communication between plc and pc
« on: February 08, 2020, 05:00:20 PM »
hello

as in the title how to test the communication between plc and pc

what i need to do is to test the communication between plc and pc using the modbus tcp com
i usually use the bing test
but i wanna use something that constantly shows the communication status

with thanks

Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile

oqapsking

  • Full Member
  • ***
  • Posts: 178
    • View Profile
Re: how to test the communication between plc and pc
« Reply #2 on: February 09, 2020, 07:22:03 AM »
i did not understand his method

oqapsking

  • Full Member
  • ***
  • Posts: 178
    • View Profile
Re: how to test the communication between plc and pc
« Reply #3 on: February 09, 2020, 07:28:21 AM »
archie has this code inside the controls

Code: [Select]
#Region "Error Display"
    Private Sub DisplaySubscribeError(ByVal sender As Object, ByVal e As MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs)
        DisplayError(e.ErrorMessage)
    End Sub

    '********************************************************
    '* Show an error via the text property for a short time
    '********************************************************
    Private WithEvents ErrorDisplayTime As System.Windows.Forms.Timer
    Private Sub DisplayError(ByVal ErrorMessage As String)
        If Not m_SuppressErrorDisplay Then
            If ErrorDisplayTime Is Nothing Then
                ErrorDisplayTime = New System.Windows.Forms.Timer
                AddHandler ErrorDisplayTime.Tick, AddressOf ErrorDisplay_Tick
                ErrorDisplayTime.Interval = 5000
            End If

            '* Save the text to return to
            If Not ErrorDisplayTime.Enabled Then
                OriginalText = Me.Text
            End If

            ErrorDisplayTime.Enabled = True

            MyBase.Text = ErrorMessage
        End If
    End Sub


    '**************************************************************************************
    '* Return the text back to its original after displaying the error for a few seconds.
    '**************************************************************************************
    Private Sub ErrorDisplay_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ErrorDisplayTime.Tick
        Text = OriginalText

        If ErrorDisplayTime IsNot Nothing Then
            ErrorDisplayTime.Enabled = False
            ErrorDisplayTime.Dispose()
            ErrorDisplayTime = Nothing
        End If
    End Sub
#End Region

is it possible to use it ? and how?

oqapsking

  • Full Member
  • ***
  • Posts: 178
    • View Profile
Re: how to test the communication between plc and pc
« Reply #4 on: February 09, 2020, 07:52:43 AM »
i think this code will work
but how to define the plc address in it ?

Code: [Select]
#Region "Error Display"
    Private m_SuppressErrorDisplay As Boolean
    <System.ComponentModel.DefaultValue(False)>
    Public Property SuppressErrorDisplay As Boolean
        Get
            Return m_SuppressErrorDisplay
        End Get
        Set(value As Boolean)
            m_SuppressErrorDisplay = value
        End Set
    End Property
    Private Sub DisplaySubscribeError(ByVal sender As Object, ByVal e As MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs)
        DisplayError(e.ErrorMessage)
    End Sub

    '********************************************************
    '* Show an error via the text property for a short time
    '********************************************************
    Private WithEvents ErrorDisplayTime As System.Windows.Forms.Timer
    Private Sub DisplayError(ByVal ErrorMessage As String)
        If Not m_SuppressErrorDisplay Then
            If ErrorDisplayTime Is Nothing Then
                ErrorDisplayTime = New System.Windows.Forms.Timer
                AddHandler ErrorDisplayTime.Tick, AddressOf ErrorDisplay_Tick
                ErrorDisplayTime.Interval = 5000
            End If

            '* Save the text to return to
            If Not ErrorDisplayTime.Enabled Then
                _0000_1st_Parent.lbl_Header_Alarm.Text = Me.Text
            End If

            ErrorDisplayTime.Enabled = True

            MyBase.Text = ErrorMessage
        End If
    End Sub


    '**************************************************************************************
    '* Return the text back to its original after displaying the error for a few seconds.
    '**************************************************************************************
    Private Sub ErrorDisplay_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ErrorDisplayTime.Tick
        Text = _0000_1st_Parent.lbl_Header_Alarm.Text

        If ErrorDisplayTime IsNot Nothing Then
            ErrorDisplayTime.Enabled = False
            ErrorDisplayTime.Dispose()
            ErrorDisplayTime = Nothing
        End If

Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
Re: how to test the communication between plc and pc
« Reply #5 on: February 09, 2020, 06:51:42 PM »
i did not understand his method

This is modified version of the idea MrPike suggested:

- Add a BasicLabel to the form
   - Set its Name property to "CommLossBasicLabel"
   - Set its AutoSize property to False
   - Set its Size property to approximately (104, 18)
   - Set its PLCAddressValue property to available integer register address, ex. 40001

- Add a timer to the form
   - Set its Name property to "CommLossTimer"
   - Set its Interval property to 500

Don't make any other changes to these 2 controls since you would be using them for comm loss indication only.

Then add either version of the following code, run the app and test it by disconnecting the slave:

Code: [Select]
    Private Sub CommLossTimer_Tick(sender As Object, e As EventArgs) Handles CommLossTimer.Tick
        If CommLossBasicLabel.BackColor = Color.Black Then
            CommLossBasicLabel.BackColor = Color.Red
        Else
            CommLossBasicLabel.BackColor = Color.Black
        End If
    End Sub

    Private Sub CommLossBasicLabel_TextChanged(sender As Object, e As EventArgs) Handles CommLossBasicLabel.TextChanged
        If CommLossBasicLabel.Text = "BasicLabel" Then Exit Sub 'First Run

        Dim dummy As Integer
        If Integer.TryParse(CommLossBasicLabel.Text, dummy) Then
            CommLossTimer.Enabled = False
            CommLossBasicLabel.BackColor = Color.Black
        Else
            CommLossTimer.Enabled = True
            CommLossBasicLabel.Value = "Disconnected"
        End If
    End Sub

Code: [Select]
    Private Sub CommLossTimer_Tick(sender As Object, e As EventArgs) Handles CommLossTimer.Tick
        CommLossBasicLabel.Highlight = Not CommLossBasicLabel.Highlight
    End Sub

    Private Sub CommLossBasicLabel_TextChanged(sender As Object, e As EventArgs) Handles CommLossBasicLabel.TextChanged
        If CommLossBasicLabel.Text = "BasicLabel" Then Exit Sub 'First Run

        Dim dummy As Integer
        If Integer.TryParse(CommLossBasicLabel.Text, dummy) Then
            CommLossTimer.Enabled = False
            CommLossBasicLabel.Highlight = False
        Else
            CommLossTimer.Enabled = True
            CommLossBasicLabel.Value = "Disconnected"
        End If
    End Sub

Your other suggestions don't appear to be viable options.

« Last Edit: February 09, 2020, 07:31:56 PM by Godra »

joko markono

  • Full Member
  • ***
  • Posts: 132
    • View Profile
Re: how to test the communication between plc and pc
« Reply #6 on: March 11, 2020, 05:43:27 AM »
Here's another option to try.
i tried this method which is 100% working on OmronSerialHostlink driver.

First i created a button (from Visual Basic standard button, not from the AHMI) to show the comm status.
Then i picked up any address from the control on the form (in this case is D2087):
Code: [Select]
Private Sub MainForm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            Me.OmronSerialHostLinkCom1.Subscribe("D2087", 1, 250, AddressOf OmronSerialHostLinkCom1_SubscribedDataReceived)
End Sub

Then the following code:
Code: [Select]
Private Sub OmronSerialHostLinkCom1_SubscribedDataReceived(sender As Object, e As Drivers.Common.PlcComEventArgs)
                If e.PlcAddress = "D2087" Then
            If e.ErrorMessage = "Error End Code=0x000F" Then
                SurfaceComButton.BackColor = Color.Red
                SurfaceComButton.Text = "NO TELEMETRY"
            Else SurfaceComButton.BackColor = Color.Lime
                SurfaceComButton.Text = "TELEMETRY OK"
            End If
        End If
    End Sub
« Last Edit: March 11, 2020, 05:51:38 AM by joko markono »

joko markono

  • Full Member
  • ***
  • Posts: 132
    • View Profile
Re: how to test the communication between plc and pc
« Reply #7 on: March 12, 2020, 01:31:42 AM »
here is a simpler one:
same, firstly create a button for indication.
Code: [Select]
Private Sub OmronSerialHostLinkCom1_SubscribedDataReceived(sender As Object, e As Drivers.Common.PlcComEventArgs)
       
       'SCU COMM LOSS INDICATION

        If e.Values.Count <= 0 Then
            SurfaceComButton.BackColor = Color.Red
            SurfaceComButton.Text = "NO TELEMETRY"
        Else SurfaceComButton.BackColor = Color.Lime
                SurfaceComButton.Text = "TELEMETRY OK"
        End If

End Sub

billerl

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: how to test the communication between plc and pc
« Reply #8 on: March 12, 2020, 12:56:09 PM »
Would the ConnectionEstablished and ConnectionClosed events simplify this, or am I misunderstanding the OP's question?

Code: [Select]
    Private Sub ModbusTCPCom1_ConnectionEstablished(sender As Object, e As EventArgs) Handles ModbusTCPCom1.ConnectionEstablished
        LabelDebug.Text = "Connection at " & vbNewLine & ModbusTCPCom1.IPAddress & " Established"
        LabelDebug.ForeColor = Color.Lime
    End Sub

    Private Sub ModbusTCPCom1_ConnectionClosed(sender As Object, e As EventArgs) Handles ModbusTCPCom1.ConnectionClosed
        LabelDebug.Text = "Connection at " & vbNewLine & ModbusTCPCom1.IPAddress & " Closed"
        LabelDebug.ForeColor = Color.Red
    End Sub

joko markono

  • Full Member
  • ***
  • Posts: 132
    • View Profile
Re: how to test the communication between plc and pc
« Reply #9 on: March 13, 2020, 03:58:16 AM »
yes, that's the exact one.