SetTagDetectionState(TagDetectionState.UNDEFINED);
//There may be uncollected data in the buffer --> call ParseBuffer()
ParseBuffer();
// Visualasiation
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)
{
}
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).
foreach (IPAddress address in hostEntry.AddressList)
{
Socket tempSocket = new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
}
if (Connection == null) return false;
Kommunikationsmodul RF182C
Betriebsanleitung, 10/2010, J31069-D0204-U001-A2-0018
MessageBox.Show(editIP.Text + " is not a legal port");
return false;
IPEndPoint ipe = new IPEndPoint(address, port);
// stream based TCP/IP socket
// the actual connect
tempSocket.Connect(ipe);
if (tempSocket.Connected)
{
//a connection was established sucessfully
Connection = tempSocket;
Connection.ReceiveTimeout = 25;
break;
}
Beispiele/Applikationen
10.2 Anwenderapplikation RF182C
95