Reading data from a PLC unit

Share RGraph:   Share or Like RGraph on Facebook!

« Back to message list

Enter your email address to get email updates on this topic. You can stop receiving updates by clicking the link in the update email messages.

Posted by Mike on 6th April 2017
Hello everybody,
I'm running an industrial plc with a very small amount of memory and this unit provides IE (with activeX...) graphs.
So I want to bypass this using RGraph. I succeeded with first tests (displays the amount of water used in the week/month/ etc). With week/month, I have no problems because I can put the 7 or 12 values into the script data:[...].
Now, I want to display values taken from a sensor. Unfortunately, the amount of data are far bigger: about 1440.
So, I can write the script with the embedded data, directly extracted from the plc BUT the length will be terrible.
Is it a way to incorporate the data using a loop for/next to read the data and display them nicely (I want to display a line ?

         var line = new RGraph.Line({
             id: 'cvs',
             data: [
                 [15,26,11,16,28,13,23,28.5,37,41,42,15],
             ],

             options: {

should be replaced by something easier like

         var line = new RGraph.Line({
             id: 'cvs',
for x=1 to sensor(length of measured data)
             data: [
                 [displayvalue(x)],
             ],
next
             options: {

etc.
No PHP available, just script into a basic html
Thank you very much to enlight me.
Mike
Posted by Richard on 6th April 2017
Hi there,

Not sure why it matters (it's just source code after all) - but you could do something like this to seperate out the code:


// The data
var data = [4,9,6,3,5,4,6,8,4,5,8,6 ...];


// Configure and display the chart
var line = new RGraph.Line({
     id: 'cvs',
     data: data,
     options: {
     }
}).draw();

How exactly is the PLc device providing the data? A JavaScript array that it injects into the page?




Richard
Posted by Mike on 4th September 2017
Hi Richard,
thank you for your explanations. I tried different ways but the problem is in fact my plc that stores data in a specific way and I'm unable to peek them easily. I need to rebuild an array of them every time I want to build a graph. Not very funny for a small plc with a small processor and very few kb of memory.

About multiple charts on the same page (to save memory), I checked your answers here in the forum but I'm stuck with the problem:
if I create different id's, only the last chart is visible. To simplify, here is the code I put:

...
<canvas id="cvs" width="900" height="350">
<canvas id="cvs2" width="900" height="350">
<script>
         window.onload = function ()
         {
             var bar = new RGraph.Bar({
                 id: 'cvs',
                 data: [1,2,3,4,5,6,7],
//options here
                 }
   }).draw();
         };

         {
             var bar = new RGraph.Bar({
                 id: 'cvs2',
                 data: [7,6,5,4,3,2,1],
//options here
                 }
   }).draw();
         };
</script>
...

Obviously, I'm more into plc, ladder and sensors than scripts.
I deeply think I miss the exact way to run those functions, but I tried several ways without success.

Thank you for your help
Mike
Posted by Richard on 4th September 2017
Hi there,

Well this is a blast from the past!

Does this run ON the PLC browser? If so then maybe the JavaScript/browser environment that it provides is different to a desktop or mobile browser.

Or does it just send the information to your desktop machine where you have a regular desktop browser?

To get multiple charts on a page you could try using different object names, like this:

www.rgraph.net/fiddle/view.html/multiple-charts-on-one-page

But does your environment have the capability (ie enough memory) to show multiple charts at once?


Richard
Posted by Mike on 4th September 2017
Hi Richard,
thank you again for that precision !
I saw my mistake with your link (obviously, yours is working)...
Stupid but simple, I forgot for an unknown reason the </canvas> at the end of the second line.
And because the built-in editor has absolutely no consistency analysis (and was not made to analyse external code), the compilation was done without errors.
Now I have html files with multiple chart with daily/monthly/yearly stats of the use of my house !
About the timing, it's because I'm always busy with other things (and I have already stats through the old-fashioned activeX local page of my plc). But the idea remained somewhere in my brain ;-)
And cherry on the sunday, I can merge several pages into one (saved some kb on the plc memory).
Have a nice day and thank you again for your support.
Mike

Add a reply




« Back to message list