private void RFIDNotification_FormClosing(object sender, FormClosingEventArgs e) { lock (moCurrentReadersLock) { foreach (object o in mStoredStates.Keys) { string address = o as string; if (mClients.ContainsKey(address)) { try { MyStoredReaderState rs = mStoredStates[address] as MyStoredReaderState; clsReader reader = mClients[address] as clsReader; if (!reader.IsConnected) { reader.ConnectAndLogin(address, rs.commandPort, rs.userName, rs.password); } restoreReaderState(rs, ref reader); reader.Dispose(); } catch { } } } } }
private void addNewReader(MyStoredReaderState rs) { if (this.InvokeRequired) { object[] temp = { rs }; try { this.Invoke(new addNewReaderDlgt(addNewReader), temp); } catch (Exception ex) { Debug.WriteLine(ex.Message); } return; } else { bool found = false; foreach (TreeNode n in treeView1.Nodes) { if (n.Text == rs.readerAddress) { found = true; break; } } if (!found) { TreeNode[] nodeChildren = new TreeNode[3]; nodeChildren[0] = new TreeNode("Notify"); nodeChildren[1] = new TreeNode("TagStream"); nodeChildren[2] = new TreeNode("IOStream"); TreeNode node = new TreeNode(rs.readerAddress, nodeChildren); node.Tag = rs.readerAddress; miReadersCount++; treeView1.Nodes.Add(node); } lblReadersCount.Text = miReadersCount.ToString(); } }
private void btnAddReader_Click(object sender, EventArgs e) { AddReader dlg = new AddReader(); if (dlg.ShowDialog() != DialogResult.OK) { return; } string sIPaddress = dlg.txtAddress.Text.Trim(); string sPort = dlg.txtPort.Text; string sUsername = dlg.txtUsername.Text; string sPassword = dlg.txtPassword.Text; MyStoredReaderState rs = new MyStoredReaderState(); rs.readerAddress = sIPaddress; try { rs.commandPort = int.Parse(sPort); rs.userName = sUsername; rs.password = sPassword; lock (moCurrentReadersLock) { if (!mStoredStates.ContainsKey(sIPaddress)) { mStoredStates.Add(sIPaddress, rs); } else { mStoredStates[sIPaddress] = rs; } addNewReader(rs); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void connect(MyStoredReaderState myReaderState, ref clsReader reader) { if (myReaderState.userName == null) { myReaderState.userName = "******"; } if (myReaderState.password == null) { myReaderState.password = "******"; } lock (moCurrentReadersLock) { reader.ConnectAndLogin( myReaderState.readerAddress, myReaderState.commandPort, myReaderState.userName, myReaderState.password); } }
private void mDiscoverer_ReaderAdded(IReaderInfo data) { if (mStoredStates.ContainsKey(data.IPAddress)) { return; } MyStoredReaderState rs = new MyStoredReaderState(); rs.readerAddress = data.IPAddress; rs.commandPort = data.TelnetPort; rs.readerName = data.Name; lock (moCurrentReadersLock) { if (!mStoredStates.ContainsKey(data.IPAddress)) { mStoredStates.Add(data.IPAddress, rs); } addNewReader(rs); } }
private void restoreReaderState(MyStoredReaderState rs, ref clsReader reader) { try { reader.AutoMode = "Off"; } catch { } if (rs.notifyMode != null) { try { reader.NotifyMode = rs.notifyMode; } catch { } } if (rs.tagStreamMode != null) { try { reader.TagStreamMode = rs.tagStreamMode; } catch { } } if (rs.ioStreamMode != null) { try { reader.IOStreamMode = rs.ioStreamMode; } catch { } } if (rs.notifyTime != null) { try { reader.NotifyTime = rs.notifyTime; } catch { } } if (rs.notifyAddress != null) { try { reader.NotifyAddress = rs.notifyAddress; } catch { } } if (rs.tagStreamAddress != null) { try { reader.TagStreamAddress = rs.tagStreamAddress; } catch { } } if (rs.ioStreamAddress != null) { try { reader.IOStreamAddress = rs.ioStreamAddress; } catch { } } if (rs.notifyFormat != null) { try { reader.NotifyFormat = rs.notifyFormat; } catch { } } if (rs.tagStreamFormat != null) { try { reader.TagStreamFormat = rs.tagStreamFormat; } catch { } } if (rs.ioStreamFormat != null) { try { reader.IOStreamFormat = rs.ioStreamFormat; } catch { } } if (rs.tagListMillis != null) { try { reader.TagListMillis = rs.tagListMillis; } catch { } } if (rs.autoWaitOutput != null) { try { reader.AutoWaitOutput = rs.autoWaitOutput; } catch { } } if (rs.autoWorkOutput != null) { try { reader.AutoWorkOutput = rs.autoWorkOutput; } catch { } } if (rs.autoTrueOutput != null) { try { reader.AutoTrueOutput = rs.autoTrueOutput; } catch { } } if (rs.autoFalseOutput != null) { try { reader.AutoFalseOutput = rs.autoFalseOutput; } catch { } } if (rs.ioStreamKeepAliveTime != null) { try { reader.IOStreamKeepAliveTime = rs.ioStreamKeepAliveTime; } catch { } } if (rs.tagStreamKeepAliveTime != null) { try { reader.TagStreamKeepAliveTime = rs.tagStreamKeepAliveTime; } catch { } } if (rs.autoMode != null) { try { reader.AutoMode = rs.autoMode; } catch { } } }
private void saveReaderState(MyStoredReaderState myReaderState) { string sIPaddress = myReaderState.readerAddress; clsReader reader = null; lock (moCurrentReadersLock) { try { if (!mClients.ContainsKey(sIPaddress)) { reader = new clsReader(); connect(myReaderState, ref reader); if (!reader.IsConnected) { throw new Exception("Can't connect to the reader."); } string r = null; try { r = reader.TagStreamAddress; } catch { } if ((r != null) && (r.IndexOf("Error") == -1)) { myReaderState.tagStreamAddress = r; r = null; } try { r = reader.TagStreamMode; } catch { } if ((r != null) && (r.IndexOf("Error") == -1)) { myReaderState.tagStreamMode = r; r = null; } try { r = reader.IOStreamAddress; } catch { } if ((r != null) && (r.IndexOf("Error") == -1)) { myReaderState.ioStreamAddress = r; r = null; } try { r = reader.IOStreamMode; } catch { } if ((r != null) && (r.IndexOf("Error") == -1)) { myReaderState.ioStreamMode = r; r = null; } try { r = reader.NotifyAddress; } catch { } if ((r != null) && r.IndexOf("Error") == -1) { myReaderState.notifyAddress = r; r = null; } try { r = reader.NotifyMode; } catch { } if ((r != null) && r.IndexOf("Error") == -1) { myReaderState.notifyMode = r; r = null; } try { r = reader.NotifyTime; } catch { } if ((r != null) && r.IndexOf("Error") == -1) { myReaderState.notifyTime = r; r = null; } try { r = reader.NotifyFormat; } catch { } if ((r != null) && (r.IndexOf("Error") == -1)) { myReaderState.notifyFormat = r; r = null; } try { r = reader.TagStreamFormat; } catch { } if ((r != null) && (r.IndexOf("Error") == -1)) { myReaderState.tagStreamFormat = r; r = null; } try { r = reader.IOStreamFormat; } catch { } if ((r != null) && (r.IndexOf("Error") == -1)) { myReaderState.ioStreamFormat = r; r = null; } try { r = reader.TagListMillis; } catch { } if ((r != null) && (r.IndexOf("Error") == -1)) { myReaderState.tagListMillis = r; r = null; } try { r = reader.AutoWaitOutput; } catch { } if ((r != null) && (r.IndexOf("Error") == -1)) { myReaderState.autoWaitOutput = r; r = null; } try { r = reader.AutoWorkOutput; } catch { } if ((r != null) && (r.IndexOf("Error") == -1)) { myReaderState.autoWorkOutput = r; r = null; } try { r = reader.AutoTrueOutput; } catch { } if ((r != null) && (r.IndexOf("Error") == -1)) { myReaderState.autoTrueOutput = r; r = null; } try { r = reader.AutoFalseOutput; } catch { } if ((r != null) && (r.IndexOf("Error") == -1)) { myReaderState.autoFalseOutput = r; r = null; } try { r = reader.IOStreamKeepAliveTime; } catch { } if ((r != null) && (r.IndexOf("Error") == -1)) { myReaderState.ioStreamKeepAliveTime = r; r = null; } try { r = reader.TagStreamKeepAliveTime; } catch { } if ((r != null) && (r.IndexOf("Error") == -1)) { myReaderState.tagStreamKeepAliveTime = r; r = null; } try { r = reader.AutoMode; } catch { } if ((r != null) && (r.IndexOf("Error") == -1)) { myReaderState.autoMode = r; r = null; } mClients.Add(sIPaddress, reader); } } catch (Exception ex) { if (mClients.ContainsKey(sIPaddress)) { mClients.Remove(sIPaddress); } if ((reader != null) && (reader.IsConnected)) { reader.Dispose(); } } }// releasing lock }