//only do something if there is a message specified
if (editMessage.Text != "")
{
// convert to byte array
byte[] buffer = Encoding.ASCII.GetBytes(editMessage.Text.ToCharArray());
try
{
}
catch (Exception ex)
{
}
//Empty the editbox
editMessage.Text = "";
}
}
/* This routine is called when UpdateTimer ticks. This happens
* synchronous to the thread owning the dialog, hence we can
* manipulate the list.
* */
private void UpdateTimer_Tick(object sender, EventArgs e)
{
if (AsyncError == true)
{
//An error occured!
SetConnectionState(false);
}
else
{
ParseBuffer();
}
}
/* Parses ReceiveBuffer for complete XML telegramms and appends
* them to the list.
* */
private void ParseBuffer()
{
// Without a lock we might cause race situations
Kommunikationsmodul RF182C
Betriebsanleitung, 10/2010, J31069-D0204-U001-A2-0018
// Send!
int count = Connection.Send(buffer);
// Did we send everything?
if (count != buffer.Length)
{
MessageBox.Show("Sending failed!");
SetConnectionState(false);
}
//Show the message in the list.
AppendOutMessage(editMessage.Text);
SetConnectionState(false);
//An error occured
MessageBox.Show(ex.Message);
Beispiele/Applikationen
10.2 Anwenderapplikation RF182C
97