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
 Origin Forum
 data acquisition + plotting
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

tonyv

Germany
Posts

Posted - 12/29/2005 :  12:26:46 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin):
Operating System:

Hi,

I found out recently the possibility for data acquisition with Origin. It is really nice opportunity but some problems have occurred.
The communication with the device, through GPIB is not a problem. After the data is stored in a Dataset, the values should be plotted. My question is how to update and show the graph after each read value from the device?
You will help me really a lot!

Cheers


Leo_Li

China
Posts

Posted - 12/30/2005 :  04:00:53 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello,

Try this:

GraphLayer gl = Project.ActiveLayer();
gl.LT_execute("plot -l");

Leo
OriginLab
Go to Top of Page

tonyv

Germany
Posts

Posted - 12/30/2005 :  05:11:18 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Leo,

Great, it works but every time draws the new graph over the old one and all of them can be seen. Maybe, you can tell me how to clear the Layer before the new drawing. I tried to look for something but unseccessful.

Tony

quote:

Hello,

Try this:

GraphLayer gl = Project.ActiveLayer();
gl.LT_execute("plot -l");

Leo
OriginLab




Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 12/30/2005 :  08:18:40 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Tony,

Maybe you can explain how you import and plot the data. Leo's solution should be good enough if each acquisition adds one or more data points to the same column and you plot only that column. If you are doing something else please give us some details, perhaps even your script or code.

Mike Buess
Origin WebRing Member
Go to Top of Page

tonyv

Germany
Posts

Posted - 12/30/2005 :  08:49:18 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply


Hi Mike,

A graph window is composed of two parts, frame and a white the sheet.Is it right? When I added Leo´s solution, I could see the plot on each measurument step(the design is measure, plot, measure, plot..) but it was ploted just into the frame, without the white page. The result was: evry time, the plot is ploted over the old one and I get as many plots as points are measured.
Maybe, this explanation is not good enough. My experince in programing with Origin is one week long :). Before, I have always used VStudio.
The application is done mainly from the examples from the help.
1. GPIB.c // modified according to my needs;
2. there is also added the code for ploting:


Worksheet wks;

wks.Create("Origin.otw", CREATE_VISIBLE_SAME);

wks.GetPage().Rename("new");

string strColName;


int colNum = wks.AddCol("MyX", strColName);

wks.AddCol("MyY", strColName);

int rows = wks.GetNumRows(); //UINT

Column cc("new", colNum);

cc.SetType(OKDATAOBJ_DESIGNATION_X);

GraphPage grph;

string strTemplate = "mytemplate.otp";

BOOL bOK = grph.Create(strTemplate, CREATE_VISIBLE);

if (!bOK)

return;

Sleep(1000);
grph.Show(TRUE);
Dataset dd1("new_MyX");
Dataset dd2("new_MyY");
dd1.SetSize(rows);
dd2.SetSize(rows);
//the loop for reading the values from the device
for( int i = 0; i < dd1.GetSize();i++)
{
char read[] = "READ?"; /* Read query */
ibwrt(Device, read, sizeof(read));
CHECK_ERROR /* Check error */

ibrd(Device, Buffer, 20);
Sleep(100);
CHECK_ERROR

Buffer[user_ibcntl] = '\0';
Sleep(100);

double a=atof(Buffer);
Sleep(100);

dd1[i] = i;
Sleep(100);

dd2[i] =a;
main(bOK,grph);

GraphLayer gl = Project.ActiveLayer();
gl.LT_execute("plot -n mytemplate.otp dd1 dd2");

Sleep(1000);



}//END of GPIB.c







3. the "main" which I call up:



void main(BOOL bOK,GraphPage grph)
{
GraphLayer grlay = grph.Layers(0);

ASSERT(grlay.IsValid());

// Get the curve object from "Data1_b" data set

Curve cv("new_MyY"); //"Data1_b");

ASSERT(cv.IsValid());

// Add one data plot to the graph layer:

bOK = 0 <= grlay.AddPlot(cv);

if (!bOK)

return;

// Rescale layer:
Sleep(100);
grlay.Rescale();


Sleep(100);
// Add another layer to graph page:

//Sleep(1000);

bOK = grph.AppendLayers(NULL);

//(strTemplate, CREATE_VISIBLE);

//grlay.Show(TRUE);



if (!bOK)


return;



// Get the second layer:

GraphLayer grlay2 = grph.Layers(1);

ASSERT(grlay2.IsValid());

// Get the curve object from "Data1_c" data set

Curve cv2("new_MyX"); //"Data1_c");

ASSERT(cv2.IsValid());

// Add one data plot to the second layer:

bOK = 0 <= grlay2.AddPlot(cv2);

// Rescale layer:

grlay.Rescale();

}


Go to Top of Page

cpyang

USA
1406 Posts

Posted - 12/30/2005 :  10:59:38 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Tony,

I have put together a simple example, as I see we didnt provide example on how to draw realtime graphs.
Hope this helps.

To try,
1. compile the code into a file
2. from script window type
daq

 
#include <Origin.h>
////////////////////////////////////////////////////////////////////////////////////
#define MAX_DAQ_PTS 1000 // max number of points that can be collected
#define MAX_Y 1234
#define MIN_Y 567
#define MIN_X (-200)
#define MAX_X 500

static void new_data(vector& vx, vector& vy, int& nCounter)
{
int nSize = MAX_DAQ_PTS;
double x0 = 0.3;// center location from 0-1
double xCtr = x0 * nSize;
double xWidth = 0.1 * nSize;
double yHeight = (MAX_Y - MIN_Y) * 0.8;
double yNoiseLevel = 0.012 * MAX_Y;
int npts = 10;
for(int ii = 0; ii < npts; ii++)
{
int nx = nCounter++;

double x = MIN_X + (MAX_X - MIN_X) * nx/(nSize - 1.0);
double y = MIN_Y + yNoiseLevel * rnd() + yHeight * exp(-(nx - xCtr)^2.0 / (PI*xWidth));
vx.Add(x);
vy.Add(y);
}
}

void daq()
{
// start a new project and with a default wks and make a line plot
LT_execute("doc -s");// turn off asking to save OPJ
Project.Open(NULL);
Worksheet wks = Project.ActiveLayer();
if(!wks)
return;// default new project not having a wks
wks.SetSize(MAX_DAQ_PTS, 2); //this will prepare the wks with the needed size so can be faster when adding data

// we need these later
string strDataX = wks.Columns(0).GetDatasetName();
string strDataY = wks.Columns(1).GetDatasetName();

GraphPage gp;
gp.Create("Line");// create new graph window with the Line.OTP template
GraphLayer gl = gp.Layers();
Curve cc(strDataX, strDataY);
int nPlot = gl.AddPlot(cc, IDM_PLOT_LINE);

// prepare graph scale
Scale ax(gl.X);
Scale ay(gl.Y);
ax.From = MIN_X;
ax.To = MAX_X;
ay.From = MIN_Y;
ay.To = MAX_Y;

Dataset dx(strDataX);
Dataset dy(strDataY);
// we start out with range reset to 0
dx.SetUpperIndex(-1);
dy.SetUpperIndex(-1);
// give some time to allow Origin to finish with graph initialization
LT_execute("sec -p 0.2");

out_str("DAQ starting...");
int nCount = 0;
int nn = 0;
do
{
vector vx, vy;
new_data(vx, vy, nCount);
dx.Append(vx, REDRAW_REALTIME);
dy.Append(vy, REDRAW_REALTIME);
// allow Origin time to do the drawing and also to allow control of other things
// and to allow typing into script window etc
LT_execute("sec -p 0.1"); // the gap of 0.1 sec can be adjusted according to collection rate
string str;
str.Format("collecting, index = %d", nn);
SetDataDisplayText(str);
} while((nn = dy.GetUpperIndex()) < MAX_DAQ_PTS);

out_str("DAQ finished");
}





CP


Go to Top of Page

tonyv

Germany
Posts

Posted - 12/30/2005 :  11:30:41 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks a lot, but:


D:\Program Files\OriginLab\Origin7\OriginC\n.c(47) :Error, Member function vector::Add not defined or does not have matching prototype.



Go to Top of Page

cpyang

USA
1406 Posts

Posted - 12/30/2005 :  11:35:41 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Tony,

Looks like your version of Origin must be very old. My code was written with Origin 7.5.

CP


Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 12/30/2005 :  12:54:39 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Tony,

Try replacing vx.Add(x) with vx.SetAtGrow(vx.GetSize(),x). Likewise with vy.Add(y).

Mike Buess
Origin WebRing Member
Go to Top of Page

tonyv

Germany
Posts

Posted - 01/02/2006 :  04:09:58 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Happy New Year!

Again:

D:\Program Files\OriginLab\Origin7\OriginC\n.c(47) :Error, Member function vector::SetAtGrow not defined or does not have matching prototype.


I have Origin7.

Tony

Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 01/02/2006 :  08:46:04 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You need to apply the Service Release 4 patch...

http://www.originlab.com/index.aspx?s=9&lm=+145 (English)
http://www.originlab.com/index.aspx?s=9&lm=198 (German)

...In fact, the original vx.Add() and vy.Add() functions work fine in 7.0 SR4. Now compiler will flag the line wks.SetSize(MAX_DAQ_PTS, 2);. However, you don't really need that line so just delete or comment out with //.

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 01/02/2006 09:59:59 AM
Go to Top of Page

tonyv

Germany
Posts

Posted - 01/02/2006 :  10:40:05 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Yes, it worked but I couldn´t see "realtime" how the graph is drawing. I added this: the lines after ->
now it seems to work well.

do
{
vector vx, vy;
new_data(vx, vy, nCount);
dx.Append(vx, REDRAW_REALTIME);
dy.Append(vy, REDRAW_REALTIME);
// allow Origin time to do the drawing and also to allow control of other things
// and to allow typing into script window etc
->GraphLayer gl = Project.ActiveLayer();
->gl.LT_execute("plot -l");
->gl.Rescale();
LT_execute("sec -p 0.2"); // the gap of 0.1 sec can be adjusted according to collection rate
string str;
str.Format("collecting, index = %d", nn);
SetDataDisplayText(str);
} while((nn = dy.GetUpperIndex()) < MAX_DAQ_PTS);


Go to Top of Page

tonyv

Germany
Posts

Posted - 01/02/2006 :  10:48:13 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks again, I am charmed:)
quote:

Yes, it worked but I couldn´t see "realtime" how the graph is drawing. I added this: the lines after ->
now it seems to work well.

do
{
vector vx, vy;
new_data(vx, vy, nCount);
dx.Append(vx, REDRAW_REALTIME);
dy.Append(vy, REDRAW_REALTIME);
// allow Origin time to do the drawing and also to allow control of other things
// and to allow typing into script window etc
->GraphLayer gl = Project.ActiveLayer();
->gl.LT_execute("plot -l");
->gl.Rescale();
LT_execute("sec -p 0.2"); // the gap of 0.1 sec can be adjusted according to collection rate
string str;
str.Format("collecting, index = %d", nn);
SetDataDisplayText(str);
} while((nn = dy.GetUpperIndex()) < MAX_DAQ_PTS);






Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 01/02/2006 :  11:06:05 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Two minor comments... (1) GraphLayer gl is declared before the do loop. No need to redeclare. (2) gl.Rescale() will update the graph. No need for "plot -l".

Mike Buess
Origin WebRing Member
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 01/02/2006 :  4:57:17 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
 Yes, it worked but I couldnt see "realtime" how the graph is drawing. I added this: the lines after -> 
now it seems to work well.


Hi Tony,

Proper realtime update via the Append command to Dataset maybe not working in your version of Origin, and that was why you need to add code like rescale to force a redraw, which is much slower then the intrisic realtime mechanism.

If you have Origin 7.5, then my original code would compile and you should see a smooth realtime drawing of the data without the flashing of the entire graph.


CP


Go to Top of Page

tonyv

Germany
Posts

Posted - 01/03/2006 :  02:52:47 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Yes, we should think of upgrading the version. :)

quote:

 Yes, it worked but I couldnt see "realtime" how the graph is drawing. I added this: the lines after -> 
now it seems to work well.


Hi Tony,

Proper realtime update via the Append command to Dataset maybe not working in your version of Origin, and that was why you need to add code like rescale to force a redraw, which is much slower then the intrisic realtime mechanism.

If you have Origin 7.5, then my original code would compile and you should see a smooth realtime drawing of the data without the flashing of the entire graph.


CP






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