Author Topic: Read PLC values directly into a VB variable?  (Read 5588 times)

rbeavers

  • Newbie
  • *
  • Posts: 19
    • View Profile
Read PLC values directly into a VB variable?
« on: November 21, 2016, 10:15:47 AM »
Hello,
I would like to read a PLC tag value or array directly into a VB variable or array. I would like this to happen in the background without having to display a control or controls...

Is it possible to read values from a PLC without having a control visible on the screen? Is there a specific tool for this?

Thanks,
-Rob

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Read PLC values directly into a VB variable?
« Reply #1 on: November 21, 2016, 10:19:14 AM »
Which driver are you using?

All of the drivers allow you to directly read/write via code. There is also the option of using a DataSubscriber to get a continuous update PLC data that will be send to an event handler.

rbeavers

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Read PLC values directly into a VB variable?
« Reply #2 on: November 23, 2016, 10:33:42 AM »
Hi Archie, I am using the EthernetIPforCLXCom v 3.99p driver. I'm particularly interested in the DataSubscriber to Event; but Discrete and Array work as well.

Can you post some VB.Net (2013) code examples for DataSubscriber and Discrete/Array? I may be using other drivers in the future, usually the AB line of PLC's.

Thanks,
-Rob

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Read PLC values directly into a VB variable?
« Reply #3 on: November 23, 2016, 10:47:32 AM »
The Datasubscribers works well when you need a continuous update of data. You can think of the DataSubscriber as a BasicLabel without the visual component. This is how you would use it:

- Add a DataSubscriber to the form
- Set PLCAddressValue to a tag
- Double click the DataSubscriber to get back to the code
- Enter this code:
Code: [Select]
Msgbox (e.PLCAddress & "=" * e.Values(0))


If you want to read a one time value in code, then you would use it like this:
Code: [Select]
Dim MyValue as string
MyValue=EthernetIPforCLXCom1.Read("MyTag")

rbeavers

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Read PLC values directly into a VB variable?
« Reply #4 on: November 23, 2016, 10:50:06 AM »
Thanks Archie.

How about addressing a single bit within an array?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Read PLC values directly into a VB variable?
« Reply #5 on: November 23, 2016, 11:01:01 AM »
How about addressing a single bit within an array?
As in a BOOL array or an array of DINT?

rbeavers

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Read PLC values directly into a VB variable?
« Reply #6 on: November 23, 2016, 11:08:29 AM »
Example:
RobotComms[20] - 20 Word Array

Need to address:

RobotComms[3].7 - Word 3, Bit 7  Boolean
and/or
RobotComms[5] - Word 5 (SINT, DINT or Real)

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Read PLC values directly into a VB variable?
« Reply #7 on: November 23, 2016, 11:51:05 AM »
Example:
RobotComms[20] - 20 Word Array

Need to address:

RobotComms[3].7 - Word 3, Bit 7  Boolean
and/or
RobotComms[5] - Word 5 (SINT, DINT or Real)
To read multiple array elements in code:
Code: [Select]
Dim values() as string
values=EthernetIPforCLXCom1.Read("RobotComms[0]",20)

The others are exactly as you have them. For example, add a BasicLabel to the form and put RobotComms[3].7 in the PLCAddressValue Property


rbeavers

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Read PLC values directly into a VB variable?
« Reply #8 on: November 23, 2016, 12:22:50 PM »
Thanks Archie!

Superb support!!! :)