1.4.2 Saving Instrument Data to Worksheet

Sending Instrument Data to Origin

Appending Data to XYY Worksheet

C# Example

public partial class Form1 : Form
{
    object Default = System.Type.Missing;
    Column colx, coly1, coly2;
    Random random = new Random();
    double[] xx = new double[1];
    double[] yy1 = new double[1];
    double[] yy2 = new double[1];

    public Form1()
    {
        InitializeComponent();
    }
    private void ConnectOrigin_Click(object sender, EventArgs e)
    {
        Origin.ApplicationSI app = new Origin.ApplicationSI();
        app.NewProject();
        WorksheetPage wbk = app.WorksheetPages.Add(Default, Default);
        Worksheet wks = wbk.Layers[0] as Worksheet;
        colx = wks.Columns.Add(Default);
        coly1 = wks.Columns.Add(Default);
        coly2 = wks.Columns.Add(Default);

        colx.DataFormat = COLDATAFORMAT.DF_DATE;
        colx.DisplayFormat = 10;
    }
    private void AddItem_Click(object sender, EventArgs e)
    {
        xx[0] = Date2Julian(DateTime.Now);
        yy1[0] = random.Next(1000);
        yy2[0] = 1000 + random.Next(1000);

        colx.SetData(xx, -1);
        coly1.SetData(yy1, -1);
        coly2.SetData(yy2, -1);
    }
    public double Date2Julian(DateTime vDate)
    {
        double JDN = vDate.Date.ToOADate() + 2415019 + (vDate.Hour - 12) / 24.0 + vDate.Minute / 1440.0 + vDate.Second / 86400.0;
        return JDN;
    }
}

VB Example

Const NUMPTS = 100
    Dim app As Origin.Application
    Dim wbk As Origin.WorksheetPage
    Dim Wks As Origin.Worksheet
    Dim colx, coly1, coly2 As Origin.Column
    Dim ii As Integer
    Dim xx(0) As Double
    Dim yy1(0) As Double
    Dim yy2(0) As Double
    Dim data As Variant

Private Sub ConnectOrigin_Click()
    Set app = New Origin.ApplicationSI
    app.NewProject
    Set wbk = app.WorksheetPages.Add
    Set Wks = wbk.Layers(0)
    Set colx = Wks.Columns.Add
    Set coly1 = Wks.Columns.Add
    Set coly2 = Wks.Columns.Add
    
    colx.Type = COLTYPE_X
    colx.DataFormat = DF_DATE
    colx.DisplayFormat = 10
    
End Sub

Private Sub AddItem_Click()
    xx(0) = Date2Julian(DateTime.Date, DateTime.Time)
    yy1(0) = Rnd(1000)
    yy2(0) = 1 + Rnd(1000)
    ii = colx.SetData(xx, -1)
    ii = coly1.SetData(yy1, -1)
    ii = coly2.SetData(yy2, -1)

End Sub

Public Function Date2Julian(ByVal vDate As Variant, ByVal vTime As Variant) As Double

    Dim DateDiff As Double
    DateDiff = DateTime.DateDiff("d", #12/31/1899#, vDate)
    Date2Julian = DateDiff + 2415019 + (hour(vTime) - 12) / 24 + minute(vTime) / 1440 + second(vTime) / 86400

End Function

Y Columns with Sampling Intervals

C# Example

In this example we use a simple Console application to generate two columns of data with Sampling Intervales to simulate instrument data and save into an Origin worksheet. Units and Long Names of both XY data in each column is also setup.

Column 1
Temperature with units in degree C, samples are taken at 0.02 sec interval.
Column 2
Presure with units in kPa, samples also taken at 0.02 sec interval
static void doTest(int npts)
{
    object Default = System.Type.Missing;
    double[] temp = new double[npts];
    double[] pres = new double[npts];
    for (int ii = 0; ii < npts; ii++)
    {
        temp[ii] = ii * 0.1;
        pres[ii] = ii * 0.000831 + 2.3;
    }

    Origin.ApplicationSI app = new Origin.ApplicationSI();
    app.NewProject();
    WorksheetPage wbk = app.WorksheetPages.Add(Default, Default);
    Worksheet wks = wbk.Layers[0] as Worksheet;
    Column colt = wks.Columns.Add(Default);
    Column colp = wks.Columns.Add(Default);

    wks.set_IsLabelVisible(LABELTYPEVALS.LT_LONG_NAME, Default, true);
    wks.set_IsLabelVisible(LABELTYPEVALS.LT_UNIT, Default, true);
    colt.Type = COLTYPES.COLTYPE_Y;
    colp.Type = COLTYPES.COLTYPE_Y;
    colt.LongName = "Temperature";
    colt.Units = "degree C";
    colp.LongName = "Pressure";
    colp.Units = "kPa";

    colt.SetEvenSampling(0, 20, "ms", "Time", Default);
    colp.SetEvenSampling(0, 30, "ms", "Time", Default);

    colt.SetData(temp, 0);
    colp.SetData(pres, 0);
}

VBA Example

Option Explicit

Const npts = 100
Public Sub doTest()

    Dim temp(npts), pres(npts) As Double
    Dim a As Variant
    Dim ii As Integer
    
    Dim app As Origin.Application
    Dim wbk As Origin.WorksheetPage
    Dim wks As Origin.Worksheet
    Dim colt As Origin.Column
    Dim colp As Origin.Column

    For ii = 0 To npts
        temp(ii) = 0.1 * ii
        pres(ii) = ii * 0.000831 + 2.3
    Next ii

    Set app = New Origin.ApplicationSI
    app.NewProject
    Set wbk = app.WorksheetPages.Add
    Set wks = wbk.Layers(0)
    Set colt = wks.Columns.Add
    Set colp = wks.Columns.Add
    
    wks.IsLabelVisible (LT_LONG_NAME) = true
    wks.IsLabelVisible (LT_UNIT) = true
    colt.Type = COLTYPE_Y
    colp.Type = COLTYPE_Y
    colt.LongName = "Temperature"
    colt.Units = "degree C"
    colp.LongName = "Pressure"
    colp.Units = "kPa"
    
    a = colt.SetEvenSampling(0, 20, "ms", "Time")
    a = colp.SetEvenSampling(0, 30, "ms", "Time")

    a = colt.SetData(temp)
    a = colp.SetData(pres)

End Sub