private void ReConn() { bool isSuc = false; using (Ping ping = new Ping()) { for (int i = 0; i < tryReconnNetTimeSpan * 60; i++) { PingReply pingReply = null; try { pingReply = ping.Send(reader.ConnString.Substring(0, reader.ConnString.IndexOf(':')), 1000);//超时为1秒 if (pingReply.Status != IPStatus.Success) { showMsg("Ping 不通"); continue; } else { isSuc = true; break; } } catch (Exception ex) { showMsg("尝试自动恢复连接失败!" + ex.Message); return; } } } //建立连接 if (isSuc) { isSuc = false; for (int i = 0; i < 3; i++)//尝试3次 { if (reader.Connect()) { showMsg("尝试自动恢复连接成功!"); changeCtrlEnable("conn"); isSuc = true; break; } else { Thread.Sleep(2000); continue; } } if (!isSuc) { showMsg("尝试自动恢复连接失败!"); } } }
void listener_OnClientConn(Socket socket, String pVer) { if (pVer == "IRP1") { IRP1.Reader reader = new IRP1.Reader(socket); if (reader.Connect()) { #region 激活天线 reader.Send(new IRP1.SysConfig_500(0x02, 0x01, new Byte[] { 0x01 }), 200); #endregion if (reader.IsConnected) { MyReader r = new MyReader(); r.reader = reader; if (r.reader.ProtocolVersion == "IRP1") { r.ScanMessage = new IRP1.ReadTag(IRP1.ReadTag.ReadMemoryBank.EPC_6C); r.StopMessage = new IRP1.PowerOff();//XC-RF502E-F6G } reader.OnMessageNotificationReceived += new MessageNotificationReceivedHandle(r_OnMessageNotificationReceived); ReaderList.Add(r); if (OnReaderClientConn != null) { OnReaderClientConn(r, EventArgs.Empty); } } } } }
// 建立连接 private void btnConn_Click(object sender, EventArgs e) { if (reader.Connect()) { changeCtrlEnable("conn"); //注册接收读写器消息事件 reader.OnMessageNotificationReceived += new Invengo.NetAPI.Core.MessageNotificationReceivedHandle(reader_OnMessageNotificationReceived); lblMsg.Text = "Connection Successful!"; } else { reader = new IRP1.Reader("Reader1", "RS232", this.comboBox1.Text + ",115200"); if (reader.Connect()) { changeCtrlEnable("conn"); //注册接收读写器消息事件 reader.OnMessageNotificationReceived += new Invengo.NetAPI.Core.MessageNotificationReceivedHandle(reader_OnMessageNotificationReceived); lblMsg.Text = "Connection Successful!"; } else { lblMsg.Text = "Connection Failed!"; MessageBox.Show("Failed to create the connection."); } } }
public static bool Connect() { bool blnvalue = false; if (reader.Connect()) { //注册接收读写器消息事件 reader.OnMessageNotificationReceived += new Invengo.NetAPI.Core.MessageNotificationReceivedHandle(reader_OnMessageNotificationReceived); blnvalue = true; } return(blnvalue); }
private void btn_Connect_Click(object sender, EventArgs e) { reader = new IRP1.Reader("Reader1", "TCPIP_Client", tbIPconnect.Text + ":7086"); //TCP msg = new IRP1.ReadTag(IRP1.ReadTag.ReadMemoryBank.EPC_6C); // { // Added MQTT COde string BrokerAddress = "localhost"; Topic = txtTopic.Text; if (Topic == "") { Topic = "rfidX"; } client = new MqttClient(BrokerAddress); clientId = Guid.NewGuid().ToString(); client.Connect(clientId); // subscribe to the topic with QoS 2 //client.Subscribe(new string[] { Topic }, new byte[] { 2 }); // we need arrays as parameters because we can subscribe to different topics with one call //return; // For Debugging if (reader.Connect()) { reader.OnMessageNotificationReceived += new Invengo.NetAPI.Core.MessageNotificationReceivedHandle(reader_OnMessageNotificationReceived); lbl_msg.Text = "Conn successful"; btn_Disconnect.Enabled = true; btn_Connect.Enabled = false; btn_ReadEPC.Enabled = true; changeCtrlEnable("conn"); //btnQuery.PerformClick(); //btnModelSN.PerformClick(); //btn_Query.PerformClick(); //btnAntQuery.PerformClick(); //btnQueryRF.PerformClick(); } else { lbl_msg.Text = "Conn failed"; MessageBox.Show("Conn failed"); } } }