Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use Measurment Studio

So I've been strugeling to get up and running with Measutment studio for a few days now. I'm having problems just getting a graph on the screen.
Here is what I've done:

1) Started a new Measument Studio project. (C++ in VS.Net 2003)
2) Added a graph to the dialog window in VS's dialog editor.
3) Changed the ID of the graph to IDC_GRAPH
4) Wrote this code:
CWnd* window = GetDlgItem(IDC_GRAPH);

CNiGraph* graph = (CNiGraph*) window;
for(int i = 0; i < 50; i++){
graph->ChartY((double) i);
}
5) Ran this code. When this snippet runs, my application crashes.

Now I think the problem is that graph is not of type CNiGraph*.
But for the life of me, I can't figure out what it's type should be.

Am I calling the right function to get a pointer to the graph?
What datatype do I get when I call GetDlgItem? I don't know enough about
MFC to make sense of it's runtime type system, so I don't really know what I've got.
Am I getting a pointer to IUknown?

Well, if anyone has some advise, I'd welcome it.
Thanks in advance,
Philip Knodle

Message Edited by pknodle on 03-16-2005 02:42 PM

Message Edited by pknodle on 03-16-2005 02:42 PM

0 Kudos
Message 1 of 10
(5,307 Views)
Did you use one of the Microsoft Visual C++ wizards to create the project or did you use the Measurement Studio Visual C++ project wizard? The Measurement Studio Visual C++ project wizard is the preferred way to create a Visual C++ project that uses Measurement Studio C++ libraries. For more information about creating a Measurement Studio C++ project, see the "Creating a New Measurement Studio Visual C++ Project" topic in the Measurement Studio reference. If you have Measurement Studio 7.1 installed, this link will take you directly to it.

If you used the Microsoft Visual C++ wizard, the first thing that you will want to do is run the Measurement Studio Add/Remove Class Libraries Wizard to add Measurement Studio C++ class libraries to your project. For more infromation, see the "Adding or Removing Measurement Studio Visual C++ Class Libraries" topic in the Measurement Studio reference. If you have Measurement Studio 7.1 installed, this link will take you directly to it.

Starting from step 3 in your post, here are a few steps that will get you to a simple working application:


  1. Right-click on the graph and click "Add Variable ..." on the context menu. Set the variable name to m_graph, then click Finish.


  2. Go back to the resource editor and add a button to the dialog. Double-click on the button.


  3. Add the following code to the button's click event handler:


    CNiReal64Vector data(100);
    CNiMath::SineWave(data, 1.0);
    m_graph.PlotY(data);


  4. Build and run the application, then click on the button to plot a sine wave to the graph.



There are several more topics in the Measurement Studio reference that you may find useful. Take a look at the topics under "Using the Measurement Studio Visual C++ Class Libraries." If you're looking for more information about using the graph, see the topics under "Using the Measurement Studio Graph Visual C++ Control" (available via this link if you have Measurement Studio 7.1 installed).

Hope this helps.

- Elton
Message 2 of 10
(5,289 Views)
Thanks Elton! That worked great!
0 Kudos
Message 3 of 10
(5,279 Views)
I posted my response before you edited your post to add the code. If you are wanting to attach CNiGraph to a dialog item instead of using a member variable, you can do this in the button click event handler instead:


CNiGraph graph;
graph.AttachControlSite(this, IDC_GRAPH);

CNiReal64Vector data(100);
CNiMath::SineWave(data, 1.0);
graph.PlotY(data);


- Elton
0 Kudos
Message 4 of 10
(5,274 Views)
Thanks for your previous replies. I got the graph control working for a short time.

I added a thread that does image processing and data display.
When I plot data in the main application thread, everything works fine.

When I call CNIGraph::PlotY(CNiReal64Vector) in the new thread, the program throws a NI::CNiOleException.
Does anyone know why this might not work in this thread?

Thanks,
Philip Knodle
0 Kudos
Message 5 of 10
(5,253 Views)
Not to reply to my own post but...

I've noticed that CNiGraph takes an argument for which thread model to use. When I use the dialog editor, the instance of CNiGraph is constucted
by some MFC code (I think, I'm a bit new at MFC programming). Where do I find the call to CNiGraph's contrutor?

Thanks,
Philip Knodle
0 Kudos
Message 6 of 10
(5,248 Views)
This is actually a place where there isn't any MFC "magic" (i.e. macros) to obscure things. Because the CNiGraph constructor has an overload that functions as the default constructor, the compiler generates code to call it automatically if you don't explicitly add a constructor call. Because the CNiGraph is a member variable of the dialog class, you put the call to the constructor in the dialog class member initialization list. Here is an exampe:


CMyApplicationDlg::CMyApplicationDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMyApplicationDlg::IDD, pParent),
m_graph(CNiInterface::SingleThread)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

Message Edited by drohacek on 03-18-2005 04:34 PM

Message 7 of 10
(5,242 Views)
This is actually a place where there isn't any MFC "magic" (i.e. macros) to obscure things. Because the CNiGraph constructor has an overload that functions as the default constructor, the compiler generates code to call it automatically if you don't explicitly add a constructor call. Because the CNiGraph is a member variable of the dialog class, you put the call to the constructor in the dialog class member initialization list. Here is an exampe:


CMyApplicationDlg::CMyApplicationDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMyApplicationDlg::IDD, pParent),
m_graph(CNiInterface::SingleThread)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}


Thanks! I was getting tripped up since I wansn't calling new. Anyways, I set the constructor of the NiGraph to use the MultipleThreads option.
Unfortunatly, this didn't have any impact. Is there anything special I need to do to make MFC/OLE/ActiveX/etc multithreaded?

Thanks again everyone. You've all been a great help.

-Philip Knodle
0 Kudos
Message 8 of 10
(5,240 Views)
Try catching the exception and displaying the message of the exception via CException::ReportError. My guess is that the exception is thrown because you haven't called CoInitialize on the new thread. If that's the case, call ::CoInitialize(NULL) at the beginning of your thread callback, then call ::CoUninitialize() at the end of the callback.

- Elton
Message 9 of 10
(5,226 Views)
Thanks again! I put a call to CoInitalize and now the new thread can call the plaotting functions.
0 Kudos
Message 10 of 10
(5,209 Views)