Data Sheet
32
ETHERIO24TCPDATASHEET
ClosingTCPConnection
//********************************************************************
//TCP Disconnect function closes port
//********************************************************************
private void TCPDisconnect()
{
client.Close();
client = null;
TestTextBox.AppendText("TCP Client Disconnected" + "\r\n");
}
SendingTCPCommands
SETTINGPORTDIRECTIONREGISTERANDPORTVALUE
//********************************************************************
//TCP Send Direction function sends command to device to set the
//Port Direction of PORT A to all output
//********************************************************************
private void TCPSendDirection_Click(object sender, EventArgs e)
{
//********************************************************
//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 Direction Command to the unit
//********************************************************
outBuffer[0] = (byte)'!'; //Direction Command
outBuffer[1] = (byte)'A'; //Port
outBuffer[2] = (byte)0x00; //Value to be written to port direction register
clientStream.Write(outBuffer, 0, 3);
clientStream.Flush(); //Send out TCP packet
//********************************************************
//Send out Port Command to the change value on Port
//********************************************************
outBuffer[0] = (byte)'A';
outBuffer[1] = (byte)0x55;
clientStream.Write(outBuffer, 0, 2);
clientStream.Flush();
//********************************************************
//Disconnect TCP connection
//********************************************************
TCPDisconnect();
}
©
2013ElexolPtyLtd Revision1.3