Author Topic: Read PLC address, scale value, then write scaled value to another address  (Read 3164 times)

jfarrell

  • Newbie
  • *
  • Posts: 6
    • View Profile
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.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5269
    • View Profile
    • AdvancedHMI
- 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)

jfarrell

  • Newbie
  • *
  • Posts: 6
    • View Profile
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'.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5269
    • View Profile
    • AdvancedHMI
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

jfarrell

  • Newbie
  • *
  • Posts: 6
    • View Profile
It works.  Thank you.