AdvancedHMI Software
General Category => Support Questions => Topic started by: oqapsking 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
-
Maybe try this: https://www.advancedhmi.com/forum/index.php?topic=1086.0
-
i did not understand his method
-
archie has this code inside the controls
#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?
-
i think this code will work
but how to define the plc address in it ?
#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
-
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:
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
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.
-
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):
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:
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
-
here is a simpler one:
same, firstly create a button for indication.
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
-
Would the ConnectionEstablished and ConnectionClosed events simplify this, or am I misunderstanding the OP's question?
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
-
yes, that's the exact one.