Agilent Technologies N5980A Webcam User Manual


 
Programming Reference
Sample Code
The following example code shows how to control the N5980A from
within a remote program. The example code is implemented in C#.
The code snippets show the required code that needs to be added to a
user program.
It implements a class N5980A in the namespace N5980AExample that
allows communication with the N5980A user software.
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Windows.Forms;
namespace TBertExample
{
class N5980A
{
/// <summary>
/// Holds the input buffer when reading from the socket.
/// </summary>
byte[] bufferin = new byte[64 * 1024];
/// <summary>
/// Holds the TcpClient that is used to establish the
/// remote connection.
/// </summary>
TcpClient m_Client = null;
/// <summary>
/// Holds the NetworkStream that provides the communication
link.
/// </summary>
NetworkStream m_Stream = null;
/// <summary>
/// Connect to the instrument with the given hostname and
/// port number. Both values can be retrieved by the
/// Connection -> Info... menu item in the N5980A software
/// </summary>
/// <param name="host">Hostname of the PC that executes
/// the N5980A software.</param>
/// <param name="port">Port number of the software instance
/// to communicate with.</param>
public void Connect(string host, int port)
{
try
{
// resolve address of the given hostname
IPHostEntry ipHostEntry = Dns.Resolve(host);
IPAddress ipAddress = ipHostEntry.AddressList[0];
// create TcpClient and connect it to the instrument
m_Client = new TcpClient();
m_Client.Connect(new IPEndPoint(ipAddress, port));
m_Stream = m_Client.GetStream();
}
catch (Exception e)
{
MessageBox.Show(e.Message, "Connect");
}
}
/// <summary>
/// Close the connection with the N5980A software.
42 N5980A User Guide