Author Topic: ZedGraph to monitor a PLC Adress  (Read 2232 times)

DanieLoche

  • Guest
ZedGraph to monitor a PLC Adress
« on: August 03, 2016, 12:05:47 PM »
Hello,

In echo to the discussion we had about using Graphs (and in concequence, ChartBySampling control) with mono (i.e. run AHMI in a Raspberry Pi), I'm working with ZedGraph now.

I tried first to adapt the ChartBySampling control (inherit from ZedGraph instead of Visual Studio Charts), but it looks to much complicated as I was not at ease neither with Zedgraph nor with ChartBySampling controls... So I decided to keep default ZedGraph.

The goal is to get regularly the datas from a PLCAdress, and add it to the ZedGraph.

To add a point to the ZedGraph is quite simple. So my question is:
How to read the value from the PLC ?

Do a Datasubscriber could help me ? (but here I don't know what exactly this control do !) I saw that e.values(0) returns a string... and I need a double to add a point to my ZedGraph.
Or perhaps a timer with a [driver].read() method ? But this solution don't looks very smart, I guess that it could brings more issues...

Running an app on çy Raspberry Pi with Mono, when I open a form with a ChartBySampling control, the app immediately closed (crashed, I suppose)...

Trying to find a solution, I found this topic. TLDR : due to Licensing, it is not allowed to use Chart forms in something else than Microsoft OS.

And I constat that the ChartBySampling control inherits from the Chart control ! Do I have to say goodbye to my project ? :'(
ChartBySampling is based on the System.Windows.Forms.DataVisualization.Charting.Chart class. If you look at this web site and look at the Mono implementation of the Chart object, you will see that it is largely not implemented:

http://www.go-mono.com/status/status.aspx?reference=4.0&profile=4.0&assembly=System.Windows.Forms.DataVisualization

Your options would be to code the equivalent of ChartBySampling and base it on something like ZEDGraph as mentioned in this post:

http://stackoverflow.com/questions/7189841/is-there-an-alternative-to-nets-windows-forms-datavisualization-charting-assem

Or you may be able to find a 3rd party implementation of System.Windows.Forms.DataVisualization.Charting.Chart as mentioned here:

http://mono.1490590.n4.nabble.com/S-W-F-DataVisualization-Charting-td4660508.html

Personally, for a charting application, I would invest the extra $30-$50 and use a micro PC that has full Windows 10 such as this:

http://www.geekbuying.com/item/Wintel-W8-Intel-Atom-Z3735F-64Bit-TV-Box-Windows8-1-Android4-4-Dual-OS-Quad-Core-HDMI-2G-32G-802-11-a-b-g-n-LAN-BT4-0-343918.html

I also found this which may or may not be of any help:

https://apps.ubuntu.com/cat/applications/oneiric/libmono-system-windows-forms-datavisualization4.0-cil/

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: ZedGraph to monitor a PLC Adress
« Reply #1 on: August 03, 2016, 05:11:17 PM »
- Add a DataSubscriber to the form
- Set PLCAddressValue to the address you want to chart
- Double click the DataSubscriber to get back to the code
- Add code something like this:
Code: [Select]
If e.ErrorID=0 then
  '* Use e.values(0) to add a point to the chart
End If

DanieLoche

  • Guest
Re: ZedGraph to monitor a PLC Adress
« Reply #2 on: August 04, 2016, 04:12:25 AM »
Than you ! I wasn't sure about how to use datasubscriber. :)


But in this case datas will be get quite fast, no ? Like at PollRate... ^^
What if I want to get the datas each 15 sec ?
« Last Edit: August 04, 2016, 04:17:51 AM by DanieLoche »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: ZedGraph to monitor a PLC Adress
« Reply #3 on: August 04, 2016, 05:36:25 AM »
- Add another copy of your driver to the form
- Set PollRateOverride to 15000
- In your DataSubscriber, set ComComponent to the new instance

This will make that DataSubscriber only receive data at a rate of 15 seconds.

DanieLoche

  • Guest
Re: ZedGraph to monitor a PLC Adress
« Reply #4 on: August 09, 2016, 12:07:02 PM »
A last question about Datasubscriber :

I'm trying to use the 2nd version to read every alarm bit from the PLC, and so add the messages to a ListView. (seemed like the simplest method to implement a table of alarm logs in an application...).

So I'm using the Data Changed Event. Want does e As Drivers.Common.PlcComEventArgs returns exactly ? I mean, do I have a direct access to the data that has changed, or do I have to make a kind of recording of the values to find the changed one and update my list view ?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: ZedGraph to monitor a PLC Adress
« Reply #5 on: August 10, 2016, 09:08:29 AM »
PLCComEventsArgs has 3 properties of interest, Values(), PLCAddress, and ErrorID

You should always check to make sure ErrorID=0 before trying to use the Values() array.

An important thing to keep in mind about the DataChanged event is that if you subscribe to an array, it will only fire when the first element of the array has changed.

When using DataSunscriber2 with multiple elements, the events will fire separately for each item. You can use e.PLCAddress to determine which item the returned values are for.