Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

can't write data using measurement studio datasocket

I'm trying to connect a datasocket to a file and write Data.
        private const string TargetDataFile    = "file:c:/DATA_1000_R_Data.txt";

This works -->            dataSocketRefData.Connect(TargetDataFile,AccessMode.WriteAutoUpdate);
and I can see the file created in the root directory.

But when I try and do this is when I get "Error:Can't write Data"

            dataSocketRefData.Data.Attributes.Add("Timestamp", DateTime.Now);

I'm using Measurement Studio 7.1 running on  XP Pro

Thanks Dan


0 Kudos
Message 1 of 4
(3,433 Views)
Hi Dan:

Do you have a file that I can use at this end to replicate the issue?

The following link might have some information useful to you:
http://sine.ni.com/apps/we/niepd_web_display.display_epd4?p_guid=B45EACE3E43956A4E034080020E74861&p_node=174961&p_source=External

Thanks
Nandini
0 Kudos
Message 2 of 4
(3,424 Views)
Hi Nandini:

I looked at the example but unfortunately you can't select a file to write to "file:......." only "dstp://". Here's a sample solution you can test.

sing System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using NationalInstruments.Net;

namespace datasocketest
{
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
        private NationalInstruments.Net.DataSocket dataSocketIOREF;
        private System.ComponentModel.IContainer components;
        private System.Windows.Forms.Button Startbutton;
        private System.Windows.Forms.TextBox StatusBox;
        private const string TargetDataFile    = "file:f:/temp/Ref_Data";

        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
  

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.Run(new Form1());
        }

        private void dataSocketIOREF_ConnectionStatusUpdated(object sender, NationalInstruments.Net.ConnectionStatusUpdatedEventArgs e)
        {
            StatusBox.Text = e.Message;
        }

        private void Startbutton_Click(object sender, System.EventArgs e)
        {
            dataSocketIOREF.Connect(TargetDataFile,AccessMode.WriteAutoUpdate);
            dataSocketIOREF.Data.Attributes.Add("Timestamp", DateTime.Now);

        }
    }
}


Best Regards;

Dan
0 Kudos
Message 3 of 4
(3,417 Views)
Nndini:

Here's the rest of it

    private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.dataSocketIOREF = new NationalInstruments.Net.DataSocket(this.components);
            this.Startbutton = new System.Windows.Forms.Button();
            this.StatusBox = new System.Windows.Forms.TextBox();
            ((System.ComponentModel.ISupportInitialize)(this.dataSocketIOREF)).BeginInit();
            this.SuspendLayout();
            //
            // dataSocketIOREF
            //
            this.dataSocketIOREF.SynchronizingObject = this;
            this.dataSocketIOREF.ConnectionStatusUpdated += new NationalInstruments.Net.ConnectionStatusUpdatedEventHandler(this.dataSocketIOREF_ConnectionStatusUpdated);
            //
            // Startbutton
            //
            this.Startbutton.Location = new System.Drawing.Point(32, 32);
            this.Startbutton.Name = "Startbutton";
            this.Startbutton.TabIndex = 0;
            this.Startbutton.Text = "Start";
            this.Startbutton.Click += new System.EventHandler(this.Startbutton_Click);
            //
            // StatusBox
            //
            this.StatusBox.Location = new System.Drawing.Point(8, 192);
            this.StatusBox.Name = "StatusBox";
            this.StatusBox.Size = new System.Drawing.Size(248, 20);
            this.StatusBox.TabIndex = 1;
            this.StatusBox.Text = "Status";
            //
            // Form1
            //
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Controls.Add(this.StatusBox);
            this.Controls.Add(this.Startbutton);
            this.Name = "Form1";
            this.Text = "Form1";
            ((System.ComponentModel.ISupportInitialize)(this.dataSocketIOREF)).EndInit();
            this.ResumeLayout(false);

        }
        #endregion
0 Kudos
Message 4 of 4
(3,415 Views)