Examples/applications
10.2 RF182C user application
RF182C communication module
Operating Instructions, 10/2010
89
SetTagDetectionState(TagDetectionState.UNDEFINED);
//There may be uncollected data in the buffer --> call ParseBuffer()
ParseBuffer();
// Visualization
Enable(true, false);
labelConnectionState.Text = "NOT CONNECTED";
labelConnectionState.BackColor = Color.Red;
buttonConnect.Text = "Connect";
AsyncError = false;
}
}
/* Connects a stream based TCP/IP socket as client. */
private bool Connect()
{
try
{
//Collect port and IP from the window.
int port = 0;
if (Int32.TryParse(editPort.Text, out port) == false || port <= 0)
{
MessageBox.Show(editIP.Text + " is not a legal port");
return false;
}
IPHostEntry hostEntry = null;
// Get host related information.
hostEntry = Dns.GetHostEntry(editIP.Text);
// Loop through the AddressList to obtain the supported AddressFamily. This is to avoid
// an exception that occurs when the host IP Address is not compatible with the address
family
// (typical in the IPv6 case).
for each (IPAddress address in hostEntry.AddressList)
{
IPEndPoint ipe = new IPEndPoint(address, port);
// stream based TCP/IP socket
Socket tempSocket = new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
// the actual connect
tempSocket.Connect(ipe);
if (tempSocket.Connected)
{
//a connection was established successfully
Connection = tempSocket;
Connection.ReceiveTimeout = 25;
break;
}
}
if (Connection == null) return false;