Chapter 5 Getting Started with Measurement Studio
Measurement Studio User Manual 5-34 ni.com
8. In Program.cs, add the following code to write an array of data to the server:
[VB.NET]
Imports NationalInstruments.NetworkVariable
Imports System.Threading
Imports System
Module Module1
Private Function GenerateDoubleArray(ByVal phase As Double) As Double()
Dim values(999) As Double
Dim x As Integer
For x = 0 To 999
values(x) = Math.Sin(((2 * Math.PI * x) / 1000) + phase) * 2
Next x
Return values
End Function
Sub Main()
Const location As String = "\\localhost\system\double"
Dim bufferedWriter As NetworkVariableBufferedWriter(Of Double()) =
New NetworkVariableBufferedWriter(Of Double())(location)
bufferedWriter.Connect()
Dim phase As Integer = 0
While (True)
Dim values As Double() = GenerateDoubleArray(phase)
Console.WriteLine("Writing Array")
bufferedWriter.WriteValue(values)
Thread.Sleep(500)
phase = phase + 1
End While
End Sub
End Module
[C#]
using System;
using System.Threading;
using NationalInstruments.NetworkVariable;
namespace NetworkVariableWriter
{
class Program
{
private static double[] GenerateDoubleArray(double phase)
{
double[] values = new double[1000];
for (int x = 0; x < 1000; x++)
values[x] = Math.Sin(((2 * Math.PI * x) / 1000) + phase) * 2;
return values;