Herunterladen Inhalt Inhalt Diese Seite drucken

Siemens RF182C Betriebsanleitung Seite 96

Simatic rfid-systeme kommunikationsmodul
Inhaltsverzeichnis
Beispiele/Applikationen
10.2 Anwenderapplikation RF182C
//Start asynchronous receive
ReceiveString s = new ReceiveString();
Connection.BeginReceive(s.buffer, 0, ReceiveString.BufferSize, 0, new
AsyncCallback(ReceiveCallback), s);
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Connecting Failed");
return false;
}
}
/* This routine is called if there is new data in the asynchronous
* receive available. The data is stored in ReceiveBuffer, so that
* it can be collected by the synchronous timer UpdateTimer.
* */
private void ReceiveCallback(IAsyncResult res)
{
try
{
if (ConnectionState == true)
{
Connection.BeginReceive(rs.buffer, 0, ReceiveString.BufferSize, 0, new
AsyncCallback(ReceiveCallback), rs);
}
}
catch (Exception ex)
{
// An error occured --> report it
AsyncError = true;
MessageBox.Show(ex.Message);
}
}
//This routine is called when the Send button is clicked
private void buttonSend_Click(object sender, EventArgs e)
{
96
// Collect data
int size = Connection.EndReceive(res);
ReceiveString s = (ReceiveString)res.AsyncState;
// Without a lock we might cause race situations
lock (ReceiveBuffer)
{
//Store data in buffer
ReceiveBuffer += Encoding.ASCII.GetString(s.buffer, 0, size);
}
//Start new asynchronous receive
ReceiveString rs = new ReceiveString();
Kommunikationsmodul RF182C
Betriebsanleitung, 10/2010, J31069-D0204-U001-A2-0018
Inhaltsverzeichnis
loading

Inhaltsverzeichnis