Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Extracting data from CNiDataSocketData

Hi!
I need to display the data into an edit box of Visual C++. I have several CNiDataSockets and I am displaying some of them on the graphs with

m_Graph.CharY(data);

However I need to display and update some values in text boxes. I am trying to use

m_Value1.SetWindowText(CNiString(data));

But it is not working and textboxes always show '0' in it. I will be thankful to get help in this regard.
0 Kudos
Message 1 of 5
(3,535 Views)
There are a couple of ways to do this. First, note that CNiDataSocketData does not just encapsulate the data - it encapsulates the data and its attributes. Therefore, to actually get to the data you should use the Value property. The Value property is a CNiVariant, which you can then cast to a CString since CNiVariant defines operator CString. For example:

m_Value1.SetWindowText((CString)data.Value);

CNiDataSocketData also defines several conversion operators, including operator CString, which apply the conversion to the data. So you could also do this:

m_Value1.SetWindowText((CString)data);

- Elton
0 Kudos
Message 2 of 5
(3,535 Views)
Hi!
I am thankful for your help, but can you please further explain the approach as none of the above lines of code seems to work as it still shows the value "0" in text fields. For illustration I am including the code here:

void COpcClientDlg::OnDataUpdated (CNiDataSocketData &data)
{
try
{
// Get Quality attribute and set LED
CNiOpcQuality quality(data);
m_QualityLED.Value = quality.IsQualityGood();

// Get Timestamp attribute and display in text box
m_Timestamp.SetWindowText(CString(data.GetAttribute("TimeStamp").Value));
}
catch (COleException* e)
{
// Unable to retrieve value for an attribute
e->ReportError();
e->Delete();
}

if (i == 1)
{
m_
Graph1.ChartY (data);
}
else if (i == 2)
{
m_Graph2.ChartY (data);
}
else if (i == 3)
{
m_Graph3.ChartY (data);
}
else if (i == 4)
{
m_Graph4.ChartY (data);
}
else if (i == 5)
{
m_Value1.SetWindowText((CString)data.Value);
}
else if (i == 6)
{
m_Value2.SetWindowText((CString)data.Value);
}
else if (i == 7)
{
m_Value3.SetWindowText((CString)data.Value);
}
}
0 Kudos
Message 3 of 5
(3,535 Views)
Assuming, for instance, that the data coming in on the DataSocket is type double, the following should do the trick:

m_value1.SetWindowText(CNiString() << static_cast(data.Value));

The Measurement Studio CNiString class provides stream insertion operators (<<) that allow writing numeric values to the string.

An alternative is to use the NumEdit control that is provided with Measurement Studio. It has a Value property that can be directly assigned to a number.

Let me know if you are still having problems.

Tony H.
Measurement Studio
0 Kudos
Message 4 of 5
(3,535 Views)
Hi!
Thanks a lot. It worked.

-Waqt
0 Kudos
Message 5 of 5
(3,535 Views)