AdvancedHMI Software
General Category => Open Discussion => Topic started by: jfarrell on January 26, 2015, 11:31:26 AM
-
I am trying to figure out a way to read an address on the PLC, scale the value, and then write the scaled value to another PLC address. For example, if address "N70:110" read 30, then scale 30 x 2, and write 60 to address "N7:55." Any suggestions? Thank you.
-
- Add a DataSubscriber to the form
- Set PLCAddressValue to N70:110
- Double click the DataSubscriber to get back to the code and enter this code:
EthernetIPforPLCSLCMicroCom1.Write("N7:55",e.values(0)*2)
-
Here is the code I ended up after entering N70:110 in the PLCAddressValue field of datasubscriber. I still got an error when trying to run it. Can you see what I'm missing?
Code:
Private Sub DataSubscriber1_DataChanged(sender As System.Object, e As MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs) Handles DataSubscriber1.DataChanged
EthernetIPforPLCSLCMicroCom1.Write("N7:55", e.Values(0) * 2)
End Sub
Error:
Overload resolution failed because no accessible 'Write' can be called without a narrowing conversion:
'Public Function Write(startAddress As String, dataToWrite As String) As String': Argument matching parameter 'dataToWrite' narrows from 'Double' to 'String'.
'Public Function Write(startAddress As String, dataToWrite As Single) As Integer': Argument matching parameter 'dataToWrite' narrows from 'Double' to 'Single'.
'Public Function Write(startAddress As String, dataToWrite As Integer) As Integer': Argument matching parameter 'dataToWrite' narrows from 'Double' to 'Integer'.
-
Sorry my mistake, plus a little more for error trapping:
Private Sub DataSubscriber1_DataChanged(sender As System.Object, e As MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs) Handles DataSubscriber1.DataChanged
Try
EthernetIPforPLCSLCMicroCom1.Write("N7:55", convert.ToInt32(e.Values(0)) * 2)
catch ex as exception
msgbox ex.message
end try
End Sub
-
It works. Thank you.