Skip to content

Commit

Permalink
Fixed disconnecting RFID reader
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan Stricker committed Oct 28, 2019
1 parent 58f14b8 commit 847d39e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
16 changes: 15 additions & 1 deletion 5E9010.29/BR_RFID/BR_RFID/BR_RFID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class BR_RFID
public const byte excReaderNotFound = 1;
public const byte excResponseTimeout = 2;
public const byte excResponseSize = 3;
public const byte excDisconnected = 4;

// ------------------------------------------------------------------------
/// <summary>Response data event. This event is called when new data arrives</summary>
Expand Down Expand Up @@ -246,7 +247,20 @@ void serRFID_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEvent
internal void RefreshTimer_Elapsed(object state)
{
Debug.WriteLine(DateTime.Now + " " + DateTime.Now.Millisecond + " Read timer");
if ((_data_ser == "") && (serRFID != null) && (serRFID.IsOpen))
if(!serRFID.IsOpen)
{
_connected = false;
try
{
disconnect();
}
catch (Exception ex)
{
}
if (OnException != null) OnException(excDisconnected);
return;
}
if ((_data_ser == "") && (serRFID != null))
{
try
{
Expand Down
15 changes: 11 additions & 4 deletions 5E9010.29/RFID_USB/RFID_USB/frmRFID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,14 @@ private void btnConnect_Click(object sender, EventArgs e)
RFID_USB.OnResponseData += new BR_RFID.ResponseData(RFID_USB_OnResponseData);
RFID_USB.connect();

if (RFID_USB.port != -1) txtOutput.AppendText(DateTime.Now.TimeOfDay + " RFID receiver found on port " + RFID_USB.port + "\r\n");
if (chkSendBallon.Checked)
if (RFID_USB.port != -1)
{
trayIcon.BalloonTipText = " RFID receiver found on port " + RFID_USB.port;
trayIcon.ShowBalloonTip(3);
txtOutput.AppendText(DateTime.Now.TimeOfDay + " RFID receiver found on port " + RFID_USB.port + "\r\n");
if (chkSendBallon.Checked)
{
trayIcon.BalloonTipText = " RFID receiver found on port " + RFID_USB.port;
trayIcon.ShowBalloonTip(3);
}
}
}
catch (Exception ex)
Expand Down Expand Up @@ -121,6 +124,10 @@ void RFID_USB_OnException(byte exception)
trayIcon.ShowBalloonTip(3);
}
break;
case BR_RFID.excDisconnected:
MessageBox.Show("RFID reader disconnected!", "B&R RFID Reader", MessageBoxButtons.OK, MessageBoxIcon.Error);
btnConnect.Enabled = true;
break;
}
}

Expand Down

0 comments on commit 847d39e

Please sign in to comment.