![background image](http://html1.mh-extra.com/html/tektronix/keithley-2306-lan/keithley-2306-lan_manual_1077546009.webp)
Model 2306-LAN Communications and Firmware Upgrade Instructions
071377001
April
2022
9
Raw socket protocol C# example
When you use the VXI-11 protocol to communicate with a 2306-LAN instrument, use the C# (C-sharp)
programming language using the following example (in the order indicated) to program your instrument.
1. Set the IP address.
2. Set the port.
3. Connect to the instrument.
4. Send a command or READ data.
static void Main(string[] args)
{
//define IP address variable
IPAddress ip;
//define end point
IPEndPoint ipe;
//define a socket
Socket clientSocket;
//instrument address ip: 192.168.0.2
ip = IPAddress.Parse("192.168.0.2");
// set instrument TCP port:5025
ipe = new IPEndPoint(ip, 5025);
clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp);
//Connect to instrument through LAN
clientSocket.Connect(ipe);
//send message
string idnCommand = ":SOUR:VOLT 5;:OUTP ON;:READ?";
//send command
set 5v, output on, read volt value
//Command encodes to byte array
byte[] sendBytes = Encoding.ASCII.GetBytes(idnCommand);
//send command
clientSocket.Send(sendBytes);
C//windows console output
Console.WriteLine("Send: " + idnCommand);
//receive message
string recStr = "";
//define receiving array . length 4096 bytes
byte[] recBytes = new byte[4096];
//receive command response
int bytes = clientSocket.Receive(recBytes, recBytes.Length, 0);
//encoding to strings
recStr = Encoding.ASCII.GetString(recBytes, 0, bytes);
//console output strings
Console.WriteLine("2306-LAN feedback: " + recStr);
clientSocket.Close();
//pause
Console.Read();
}