void __timer_Tick_getCommand(object sender, EventArgs e) { string url = RestUrl.getCommand; CommandProtocol cmd = new CommandProtocol(string.Empty, this.lastUpdateTimeStamp, string.Empty); string jsonString = fastJSON.JSON.Instance.ToJSON(cmd); __httpHelper.TryPostData(url, jsonString); }
private void 关闭读写器CToolStripMenuItem_Click(object sender, EventArgs e) { CommandProtocol cp = new CommandProtocol("close_reader2300", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "inventory"); //CommandProtocol cp = new CommandProtocol("close_rmu900", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "inventory"); string jsonString = fastJSON.JSON.Instance.ToJSON(cp); HttpWebConnect helper = new HttpWebConnect(); helper.RequestCompleted += new deleGetRequestObject(helper_RequestCompleted_addCommand); string url = RestUrl.addCommand; helper.TryPostData(url, jsonString); }
void helper_RequestCompleted_addCommand(object o) { string strProduct = (string)o; Debug.WriteLine( string.Format("frmMain.helper_RequestCompleted_addCommand-> response = {0}" , strProduct)); CommandProtocol u2 = fastJSON.JSON.Instance.ToObject <CommandProtocol>(strProduct); if (u2.state == "ok") { Debug.WriteLine( string.Format("frmMain.helper_RequestCompleted_addCommand -> = {0}" , "ok")); } else { Debug.WriteLine( string.Format("frmMain.helper_RequestCompleted_addCommand -> = {0}" , "failed")); } }
void commandDispose(CommandProtocol _cmd) { if (_cmd == null) { return; } if (string.Compare(this.lastUpdateTimeStamp, _cmd.timeStamp, true) < 0)//如果命令的时间较晚 { this.lastUpdateTimeStamp = _cmd.timeStamp; } switch (_cmd.command.ToLower().Trim()) { #region 之前处理命令的代码 case "open_rmu900": if (!this.flagList.Contains(_cmd.flag)) { this.flagList.Add(_cmd.flag); } this.lblStatus.Text = "接收到命令 " + _cmd.command + " " + _cmd.timeStamp + " flag = " + _cmd.flag; this.appendLog(this.lblStatus.Text); if (this.operaterGetTag == null) { operaterGetTag = new rfidOperateUnitInventoryTag(dataTransfer); operaterGetTag.registeCallback(new deleRfidOperateCallback(rfidCallback)); } operaterGetTag.OperateStart(); break; case "close_rmu900": if (this.flagList.Contains(_cmd.flag)) { this.flagList.Remove(_cmd.flag); } this.lblStatus.Text = "接收到命令 " + _cmd.command + " " + _cmd.timeStamp + " flag = " + _cmd.flag; this.appendLog(this.lblStatus.Text); if (null == this.operaterStopGetTag) { operaterStopGetTag = new rfidOperateUnitStopInventoryTag(dataTransfer); } this.operaterStopGetTag.OperateStart(); break; case "open_reader2300": if (!this.flagList.Contains(_cmd.flag)) { this.flagList.Add(_cmd.flag); } try { this.lblStatus.Text = "接收到命令 " + _cmd.command + " " + _cmd.timeStamp + " flag = " + _cmd.flag; this.appendLog(this.lblStatus.Text); //UdpConfig udpconfig = new UdpConfig(this.Controls, "UDP参数设置", null); //staticClass.iServePort = int.Parse(udpconfig.port); //staticClass.strServerIP = udpconfig.ip; //UDPServer.startUDPListening(); //清空之前的缓存 __udpServer.Manualstate.WaitOne(); __udpServer.Manualstate.Reset(); string str = __udpServer.sbuilder.ToString(); __udpServer.sbuilder.Remove(0, str.Length); __2300helper.clearTags(); __udpServer.Manualstate.Set(); __reader2300Timer.Enabled = true; } catch (Exception ex) { MessageBox.Show(ex.Message, "SGSServerUDP", MessageBoxButtons.OK, MessageBoxIcon.Error); } break; case "close_reader2300": if (this.flagList.Contains(_cmd.flag)) { this.flagList.Remove(_cmd.flag); } try { this.lblStatus.Text = "接收到命令 " + _cmd.command + " " + _cmd.timeStamp + " flag = " + _cmd.flag; this.appendLog(this.lblStatus.Text); __reader2300Timer.Enabled = false; //UDPServer.stopUDPListening(); } catch (Exception ex) { MessageBox.Show(ex.Message, "SGSServerUDP", MessageBoxButtons.OK, MessageBoxIcon.Error); } break; #endregion } }