Convert between Datatable and TAP ResultTable

Hi,

I wrote a piece of code to convert between Datatable and TAP‘s ResultTable, can you help check if this ok?

When publish result:

private string name;
private List<string> columnNames;
private Array[] results;

Datatable2ResultTable(dt, out name, out columnNames, out results);
Results.PublishTable(name, columnNames, results);

Show ResultTable in a ListView:

DataTable dt = ResultTable2Datatable(resultTable);
listView.ItemsSource = dt.DefaultView;
public static bool Datatable2ResultTable(DataTable dt, out string name, out List<string> columnNames , out  Array[] results)
        {
            name = dt.TableName;

            List<string> _columnNames = new List<string>();
            if (dt.Columns.Count > 0)
            {
                int columnNum = 0;
                columnNum = dt.Columns.Count;
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    _columnNames.Add(dt.Columns[i].ColumnName);
                }
            }
            columnNames = _columnNames;

            Array[] _results = new Array[dt.Columns.Count];

            if (dt.Columns.Count > 0)
            {
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    string colName = dt.Columns[i].ColumnName;

                    ArrayList colDatas = new ArrayList();
                    //create arraylsit from DataTable
                    foreach (DataRow dr in dt.Rows)
                    {
                        colDatas.Add(dr[colName]);
                    }

                    _results[i] = colDatas.ToArray();
                }
            }
            results = _results;
            return true;
            }

        public static DataTable ResultTable2Datatable(ResultTable resultTable)
        {
            DataTable dt = new DataTable("TestResult");

            // Write out the result table column names.
            foreach (ResultColumn rc in resultTable.Columns)
            {
                dt.Columns.Add(rc.Name);
            }

            int maxRowIndex = MaxRowCount(resultTable);

            // Write out the rows for each column.  
            for (int rowIndex = 0; rowIndex < maxRowIndex; rowIndex++)
            {
                DataRow dr = dt.NewRow();
                int colIndex = 0;
                foreach (ResultColumn rc in resultTable.Columns)
                {
                    dr[colIndex] = rc.Data.GetValue(rowIndex);
                    colIndex++;
                }
                dt.Rows.Add(dr);
            }

            return dt;
        }

Hi @Light,

It looks ok to me. Are you having any specific trouble with it?

When test some dut, I have I-V sweep step, sweep step dymatic adjusted according the current, use datatable is more conveniently.

When test plan finished, I also need to show some test data in a dock pannel.

Another question, how to show I-V curve during test step run?

If you have a custom panel, you can specify a result listener. Then you can show your I-V curve on the panel.

If you check the examples, it shows one where a ResultListener is being used with a panel. opentap/sdk/Examples/PluginDevelopment.Gui/GUI/DockablePanel.cs at main · opentap/opentap · GitHub

Especially note how it uses GuiHelper.GuiInvoke to avoid calling into the GUI from outside the GUI thread.

On those call backs you can show any kind of graph you’d like.

Thank you.

Refer to Alexander’s code, I finnally got what I need.

2 Likes