Private NotificationIDVisibility As String
Private Sub SubscribeToCommDriver()
'*************************
'* Visbility Subscription
'*************************
NotificationIDVisibility = _CommComponent.Subscribe(m_PLCaddressVisibility, 250, AddressOf PolledDataReturnedVisibility)
End Sub
Private Sub PolledDataReturnedVisibility(ByVal Values() As String)
Try
MyBase.Visible = Values(0)
Catch
DisplayError("INVALID Visibilty VALUE RETURNED!")
End Try
End Sub
FYI: The next release that will be posted on Monday has the code that is much easier for understanding the subscribe process.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks Archie,
I'm not following what you're doing here, how would I read the value of address "B3:0/0" for instance?
I've downloaded the new HMI release and will have a look at that also, where's the best place to start in that for this?
Thanks,
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
'* Save the reference number returned to be used for unsubscribing
Private NotificationID As String
Private Sub SubscribeToCommDriver()
'* Subscribe to B3:0/0 , update every 250ms, return data to Sub PolledDataReturned
NotificationID = DF1Comm1.Subscribe("B3:0/0", 250, AddressOf PolledDataReturned)
End Sub
Private Sub PolledDataReturned(ByVal Values() As String)
'* Show the returned value in a label
Label1.Text = Values(0)
End Sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There are several tutorials on Youtube for using AdvancedHMI. The new release contains a file QuickStart.pdf
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2011-06-14
I am unsure as to the benefit of subscribing… what does this actually do? In the few projects I have been playing around with AdvancedHMI, I just set the controls up to read an address and it works. I have used this method on N addresses as well as bits… so I don't see what subscribing offers.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Subscribing is primarily intended for the components. But it does have the advantage in some drivers that it will optimize the reading of data by grouping multiple subscription if it can, then perform a single read.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks Archie, I still haven't got it working though! I tried your last code, but nothing happened, so i put a timer in and called the 'SubscribetoCommDriver' method, but when it tried i got an error saying something like invalid command.
The reason i want to subscribe is i have a form with lots of tags and when it runs, it is slow to respond to the buttons on the form because the readany commands take a little while to execute. I presume the subscribe will overcome this?…
By the way, when i opened up the quick start guide in the new version of HMI, there was nothing in the pdf.
Thanks,
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
On the form with a lot of tags, are you using the BasicLabel control or any of the other contols? Those controls take care of handling all of the subscribing.
Otherwise you want to perform your reads asynchronously. Set the AsyncMode property to true and create an event handler for DataReceived event. Subscribing also happens asynchronously.
You can download the DF1Comm project on sourceforge to see examples of how to read synchronously.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm not using any controls, only read-any methods, as my boss wants it to look like our old scada system, so, the bits are compared and then pictureboxes load in images accordingly.
i can't find the df1comm project on this site?
I tried adding the datareceived event from the ethernet driver events list, and changed asyncmode to true, i then tried a readany but still no joy - i must be going wrong again!
thanks for all the help so far.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry, my mistake. I thought the version posted was the latest release. This is the code form the latest version:
Private Sub btnRead1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRead1.Click
Try
'* Set it to Async read
'* An asynchronous read will return before the data is back from the PLC
'* The data will be returned in a DataRecevied event
'* This keeps the form from hanging while waiting on data from the PLC
DF1Comm1.AsyncMode = True
'* Perform the read
DF1Comm1.ReadAny(txtAddress1.Text)
DF1Comm1.AsyncMode = False
ResultError.Text = "Successful Read"
Catch ex As Exception
'* show any errors in status bar
ResultError.Text = ex.Message
End Try
End Sub
'******************************************************
'* This is the callback when Async data is received
'******************************************************
Private Sub DF1Comm1_DataReceived(ByVal sender As Object, ByVal e As DF1CommEventArgs) Handles DF1Comm1.DataReceived
If e.PLCAddress = txtAddress1.Text Then lblRead1Result.Text = e.Values(0)
End Sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
That code should work with all versions. There were no changes in that part, to my knowledge. The biggest change between the prior and latest release is the subscribing call.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have almost got this working. But when I do more than two ReadAnys i dont get the data. Here is my code as to what i'm up to:
Timer interval is 100
Public Class MainForm
Private Tank36Level As Double
Private Tank37Level As Double
Private Tank38Level As Double
Private Tank39Level As Double
Private Tank40Level As Double
End Sub
'
Private Sub EthernetIPforSLCMicro1_DataReceived(ByVal sender As System.Object, ByVal e As AdvancedHMI.PLCCommEventArgs) Handles EthernetIPforSLCMicro1.DataReceived
If e.PLCAddress = "F25:40" Then Tank36Level = e.Values(0)
If e.PLCAddress = "F25:43" Then Tank37Level = e.Values(0)
If e.PLCAddress = "F25:46" Then Tank38Level = e.Values(0)
If e.PLCAddress = "F25:49" Then Tank39Level = e.Values(0)
If e.PLCAddress = "F25:52" Then Tank40Level = e.Values(0)
End Sub
End Class
Thanks,
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Public Class MainForm
Private Tank36Level As Double
Private Tank37Level As Double
Private Tank38Level As Double
Private Tank39Level As Double
Private Tank40Level As Double
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
' Get Tank levels
EthernetIPforSLCMicro1.AsyncMode = True
EthernetIPforSLCMicro1.ReadAny("F25:40",13)
EthernetIPforSLCMicro1.AsyncMode = False
End Sub
'
Private Sub EthernetIPforSLCMicro1_DataReceived(ByVal sender As System.Object, ByVal e As AdvancedHMI.PLCCommEventArgs) Handles EthernetIPforSLCMicro1.DataReceived
If e.PLCAddress = "F25:40" Then
Tank36Level = e.Values(0)
Tank37Level = e.Values(3)
Tank38Level = e.Values(6)
Tank39Level = e.Values(9)
Tank40Level = e.Values(12)
Archie,
Yes the method you provide works well when reading the F25 register, but I am also reading a B30 register with multiple ReadAnys still makes the program slow to respond to button clicks. I think I need to subscribe to these, as i can't asyncRead individual bits in the B30 reg.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Unless t here is an issue in the driver, it should let you do an Async read on bits. If that doesn't work, you can try it like this:
Private MyBit0 As Boolean
Private MyBit1 As Boolean
Private MyBit2 As Boolean
Private MyBit3 As Boolean
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
' Get Tank levels
EthernetIPforSLCMicro1.AsyncMode = True
EthernetIPforSLCMicro1.ReadAny("B30:0")
EthernetIPforSLCMicro1.AsyncMode = False
End Sub
'
Private Sub EthernetIPforSLCMicro1_DataReceived(ByVal sender As System.Object, ByVal e As AdvancedHMI.PLCCommEventArgs) Handles EthernetIPforSLCMicro1.DataReceived
If e.PLCAddress = "B30:0" Then
MyBit0 = ((e.Values(0) and 1)>0)
MyBit1 = ((e.Values(0) and 2)>0)
MyBit2 = ((e.Values(0) and 4)>0)
MyBit3 = ((e.Values(0) and 8)>0)
end if
End Sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Again, that's fine when reading two file registers, but trying three or more, it seems to choose only two of them. I'm enabling and re-enabling the asyncmode with each Read. Any more ideas? Thanks for all the help with this. :)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Not sure why that doesn't work, but this is a method that I have used when polling multiple addresses:
Private NextAddressToRead as String="B30:0"
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
' Get Tank levels
EthernetIPforSLCMicro1.AsyncMode = True
EthernetIPforSLCMicro1.ReadAny(NextAddressToRead)
End Sub
'
Private Sub EthernetIPforSLCMicro1_DataReceived(ByVal sender As System.Object, ByVal e As AdvancedHMI.PLCCommEventArgs) Handles EthernetIPforSLCMicro1.DataReceived
If e.PLCAddress = "B30:0" Then
MyBit0 = ((e.Values(0) and 1)>0)
MyBit1 = ((e.Values(0) and 2)>0)
MyBit2 = ((e.Values(0) and 4)>0)
MyBit3 = ((e.Values(0) and 8)>0)
NextAddressToRead="F25:40"
end if
If e.PLCAddress = "F25:40" then
.
.
.
NextAddressToRead="B30:0"
End if
End Sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Right, I've got it work in the new version of AdvancedHMIv3, but, it doesn't seem any more responsive than doing the synchronous method! The main problem for me is that i have a button on the form that is slow to respond to clicks. Would the subscribe method improve upon this? Would the subscribe method you mentioned in point 4 work for the latest HMIv3? thanks,
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Archie, I've got it working perfectly now with the subscribe command! I'm using the main form load event to initiate all of the subscribes and then using the polleddatareturned events to update my variables. I might go down the road of making up my own components to make building a bit quicker. thanks for all the help!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2011-06-21
That's good that you got it working… I was going to say that in my latest test project I have a main form with several popup forms. The main form is an overall plant layout, with status indicators for each motor in the plant. Clicking on any one of them brings up a small popup where the operator can do start/stop set speed, etc. I noticed a lot of problems using several forms, but this is all on DF1. I never did use the subscribe methods, but what I did to work around it all was when each popup loads, I set the DF1Comm of each component of the popup to the DF1 that's on the main form. This way, all comms are going through one iteration of the driver instead of multiple ones. That, in conjunction with setting the DF1 on the main form to ASYNCH seemed to make things run pretty smoothly.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
Has anyobody managed to use the subscribe method? I can' t figure it out!
Thanks,
aaron.
Private NotificationIDVisibility As String
Private Sub SubscribeToCommDriver()
'*************************
'* Visbility Subscription
'*************************
NotificationIDVisibility = _CommComponent.Subscribe(m_PLCaddressVisibility, 250, AddressOf PolledDataReturnedVisibility)
End Sub
Private Sub PolledDataReturnedVisibility(ByVal Values() As String)
Try
MyBase.Visible = Values(0)
Catch
DisplayError("INVALID Visibilty VALUE RETURNED!")
End Try
End Sub
FYI: The next release that will be posted on Monday has the code that is much easier for understanding the subscribe process.
Thanks Archie,
I'm not following what you're doing here, how would I read the value of address "B3:0/0" for instance?
I've downloaded the new HMI release and will have a look at that also, where's the best place to start in that for this?
Thanks,
'* Save the reference number returned to be used for unsubscribing
Private NotificationID As String
Private Sub SubscribeToCommDriver()
'* Subscribe to B3:0/0 , update every 250ms, return data to Sub PolledDataReturned
NotificationID = DF1Comm1.Subscribe("B3:0/0", 250, AddressOf PolledDataReturned)
End Sub
Private Sub PolledDataReturned(ByVal Values() As String)
'* Show the returned value in a label
Label1.Text = Values(0)
End Sub
There are several tutorials on Youtube for using AdvancedHMI. The new release contains a file QuickStart.pdf
I am unsure as to the benefit of subscribing… what does this actually do? In the few projects I have been playing around with AdvancedHMI, I just set the controls up to read an address and it works. I have used this method on N addresses as well as bits… so I don't see what subscribing offers.
Subscribing is primarily intended for the components. But it does have the advantage in some drivers that it will optimize the reading of data by grouping multiple subscription if it can, then perform a single read.
Thanks Archie, I still haven't got it working though! I tried your last code, but nothing happened, so i put a timer in and called the 'SubscribetoCommDriver' method, but when it tried i got an error saying something like invalid command.
The reason i want to subscribe is i have a form with lots of tags and when it runs, it is slow to respond to the buttons on the form because the readany commands take a little while to execute. I presume the subscribe will overcome this?…
By the way, when i opened up the quick start guide in the new version of HMI, there was nothing in the pdf.
Thanks,
On the form with a lot of tags, are you using the BasicLabel control or any of the other contols? Those controls take care of handling all of the subscribing.
Otherwise you want to perform your reads asynchronously. Set the AsyncMode property to true and create an event handler for DataReceived event. Subscribing also happens asynchronously.
You can download the DF1Comm project on sourceforge to see examples of how to read synchronously.
I'm not using any controls, only read-any methods, as my boss wants it to look like our old scada system, so, the bits are compared and then pictureboxes load in images accordingly.
i can't find the df1comm project on this site?
I tried adding the datareceived event from the ethernet driver events list, and changed asyncmode to true, i then tried a readany but still no joy - i must be going wrong again!
thanks for all the help so far.
i found the df1comm project, i'll have a look, but please, any tips are welcomed!
I had a look through the DF1Comm project, and saw that the driver was set ASyncMode = False, and no 'DataReceived' method used. Help please!
Sorry, my mistake. I thought the version posted was the latest release. This is the code form the latest version:
Private Sub btnRead1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRead1.Click
Try
'* Set it to Async read
'* An asynchronous read will return before the data is back from the PLC
'* The data will be returned in a DataRecevied event
'* This keeps the form from hanging while waiting on data from the PLC
DF1Comm1.AsyncMode = True
'* Perform the read
DF1Comm1.ReadAny(txtAddress1.Text)
DF1Comm1.AsyncMode = False
ResultError.Text = "Successful Read"
Catch ex As Exception
'* show any errors in status bar
ResultError.Text = ex.Message
End Try
End Sub
'******************************************************
'* This is the callback when Async data is received
'******************************************************
Private Sub DF1Comm1_DataReceived(ByVal sender As Object, ByVal e As DF1CommEventArgs) Handles DF1Comm1.DataReceived
If e.PLCAddress = txtAddress1.Text Then lblRead1Result.Text = e.Values(0)
End Sub
Does this code work with the previous version of ADVHMI?
That code should work with all versions. There were no changes in that part, to my knowledge. The biggest change between the prior and latest release is the subscribing call.
Hi Archie,
I have almost got this working. But when I do more than two ReadAnys i dont get the data. Here is my code as to what i'm up to:
Timer interval is 100
Public Class MainForm
Private Tank36Level As Double
Private Tank37Level As Double
Private Tank38Level As Double
Private Tank39Level As Double
Private Tank40Level As Double
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
' Get Tank levels
EthernetIPforSLCMicro1.AsyncMode = True
EthernetIPforSLCMicro1.ReadAny("F25:40")
EthernetIPforSLCMicro1.ReadAny("F25:43")
EthernetIPforSLCMicro1.ReadAny("F25:46")
EthernetIPforSLCMicro1.ReadAny("F25:49")
EthernetIPforSLCMicro1.ReadAny("F25:52")
EthernetIPforSLCMicro1.AsyncMode = False
' ''
TextBox1.Text = Format(Tank36Level, "#") & " cm"
TextBox2.Text = Format(Tank37Level, "#") & " cm"
TextBox3.Text = Format(Tank38Level, "#") & " cm"
TextBox4.Text = Format(Tank39Level, "#") & " cm"
TextBox5.Text = Format(Tank40Level, "#") & " cm"
'
End Sub
'
Private Sub EthernetIPforSLCMicro1_DataReceived(ByVal sender As System.Object, ByVal e As AdvancedHMI.PLCCommEventArgs) Handles EthernetIPforSLCMicro1.DataReceived
If e.PLCAddress = "F25:40" Then Tank36Level = e.Values(0)
If e.PLCAddress = "F25:43" Then Tank37Level = e.Values(0)
If e.PLCAddress = "F25:46" Then Tank38Level = e.Values(0)
If e.PLCAddress = "F25:49" Then Tank39Level = e.Values(0)
If e.PLCAddress = "F25:52" Then Tank40Level = e.Values(0)
End Sub
End Class
Thanks,
That should work, but a better may be like this:
Public Class MainForm
Private Tank36Level As Double
Private Tank37Level As Double
Private Tank38Level As Double
Private Tank39Level As Double
Private Tank40Level As Double
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
' Get Tank levels
EthernetIPforSLCMicro1.AsyncMode = True
EthernetIPforSLCMicro1.ReadAny("F25:40",13)
EthernetIPforSLCMicro1.AsyncMode = False
End Sub
'
Private Sub EthernetIPforSLCMicro1_DataReceived(ByVal sender As System.Object, ByVal e As AdvancedHMI.PLCCommEventArgs) Handles EthernetIPforSLCMicro1.DataReceived
If e.PLCAddress = "F25:40" Then
Tank36Level = e.Values(0)
Tank37Level = e.Values(3)
Tank38Level = e.Values(6)
Tank39Level = e.Values(9)
Tank40Level = e.Values(12)
TextBox1.Text = Format(Tank36Level, "#") & " cm"
TextBox2.Text = Format(Tank37Level, "#") & " cm"
TextBox3.Text = Format(Tank38Level, "#") & " cm"
TextBox4.Text = Format(Tank39Level, "#") & " cm"
TextBox5.Text = Format(Tank40Level, "#") & " cm"
end if
End Sub
ah, i see you bring an array back and split it back out. i'll give that a try in the morning. i'd still like to get the subscribe working…
Archie,
Yes the method you provide works well when reading the F25 register, but I am also reading a B30 register with multiple ReadAnys still makes the program slow to respond to button clicks. I think I need to subscribe to these, as i can't asyncRead individual bits in the B30 reg.
Unless t here is an issue in the driver, it should let you do an Async read on bits. If that doesn't work, you can try it like this:
Private MyBit0 As Boolean
Private MyBit1 As Boolean
Private MyBit2 As Boolean
Private MyBit3 As Boolean
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
' Get Tank levels
EthernetIPforSLCMicro1.AsyncMode = True
EthernetIPforSLCMicro1.ReadAny("B30:0")
EthernetIPforSLCMicro1.AsyncMode = False
End Sub
'
Private Sub EthernetIPforSLCMicro1_DataReceived(ByVal sender As System.Object, ByVal e As AdvancedHMI.PLCCommEventArgs) Handles EthernetIPforSLCMicro1.DataReceived
If e.PLCAddress = "B30:0" Then
MyBit0 = ((e.Values(0) and 1)>0)
MyBit1 = ((e.Values(0) and 2)>0)
MyBit2 = ((e.Values(0) and 4)>0)
MyBit3 = ((e.Values(0) and 8)>0)
end if
End Sub
Again, that's fine when reading two file registers, but trying three or more, it seems to choose only two of them. I'm enabling and re-enabling the asyncmode with each Read. Any more ideas? Thanks for all the help with this. :)
Not sure why that doesn't work, but this is a method that I have used when polling multiple addresses:
Private NextAddressToRead as String="B30:0"
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
' Get Tank levels
EthernetIPforSLCMicro1.AsyncMode = True
EthernetIPforSLCMicro1.ReadAny(NextAddressToRead)
End Sub
'
Private Sub EthernetIPforSLCMicro1_DataReceived(ByVal sender As System.Object, ByVal e As AdvancedHMI.PLCCommEventArgs) Handles EthernetIPforSLCMicro1.DataReceived
If e.PLCAddress = "B30:0" Then
MyBit0 = ((e.Values(0) and 1)>0)
MyBit1 = ((e.Values(0) and 2)>0)
MyBit2 = ((e.Values(0) and 4)>0)
MyBit3 = ((e.Values(0) and 8)>0)
NextAddressToRead="F25:40"
end if
If e.PLCAddress = "F25:40" then
.
.
.
NextAddressToRead="B30:0"
End if
End Sub
Right, I've got it work in the new version of AdvancedHMIv3, but, it doesn't seem any more responsive than doing the synchronous method! The main problem for me is that i have a button on the form that is slow to respond to clicks. Would the subscribe method improve upon this? Would the subscribe method you mentioned in point 4 work for the latest HMIv3? thanks,
Archie, I've got it working perfectly now with the subscribe command! I'm using the main form load event to initiate all of the subscribes and then using the polleddatareturned events to update my variables. I might go down the road of making up my own components to make building a bit quicker. thanks for all the help!
That's good that you got it working… I was going to say that in my latest test project I have a main form with several popup forms. The main form is an overall plant layout, with status indicators for each motor in the plant. Clicking on any one of them brings up a small popup where the operator can do start/stop set speed, etc. I noticed a lot of problems using several forms, but this is all on DF1. I never did use the subscribe methods, but what I did to work around it all was when each popup loads, I set the DF1Comm of each component of the popup to the DF1 that's on the main form. This way, all comms are going through one iteration of the driver instead of multiple ones. That, in conjunction with setting the DF1 on the main form to ASYNCH seemed to make things run pretty smoothly.