The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Plot real time data form multiple sensors
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

TomBe

Germany
3 Posts

Posted - 06/17/2015 :  09:08:31 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi,
I’m having problems with importing data in real time into Origin and plot them.
The data is available through a serial COM port, or an ASCII file, in which the new values are constantly written into.
The data stream contains multiple sensors and I would like to display them in a bar chart next to each other.

The data stream would look like this:

1 value_sensor1
2 value_sensor2


But I could change the data stream to any format, if needed.

I’ve tried this script: http://www.originlab.com/forum/topic.asp?TOPIC_ID=2370
quote:
getfilename *.*; // open file selection dialog... find your ASCII file
%Z=%B%A; // %A is selected file name, %B is its path
%P=%H; // plot name
%W=%[%C,'_']; // wks name. Next, define the TimerProc macro...
def TimerProc {
win -o %W {open -w %Z}; // import ASCII file to wks
lay -a; // rescale to show new data
};
timer 6; // run TimerProc every 6 seconds



My problem is, that Origin plots the highest value for each sensor. But I need the latest value for each sensor to be plotted.
Is there a simple way to accomplish this?
I’m very grateful for any help.

Edited by - TomBe on 06/17/2015 09:09:49 AM

SeanMao

China
288 Posts

Posted - 06/17/2015 :  10:03:05 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

You can check out the example in link below for your case:

http://www.originlab.com/doc/LabTalk/examples/Data-Import#Reimport

In the example, there is a line should be modified as following:

plotxy (1,2) 215; // Used to plot a bar plot

For plot type IDs, please refer to this page:

http://www.originlab.com/doc/LabTalk/ref/Plot-Type-IDs

Give it a try and see how far it goes.

Regards!

Sean

OriginLab Tech. Service
Go to Top of Page

TomBe

Germany
3 Posts

Posted - 06/18/2015 :  05:52:00 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Sean,
Thank You very much for the quick reply. This method seems much more elegant.
But unfortunately it didn’t solve my problem. Origin still displays the highest value for each sensor in the bar chart.
I probably did not explain exactly enough how the values are written into the file.
The new values are constantly added to the end of the file.
The file would look like this after a few milliseconds:
1 value_sensor1
2 value_sensor2

1 value_sensor1
2 value_sensor2

1 value_sensor1
2 value_sensor2


I’ve tried to use the Range Notation to plot only the latest values, but it seems that that’s not the right way.

I could add a Y value to my data stream, which will be increased every time after all sensor values are written.
For example:

X Y Z
1 1 value_sensor1
2 1 value_sensor2

1 2 value_sensor1
2 2 value_sensor2


If I use the 3D Surface Graph instead of the bar chart, is it possible to plot the second last Y value, so Origin does not plot a half finished row of values?

Regards
Tom
Go to Top of Page

SeanMao

China
288 Posts

Posted - 06/19/2015 :  04:34:08 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Suppose you have 3 sensors, the following code should help:


string fname$ = E:\Test\TestData.txt;
impasc;
@glob=1;
range raIn = !; // For reimport
int inirows = count(col(1),!=""); // Count total data rows
//Suppose there are only 3 sensors
plotxy (wcol(1)[inirows-2:inirows],wcol(2)[inirows-2:inirows]) 215; // Plot last sensor set as bar plot
string gname$ = %H;
double olddate = exist(%(fname$),5); // Note the file date-time

def timerproc
{
    double newdate = exist(%(fname$),5); // Current file date-time
    if(newdate != olddate)
    {
        reimport orng:=raIn; // reimport if the file has changed
        olddate = newdate;
        win -c %(gname$); // Delete previous graph
        int nrows = count(col(1),!=""); 
        range rnewX = wcol(1)[nrows-2:nrows]; // Define a range to store last 3 X values
		range rnewY = wcol(2)[nrows-2:nrows]; // Define a range to store last 3 Y values
		plotxy (rnewX,rnewY) 215;
		string gname$ = %H;
    }
    else ty Nothing new ...; // Delete this line if not needed
}

@glob=0;
timer 10;

//timer -k;

Edited by - SeanMao on 06/19/2015 04:34:50 AM
Go to Top of Page

TomBe

Germany
3 Posts

Posted - 07/04/2015 :  06:34:04 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you very much for your help.
Unfortunately Origin needs a few seconds to load the file, after 10 seconds, because the file is getting too big, I guess.
Origin is probably not the right program for live data.
But the code you wrote works fine, if you wait a few seconds.
Thank you
Go to Top of Page

long123

China
9 Posts

Posted - 07/10/2015 :  02:03:10 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
My problem is, that Origin plots the highest value for each sensor. But I need the latest value for each sensor to be plotted.

sbvdxfnbghm
Go to Top of Page

SeanMao

China
288 Posts

Posted - 07/14/2015 :  02:31:38 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

If you select the whole column, the bar of the highest value will overlap with other ones and appeared as one bar only.

That is way in the script I replied before, it will only plot the latest added points but not the maximum value.

Regards!

Sean

quote:
Originally posted by long123

My problem is, that Origin plots the highest value for each sensor. But I need the latest value for each sensor to be plotted.

sbvdxfnbghm

Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000