Data Sheet

33
ETHERIO24TCPDATASHEET
READINGPORTVALUE
//********************************************************************
//TCP Read Port function sends the command to the device,
//to read the Port and the Value on the Port
//********************************************************************
private void TCPReadPort_Click(object sender, EventArgs e)
{
//********************************************************
//Define the Return Buffer for incoming data
//********************************************************
byte[] ReturnDataBuffer = new byte[2];
//********************************************************
//Open TCP Connection
//********************************************************
if (!TCPConnect())
return; //will kick out if not connected successfully
//********************************************************
//Define variables that are to be used in routine
//********************************************************
NetworkStream clientStream = client.GetStream();
byte[] outBuffer = new byte[16];
byte[] inBuffer = new byte[16];
//********************************************************
//Send out Port Read Command to the unit
//********************************************************
outBuffer[0] = (byte)'a';
clientStream.Write(outBuffer, 0, 1);
clientStream.Flush(); //Send out Command
//********************************************************
//Implementation of Reading Port with Blocking
//Function ReadPortValue only returns 2 bytes
//********************************************************
ReturnDataBuffer = ReadPortValue(clientStream);
//********************************************************
//Display the Port Value in the TextBox provided
//********************************************************
TestTextBox.AppendText("Read Port " +
System.Text.ASCIIEncoding.ASCII.GetString(ReturnDataBuffer,0,1) + " 0x"
+ ReturnDataBuffer[1].ToString("X2") + "\r\n");
TestTextBox.AppendText("\r\n");
//********************************************************
//Disconnect TCP connection
//********************************************************
TCPDisconnect();
}
©
2013ElexolPtyLtd Revision1.3