Example #1
0
        /// <summary>
        /// 命令执行响应结果
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void cmd_ResponseHandle(object sender, ResponseEventArgs e)
        {
            CmdProtocol cmd = sender as CmdProtocol;
            if (null == cmd || string.IsNullOrEmpty(cmd.CmdId))
                return;

            MessageBox.Show(cmd.CmdId + "  " + basefun.valtag(cmd.ResponseFormat, "{状态}"));
        }
Example #2
0
 /// <summary>
 /// 射频读卡器响应句柄
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void cmdRFID_ResponseHandle(object sender, ResponseEventArgs e)
 {
     CommandBase cmd = sender as CommandBase;
     if (null == cmd || null == e || !e.Success || null == e.Response || e.Response.Length < 1)
         return;
     byte[] response = e.Response;
     int len = response.Length;
     if (0x02 != response[0] || 0x03 != response[len - 3] || 0x0A != response[len - 2] || 0x0D != response[len - 1])
         return;
     string str = CommandBase.Parse(response);
     if (str.Length < 13)
         return;
     this.rfID = str.Substring(1, 8);
 }
Example #3
0
        /// <summary>
        /// 触发事件
        /// </summary>
        /// <param name="arg"></param>
        public virtual void RaiseResponse(ResponseEventArgs arg)
        {
            EventHandler <ResponseEventArgs> handle = this.ResponseHandle;

            this.responseData = arg.Response;
            if (null != handle)
            {
                handle(this, arg);
            }
            if (null != this.eventWh)
            {
                this.eventWh.Set();
            }
        }
Example #4
0
 /// <summary>
 /// ���ش����¼�,������Ӧ��ʽ
 /// </summary>
 /// <param name="arg"></param>
 public override void RaiseResponse(ResponseEventArgs arg)
 {
     if (null == arg) return;
     this.fileheader.Clear();
     this.filecontext = new byte[0];
     if (arg.Response.Length < 1 || !arg.Success)
     {
         base.RaiseResponse(arg);
         return;
     }
     //����ļ�ͷ��Ϣ
     byte[] header = SvrFileTrans.GetFileheader(arg.Response);
     this.fileheader = SvrFileTrans.ParseInfo(header);
     if (arg.Response.Length > header.Length)
     {
         this.filecontext = new byte[arg.Response.Length - header.Length];
         Array.Copy(arg.Response, header.Length, this.filecontext, 0, this.filecontext.Length);
     }
     base.RaiseResponse(arg);
 }
Example #5
0
 /// <summary>
 /// 接收广播反馈,需要多次交互获取完整信息
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private static void cmd_RpsDoorHandle(object sender, ResponseEventArgs e)
 {
     if (null == sender || !(sender is CommandBase) || null == e || !e.Success || null == e.Response || e.Response.Length < 1)
         return;
     CommandBase cmd = sender as CommandBase;
     string rsl = CommandBase.Parse(cmd.ResponseData, true);
     //格式参数:普通/物理地址/IP地址/文本/数字
     string[] formatinfo ={ "功能码,3,2;",
                              "物理地址,5,6", "IP地址,11,4;子网掩码,15,4;网关IP,19,4;",
                              "",
                             "站址,1,2;工作端口,23,2;"};
     //读取信息列表
     List<string> infolist = new List<string>();
     if (null == cmd.Tag)
         cmd.Tag = infolist;
     infolist = cmd.Tag as List<string>;
     string info = parseDetail(rsl, "", formatinfo[0], formatinfo[1], formatinfo[2], formatinfo[3], formatinfo[4], true);
     infolist.Add(info);
 }
Example #6
0
 /// <summary>
 /// ���չ㲥����,��Ҫ��ν�����ȡ������Ϣ
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private static void cmd_RpsDoorHandle(object sender, ResponseEventArgs e)
 {
     if (null == sender || !(sender is CommandBase) || null == e || !e.Success || null == e.Response || e.Response.Length < 1)
         return;
     CommandBase cmd = sender as CommandBase;
     string rsl = CommandBase.Parse(cmd.ResponseData, true);
     //��ʽ��������ͨ/�����ַ/IP��ַ/�ı�/����
     string[] formatinfo ={ "������,3,2;",
                              "�����ַ,5,6", "IP��ַ,11,4;��������,15,4;����IP,19,4;",
                              "",
                             "վַ,1,2;�����˿�,23,2;"};
     //��ȡ��Ϣ�б�
     List<string> infolist = new List<string>();
     if (null == cmd.Tag)
         cmd.Tag = infolist;
     infolist = cmd.Tag as List<string>;
     string info = parseDetail(rsl, "", formatinfo[0], formatinfo[1], formatinfo[2], formatinfo[3], formatinfo[4], true);
     infolist.Add(info);
 }
Example #7
0
 /// <summary>
 /// ��Ӧ����,Ѳ��
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void CmdCard_ResponseHandle(object sender, ResponseEventArgs e)
 {
     this.stateresponse = (null == e || !e.Success) ? "ͨѶ�ж�" : "";
     if (null == sender || null == e || !e.Success || !(sender is CmdCard))
         return;
     CmdCard card = sender as CmdCard;
     if (0 == card.stateChecking)
         return;
     string tag = card.ResponseFormat;
     string cardid = basefun.valtag(tag, "{����}");
     string state = basefun.valtag(tag, "{״̬}");
     if (card.cardid == cardid)
     {
         if (!string.IsNullOrEmpty(cardid))
             card.tmIDcache.Change(3000, Timeout.Infinite);
         return;
     }
     if (string.IsNullOrEmpty(cardid) && card.isCardIC)
     {
         card.cardnum = "";
         card.cardserno = "";
         card.cardid = cardid;
         return;
     } if (string.IsNullOrEmpty(cardid))
         return;
     card.cardid = cardid;
     card.tmIDcache.Change(3000, Timeout.Infinite);
     //ID���򿨺�/�������ͬ,IC����ȡд����
     if (card.isCardIC)
     {
         //��ȡ�����
         string data = card.ReadCardNum();
         card.cardnum = basefun.valtag(data, "{�����}");
     }else
         card.cardnum = card.CardSID;
     card.cardserno = cardid;
     if (card.isCardIC)
         card.Buzz(true);
 }
Example #8
0
 /// <summary>
 /// 重载触发事件,解析响应格式
 /// </summary>
 /// <param name="arg"></param>
 public override void RaiseResponse(ResponseEventArgs arg)
 {
     if (null == arg) return;
     if (arg.Success)
         this.responseFormat = this.FormatResponse(arg.Response);
     else
         this.responseFormat = "";
     Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 解析:" + this.responseFormat);
     myLog.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 解析:" + this.responseFormat);
     base.RaiseResponse(arg);
 }
Example #9
0
 /// <summary>
 /// 重载触发事件,解析响应格式
 /// </summary>
 /// <param name="arg"></param>
 public override void RaiseResponse(ResponseEventArgs arg)
 {
     if (null == arg) return;
     this.fileheader.Clear();
     this.filecontext = new byte[0];
     if (arg.Response.Length < 1 || !arg.Success)
     {
         base.RaiseResponse(arg);
         return;
     }
     //检查文件头信息
     byte[] header = SvrFileTrans.GetFileheader(arg.Response);
     this.fileheader = SvrFileTrans.ParseInfo(header);
     if (arg.Response.LongLength > header.LongLength)
     {
         this.filecontext = new byte[arg.Response.LongLength - header.LongLength];
         Array.Copy(arg.Response, header.LongLength, this.filecontext, 0, this.filecontext.LongLength);
     }
     string msgrp = Encoding.GetEncoding("GB2312").GetString(header);
     Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 解析:" + msgrp);
     myLog.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 解析:" + msgrp);
     base.RaiseResponse(arg);
 }
Example #10
0
 /// <summary>
 /// 在当前没有执行指令响应时利用响应事件保存数据
 /// </summary>
 /// <param name="sender">事件指令实例</param>
 /// <param name="e"></param>
 private void execResponse(object sender, ResponseEventArgs e)
 {
     if (null == sender || null == e || !e.Success)
         return;
     CmdProtocol cmdP = sender as CmdProtocol;
     if (null == cmdP || 1 == this.stateChecking || this.isexecuting)
         return;
     string msg = cmdP.ResponseFormat;
     this.writeRecord(msg);
 }
Example #11
0
        /// <summary>
        /// 巡检响应,连续失败5分钟(tsbusy)则认为停机,间隔tsbusy巡检
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmdGather_ResponseHandle(object sender, ResponseEventArgs e)
        {
            if (null == sender || null == e || null == e.Response || e.Response.Length < 5)
                return;
            CmdProtocol cmdP = sender as CmdProtocol;
            if (null == cmdP || 0 == this.stateChecking)
                return;
            if (btcmd[0] != e.Response[3] || btcmd[1] != e.Response[4])
                return;
            if (!e.Success)
            {
                //连续长时间失败时,增大巡检周期
                if (cmdP.TimeSendInv < this.tsbusy && DateTime.Now - cmdP.ResponseDatetime > this.tsbusy)
                {
                    if (cmdP.TimeSendInv < this.tsbusy)
                        cmdP.TimeSendInv = this.tsbusy.Add(this.tsinv);
                }
                return;
            }
            string msg = cmdP.ResponseFormat;
            if (string.IsNullOrEmpty(msg) || "true" != basefun.valtag(msg, "Success"))
                return;
            //离线后恢复在线时,恢复巡检周期
            if (cmdP.TimeSendInv > this.tsbusy)
                cmdP.TimeSendInv = this.tsinv;
            msg = this.validateSate(msg);
            string sumstr = basefun.valtag(msg, "{刷卡记录数}");
            if (string.IsNullOrEmpty(sumstr))
                return;
            int sum = -1;
            int.TryParse(sumstr, out sum);
            if (sum > -1)
                this.sumRecord = sum;
            if (sum < 1) return;

            //加入采集队列
            Monitor.Enter(dvQueue);
            if (!dvQueue.Contains(this))
                dvQueue.Enqueue(this);
            Monitor.PulseAll(dvQueue);
            Monitor.Exit(dvQueue);
            hdlWh.Set();
            if (dtRunHdl < DateTime.Now.AddSeconds(-30))
                ThreadManager.QueueUserWorkItem(gatherData, null);
        }
Example #12
0
        /// <summary>
        /// Ѳ����Ӧ,����ʧ��5����(tsbusy)����Ϊͣ��,���tsbusyѲ��
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmdGather_ResponseHandle(object sender, ResponseEventArgs e)
        {
            if (null == sender || null == e)
                return;
            CmdProtocol cmdP = sender as CmdProtocol;
            if (null == cmdP || 0 == this.stateChecking)
                return;
            if (!e.Success)
            {
                //������ʱ��ʧ��ʱ������Ѳ������
                if (cmdP.TimeSendInv < this.tsbusy && DateTime.Now - cmdP.ResponseDatetime > this.tsbusy)
                {
                    if (cmdP.TimeSendInv < this.tsbusy)
                        cmdP.TimeSendInv = this.tsbusy.Add(this.tsinv);
                }
                return;
            }
            string msg = cmdP.ResponseFormat;
            if (string.IsNullOrEmpty(msg) || "true" != basefun.valtag(msg, "Success"))
                return;
            //���ߺ�ָ�����ʱ���ָ�Ѳ������
            if (cmdP.TimeSendInv > this.tsbusy)
                cmdP.TimeSendInv = this.tsinv;
            this.validateSate(msg);

            //2�����ڼ�¼������20��,���豸���ڷ�æ״̬,����ʱ�ɲɼ�
            string sumstr = basefun.valtag(msg, "{ˢ����¼��}");
            string dtstr = basefun.valtag(msg, "{ˢ��ʱ��}");
            if (string.IsNullOrEmpty(sumstr) || string.IsNullOrEmpty(dtstr))
                return;
            int sum = Convert.ToInt32(sumstr);
            DateTime dtcard = DateTime.MinValue;
            try { dtcard = Convert.ToDateTime(dtstr); }
            catch { }
            if ("���ڻ�" == this.devtype && this.posRecord > sum)
            {
                this.posRecord = 0;
                NameObjectList posps = new NameObjectList();
                posps["������"] = this.devid;
                this.query.ExecuteNonQuery("���ü�¼λ��", posps, posps, posps);
            }
            //�ж��Ƿ�æ״̬
            if (sum < 1 || (sum > 60 && DateTime.Now - dtcard < this.tsbusy))
                return;

            //���¼�¼�Ҳ���æʱ�ɲɼ��¼�¼50��
            string[] cols ={ "{����}", "״̬���", "������", "{ˢ��ʱ��}" };
            string tag = "@�豸��ַ=" + Convert.ToString(this.station);
            int st = this.stateChecking;
            this.reChecking(0);
            bool isreset = false;
            if (sum > 10 && DateTime.Now - dtcard > (this.tsbusy + this.tsbusy + this.tsbusy))
            {
                isreset = sum <= 50;
                sum = sum > 50 ? 51 : sum + 1;
            }
            else
            {
                isreset = sum <= 10;
                sum = sum > 10 ? 11 : sum + 1;
            }
            TimeSpan tswait = this.waitTime;
            for (int i = 0; i < sum; i++)
            {
                if ("���ڻ�" == this.devtype)
                    tag = basefun.setvaltag(tag, "{��¼����}", Convert.ToString(this.posRecord));
                cmdP.setCommand("�Ž�", "��ȡ��¼", tag);
                msg = getResponse(this.commimgr, e.Target, cmdP, tswait);
                if ("true" != basefun.valtag(msg, "Success"))
                    break;
                string cardnum = basefun.valtag(msg, "{����}");
                if (string.IsNullOrEmpty(cardnum) || "16777215" == cardnum || "0" == cardnum)
                {
                    this.posRecord++;
                    continue;
                }
                string info = "";
                for (int c = 0; c < cols.Length; c++)
                    info = basefun.setvaltag(info, cols[c], basefun.valtag(msg, cols[c]));
                info = basefun.setvaltag(info, "״̬", this.getStateDoorCard(basefun.valtag(info, "״̬���")));
                NameObjectList ps = ParamManager.createParam(info);
                ps["������"] = this.devid;
                ps["ʱ��"] = ps["ˢ��ʱ��"];
                bool success = this.query.ExecuteNonQuery("�ɼ��Ž�����", ps, ps, ps);
                if (!success)
                    ServiceTool.LogMessage(info, null, EventLogEntryType.Warning);
                DateTime dt = Convert.ToDateTime(ps["ˢ��ʱ��"]);
                this.AddRecord(info);
                DvRecordEventArgs arg = new DvRecordEventArgs(this.devid, this.station, dt, info);
                this.RaiseRecord(arg);
                if (!success)
                    break;
                this.posRecord++;
                //���һ����ȡ��¼
                if (i == sum - 1 && isreset && this.posRecord > 10000)
                {
                    cmdP.setCommand("�Ž�", "��ռ�¼", tag);
                    cmdP.ResetState();
                    this.commimgr.SendCommand(this.target, cmdP);
                    if (cmdP.EventWh.WaitOne(this.waitTime, false))
                    {
                        string suc = basefun.valtag(cmdP.ResponseFormat, "Success");
                        if ("true" == suc)
                            this.query.ExecuteNonQuery("���ü�¼λ��", ps, ps, ps);
                    }
                }
            }
            this.reChecking(st);
        }
Example #13
0
 /// <summary>
 /// 在当前没有执行指令响应时利用响应事件保存数据
 /// </summary>
 /// <param name="sender">事件指令实例</param>
 /// <param name="e"></param>
 private void execResponse(object sender, ResponseEventArgs e)
 {
     if (null == sender || null == e || !e.Success)
         return;
     CmdProtocol cmdP = sender as CmdProtocol;
     if (null == cmdP || 0 == this.stateChecking || this.isexecuting)
         return;
     string msg = cmdP.ResponseFormat;
     string suc = basefun.valtag(msg, "Success");
     string cardnum = basefun.valtag(msg, "{卡号}");
     if ("true" != suc || string.IsNullOrEmpty(cardnum) || "16777215" == cardnum || "0" == cardnum)
         return;
     Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 执行:" + msg);
     myLog.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 执行:" + msg);
     msg = writeRecord(msg, true);
     this.posRecord++;
 }
Example #14
0
        /// <summary>
        /// 巡检响应,连续失败5分钟(tsbusy)则认为停机,间隔tsbusy巡检
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmdGather_ResponseHandle(object sender, ResponseEventArgs e)
        {
            if (null == sender || null == e || null == e.Response || e.Response.Length < 5)
                return;
            CmdProtocol cmdP = sender as CmdProtocol;
            if (null == cmdP || 0 == this.stateChecking)
                return;
            if (btcmd[0] != e.Response[3] || btcmd[1] != e.Response[4])
                return;
            if (!e.Success)
            {
                //连续长时间失败时,增大巡检周期
                if (cmdP.TimeSendInv < this.tsbusy && DateTime.Now - cmdP.ResponseDatetime > this.tsbusy)
                {
                    if (cmdP.TimeSendInv < this.tsbusy)
                        cmdP.TimeSendInv = this.tsbusy.Add(this.tsinv);
                }
                return;
            }
            string msg = cmdP.ResponseFormat;
            if (string.IsNullOrEmpty(msg) || "true" != basefun.valtag(msg, "Success"))
                return;
            //触发事件
            if ("考勤机" != this.devtype)
            {
                string cardnum = basefun.valtag(msg, "{刷卡卡号}");
                string strdate = basefun.valtag(msg, "{刷卡时间}");
                if (cardnum != cardnumprev || strdate != strdateprev)
                {
                    if ("0001-1-1 00:00:00" != strdate && "16777215" != cardnum && "0" != cardnum && !string.IsNullOrEmpty(cardnum))
                    {
                        string msginfo = basefun.setvaltag("", "{卡号}", cardnum);
                        string[] cols ={ "{刷卡时间}", "状态编号", "读卡器" };
                        for (int i = 0; i < cols.Length; i++)
                            msginfo = basefun.setvaltag(msginfo, cols[i], basefun.valtag(msg, cols[i]));
                        writeRecord(msginfo, true);
                    }
                    cardnumprev = cardnum;
                    strdateprev = strdate;
                }
            }
            //离线后恢复在线时,恢复巡检周期
            if (cmdP.TimeSendInv > this.tsbusy)
                cmdP.TimeSendInv = this.tsinv;
            msg = this.validateSate(msg);
            string sumstr = basefun.valtag(msg, "{刷卡记录数}");
            if (string.IsNullOrEmpty(sumstr))
                return;
            int sum = -1;
            int.TryParse(sumstr, out sum);
            if (sum < 1) return;

            if ("考勤机" != this.devtype)
                return;
            //重置记录位置
            if (this.posRecord > sum + 10)
            {
                this.posRecord = 0;
                NameObjectList posps = new NameObjectList();
                posps["控制器"] = this.devid;
                try
                {
                    Monitor.Enter(objquery);
                    this.query.ExecuteNonQuery("重置记录位置", posps, posps, posps);
                }
                finally
                {
                    Monitor.PulseAll(objquery);
                    Monitor.Exit(objquery);
                }
            }
            //没有新记录
            if (sum < this.posRecord)
                return;

            //加入采集队列
            Monitor.Enter(dvQueue);
            if (!dvQueue.Contains(this))
                dvQueue.Enqueue(this);
            Monitor.PulseAll(dvQueue);
            Monitor.Exit(dvQueue);
            hdlWh.Set();
            if (dtRunHdl < DateTime.Now.AddSeconds(-30))
                ThreadManager.QueueUserWorkItem(gatherData, null);
        }
Example #15
0
 /// <summary>
 /// 有刷卡,读取卡信息
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void cmdP_ResponseHandle(object sender, ResponseEventArgs e)
 {
     CmdProtocol cmd = sender as CmdProtocol;
     if ("结束" == this.tagData || null == cmd)
         return;
     CommiTarget commipm = e.Target;
     string station = basefun.valtag(Convert.ToString(cmd.Tag), "设备地址");
     switch (commipm.ProtocolType)
     {
         case CommiType.TCP:
         case CommiType.UDP:
             string ip = commipm.SrvEndPoint.ToString();
             error[ip] = "通讯正常";
             if (!e.Success)
                 error[ip] = "通讯指令异常";
             break;
         case CommiType.SerialPort:
             string portname = commipm.PortName + ":" + station;
             error[portname] = e.Success ? "通讯正常" : "通讯指令异常";
             break;
     }
     if (!e.Success) return;
     if (!string.IsNullOrEmpty(cmd.ResponseFormat))
     {
         //开闸方式管理机开闸时咱停巡检,收费交互后重新启动
         string tag = cmd.ResponseFormat;
         if ("44" == basefun.valtag(tag, "{开闸方式}"))
         {
             //出入场时间相同则是入场,入场不限定
             string dtparkin = basefun.valtag(tag, "{入场时间}");
             string dtparkout = basefun.valtag(tag, "{出入场时间}");
             if (dtparkin != dtparkout)
             {
                 foreach (CommandBase c in this.cmdDevs)
                     c.TimeSendInv = new TimeSpan(365, 0, 0, 0);
             }
         }
         tagData = basefun.setvaltag(tag, "设备名称", cmd.CmdId);
     }
 }
Example #16
0
 /// <summary>
 /// 接收传递通讯
 ///     包含参数: len,dir=request/response,cmd=TransFile.trans,source,target,
 ///               CommiType,addr=ipaddr/COM1,port,baudRate,parity,dataBits,stopBits
 /// </summary>
 /// <param name="sender">触发事件的实例</param>
 /// <param name="e">响应参数</param>
 private static void onCommiTransHandle(object sender, ResponseEventArgs e)
 {
     CmdFileTrans trans = sender as CmdFileTrans;
     if (null == trans || null == e || null == e.Target)
         return;
     NameValueCollection ps = trans.FileHeader;
     byte[] data = trans.FileContext;
     if ("TransFile.trans" != ps["cmd"] || "request" != ps["dir"])
         return;
     if (string.IsNullOrEmpty(ps["CommiType"]) || string.IsNullOrEmpty(ps["addr"]))
         return;
     CommiType commitype = CommiType.SerialPort;
     string addr = ps["addr"];
     int port = -1;
     //检测地址
     try
     {
         addr = addr.ToUpper();
         if (!addr.StartsWith("COM"))
             commitype = (CommiType)Enum.Parse(typeof(CommiType), ps["CommiType"], true);
         if (!string.IsNullOrEmpty(ps["port"]))
             port = Convert.ToInt32(ps["port"]);
     }
     catch { return; }
     //检测通讯参数
     if (CommiType.SerialPort != commitype && port < 0)
         return;
     if (CommiType.SerialPort == commitype &&
         (string.IsNullOrEmpty(ps["baudRate"]) || string.IsNullOrEmpty(ps["parity"])
             || string.IsNullOrEmpty(ps["dataBits"]) || string.IsNullOrEmpty(ps["stopBits"])))
         return;
     //创建通讯目标
     CommiTarget target = null;
     if (CommiType.SerialPort != commitype)
         target = new CommiTarget(addr, port, commitype);
     else
         try
         {
             int baudRate = Convert.ToInt32(ps["baudRate"]);
             Parity parity = (Parity)Enum.Parse(typeof(Parity), ps["parity"], true);
             int databits = Convert.ToInt16(ps["dataBits"]);
             StopBits stopBits = (StopBits)Enum.Parse(typeof(StopBits), ps["stopBits"], true);
             target = new CommiTarget(addr, baudRate, parity, databits, stopBits);
         }
         catch { return; }
     target.setProtocol(Protocol.PTLCard);
     switch (ps["dtpl"])
     {
         case "停车场":
             target.setProtocol(Protocol.PTLPark); break;
         case "门禁":
             target.setProtocol(Protocol.PTLDoor); break;
         case "消费":
             target.setProtocol(Protocol.PTLEatery); break;
     }
     //执行传递的指令
     CmdProtocol cmd = new CmdProtocol(false);
     cmd.setCommand(data);
     ps["dir"] = "response";
     CommiManager.GlobalManager.SendCommand(target, cmd);
     if (!cmd.EventWh.WaitOne(800, false))
         ps["msg"] = "目标通讯超时失败";
     data = cmd.ResponseData;
     ps["len"] = data.LongLength.ToString();
     byte[] fh = SvrFileTrans.ParseInfo(ps);
     byte[] response = new byte[fh.LongLength + data.LongLength];
     Array.Copy(fh, response, fh.LongLength);
     if (data.Length > 0)
         Array.Copy(data, 0, response, fh.LongLength, data.LongLength);
     cmd.setCommand(response);
     CommiManager.GlobalManager.SendCommand(e.Target, cmd, true);
 }
        /// <summary>
        /// 停车场有刷卡,读取卡信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void cmdP_ResponseHandle(object sender, ResponseEventArgs e)
        {
            CmdProtocol cmd = sender as CmdProtocol;
            if ("结束" == this.tagData || null == cmd)
                return;

            CommiTarget commipm = e.Target;
            string tag = cmd.ResponseFormat;

            Debug.WriteLine("返回:" + tag);
            string ErrorInfo = CommErrorInfo(tag);
            string station = basefun.valtag(Convert.ToString(cmd.Tag), "设备地址");
            switch (commipm.ProtocolType)
            {
                case CommiType.TCP:
                case CommiType.UDP:
                    string ip = commipm.SrvEndPoint.ToString();
                    error[ip] = "通讯正常";
                    if (!string.IsNullOrEmpty(ErrorInfo))
                        error[ip] = ErrorInfo;
                    break;
                case CommiType.SerialPort:
                    string portname = commipm.PortName + ":" + station;
                    error[portname] = string.IsNullOrEmpty(ErrorInfo) ? "通讯正常" : ErrorInfo;
                    break;
            }
            string recordCount = basefun.valtag(tag, "{新记录}");

            if (recordCount == "0" || string.IsNullOrEmpty(recordCount)) return;
            string cardnum = "";

            CardMoney = cardnum;
            if ("0" != recordCount)
            {
                // Thread.Sleep(200);
                string tpl = "停车场", cmdNextName = "收集下一条记录";
                CmdProtocol cmdNext = new CmdProtocol(false);
                tag = basefun.setvaltag(tag, "设备地址", station);
                cmdNext.setCommand(tpl, cmdNextName, tag);
                CommiManager.GlobalManager.SendCommand(e.Target, cmdNext);
                if (cmdNext.EventWh.WaitOne(800, false))
                {
                    tag = cmdNext.ResponseFormat;
                    tag = basefun.setvaltag(tag, "操作类别", "进出场管理");
                    tag = basefun.setvaltag(tag, "设备名称", cmd.CmdId);
                    cardnum = basefun.valtag(tag, "{卡号}");
                    string carnum = basefun.valtag(tag, "{车牌号码}");
                    if (string.IsNullOrEmpty(carnum.Replace("0", "")))
                        tag = basefun.setvaltag(tag, "{车牌号码}", "");
                }
            }
            NameObjectList ps = new NameObjectList();
            ps["卡号"] = cardnum;
            Debug.WriteLine(DateTime.Now.ToString("mm:ss.ffff") + "卡号" + cardnum);
            //用Query处理异常
            //   DataTable tab = this.Query.getTable("获得卡信息", ps);
            DataTable tab = getDate(cardnum);
            if (null == tab || tab.Rows.Count < 1)
                return;
            Debug.WriteLine(DateTime.Now.ToString("mm:ss.ffff") + "tab记录" + tab.TableName);
            DataRow dr = tab.Rows[0];
            foreach (DataColumn c in tab.Columns)
            {
                string fld = c.ColumnName;
                string val = basefun.valtag(tag, "{" + fld + "}");
                string val2 = basefun.valtag(tag, fld);
                if (string.IsNullOrEmpty(val) && !string.IsNullOrEmpty(val2))
                    basefun.setvaltag(tag, "{" + fld + "}", val2);
                if (!string.IsNullOrEmpty(val) || !string.IsNullOrEmpty(val2))
                    continue;
                val = Convert.ToString(dr[c]);
                if (string.IsNullOrEmpty(val))
                    continue;
                tag = basefun.setvaltag(tag, "{" + fld + "}", val);
            }
            string strNow = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            if (string.IsNullOrEmpty(basefun.valtag(tag, "{入场时间}")))
                tag = basefun.setvaltag(tag, "{入场时间}", strNow);
            if (string.IsNullOrEmpty(basefun.valtag(tag, "{出入场时间}")))
                tag = basefun.setvaltag(tag, "{出入场时间}", strNow);
            if (string.IsNullOrEmpty(basefun.valtag(tag, "{出场时间}")))
                tag = basefun.setvaltag(tag, "{出场时间}", basefun.valtag(tag, "{出入场时间}"));
            tag = basefun.setvaltag(tag, "操作类别", "进出场管理");
            tagData = tag;
        }
Example #18
0
 /// <summary>
 /// 重载触发事件,解析响应格式
 /// </summary>
 /// <param name="arg"></param>
 public override void RaiseResponse(ResponseEventArgs arg)
 {
     if (null == arg) return;
     if (arg.Success)
         this.responseFormat = this.FormatResponse(arg.Response);
     else
         this.responseFormat = "";
     base.RaiseResponse(arg);
 }
Example #19
0
 /// <summary>
 /// 响应请求,巡检
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void CmdCard_ResponseHandle(object sender, ResponseEventArgs e)
 {
     this.stateresponse = (null == e || !e.Success) ? "通讯中断" : "";
     if (null == sender || null == e || !e.Success || !(sender is CmdCard))
         return;
     CmdCard card = sender as CmdCard;
     if (0 == card.stateChecking)
         return;
     string tag = card.ResponseFormat;
     string cardid = basefun.valtag(tag, "{卡号}");
     if (!string.IsNullOrEmpty(cardid))
         sumempty = 0;
     else if (!this.isEmpty)
         sumempty++;
     if (string.IsNullOrEmpty(cardid) && string.IsNullOrEmpty(card.cardid) && string.IsNullOrEmpty(card.cardnum))
         return;
     if (this.isEmpty)
     {
         card.tmIDcache.Change(0, Timeout.Infinite);
         return;
     }
     if (string.IsNullOrEmpty(cardid))
         return;
     if (card.cardid == cardid && !string.IsNullOrEmpty(card.cardnum))
         return;
     //ID卡则卡号/卡编号相同,IC卡读取写入编号
     //读取卡编号
     bool isbuzz = card.cardid != cardid;
     if (!card.isCardIC)
         card.cardnum = card.CardSID;
     else
     {
         string data = card.ReadCardNum();
         card.cardnum = basefun.valtag(data, "{卡编号}");
     }
     card.cardid = cardid;
     card.cardserno = cardid;
     if (card.isCardIC && isbuzz)
         card.Buzz(true);
 }
Example #20
0
 /// <summary>
 /// Ѳ����Ӧ,����ʧ��5����(tsbusy)����Ϊͣ��,���tsbusyѲ��
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void cmdGather_ResponseHandle(object sender, ResponseEventArgs e)
 {
     if (null == sender || null == e)
         return;
     CmdProtocol cmdP = sender as CmdProtocol;
     if (null == cmdP || 0 == this.stateChecking)
         return;
     if (!e.Success)
     {
         //������ʱ��ʧ��ʱ������Ѳ������
         if (cmdP.TimeSendInv < this.tsbusy && DateTime.Now - cmdP.ResponseDatetime > this.tsbusy)
         {
             if (cmdP.TimeSendInv < this.tsbusy)
                 cmdP.TimeSendInv = this.tsbusy.Add(this.tsinv);
         }
         return;
     }
     string msg = cmdP.ResponseFormat;
     if ("true" != basefun.valtag(msg, "Success"))
         return;
     //���ߺ�ָ�����ʱ���ָ�Ѳ������
     if (cmdP.TimeSendInv > this.tsbusy)
         cmdP.TimeSendInv = this.tsinv;
     //�����л�û���¼�¼,��
     string valwk = basefun.valtag(msg, "������");
     int sum = Convert.ToInt32(basefun.valtag(msg, "{�ɼ���־}"));
     if ("1" == valwk || sum < 1)
         this.dtwork = DateTime.Now;
     this.validateSate(msg);
     //���¼�¼�Ҳ���æʱ�ɲɼ��¼�¼50��
     if (sum < 1 || DateTime.Now - this.dtwork < tsbusy)
         return;
     string[] cols ={ "{����}", "{����}", "{����ʱ��}", "{���ѽ��}", "{�����}", "{�ۼƲ������}", "{���ѻ���}", "{����Ա��}" };
     string tag = "@�豸��ַ=" + Convert.ToString(this.station);
     this.reChecking(0);
     TimeSpan tswait = this.waitTime;
     for (int i = 0; i < 51; i++)
     {
         if(i<1)
             cmdP.setCommand("����", "ȡ��ǰ���Ѽ�¼", tag);
         else if(i<2)
             cmdP.setCommand("����", "ȡ��һ�����Ѽ�¼", tag);
         msg = getResponse(this.commimgr, this.target, cmdP, tswait);
         if ("true" != basefun.valtag(msg, "Success"))
             break;
         string cardnum = basefun.valtag(msg, "{����}");
         if (string.IsNullOrEmpty(cardnum) || "16777215" == cardnum || "0" == cardnum)
             continue;
         string info = "";
         for (int c = 0; c < cols.Length; c++)
             info = basefun.setvaltag(info, cols[c], basefun.valtag(msg, cols[c]));
         NameObjectList ps = ParamManager.createParam(info);
         ps["���ѻ�"] = this.devid;
         bool success = this.query.ExecuteNonQuery("�ɼ�����", ps, ps, ps);
         if (!success)
             ServiceTool.LogMessage(info, null, EventLogEntryType.Warning);
         DateTime dt = Convert.ToDateTime(ps["����ʱ��"]);
         this.AddRecord(info);
         DvRecordEventArgs arg = new DvRecordEventArgs(this.devid, this.station, dt, info);
         this.RaiseRecord(arg);
         if (!success)
             break;
     }
     this.reChecking(1);
 }
Example #21
0
 /// <summary>
 /// 巡检响应,连续失败5分钟(tsbusy)则认为停机,间隔tsbusy巡检
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void cmdGather_ResponseHandle(object sender, ResponseEventArgs e)
 {
     if (null == sender || null == e)
         return;
     CmdProtocol cmdP = sender as CmdProtocol;
     if (null == cmdP || 0 == this.stateChecking)
         return;
     if (!e.Success)
     {
         //连续长时间失败时,增大巡检周期
         if (cmdP.TimeSendInv < this.tsbusy && DateTime.Now - cmdP.ResponseDatetime > this.tsbusy)
         {
             if (cmdP.TimeSendInv < this.tsbusy)
                 cmdP.TimeSendInv = this.tsbusy.Add(this.tsinv);
         }
         return;
     }
     string msg = cmdP.ResponseFormat;
     if ("true" != basefun.valtag(msg, "Success"))
         return;
     //离线后恢复在线时,恢复巡检周期
     if (cmdP.TimeSendInv > this.tsbusy)
         cmdP.TimeSendInv = this.tsinv;
     //工作中或没有新记录,则
     string valwk = basefun.valtag(msg, "工作中");
     int sum = Convert.ToInt32(basefun.valtag(msg, "{采集标志}"));
     if ("1" == valwk || sum < 1)
         this.dtwork = DateTime.Now;
     this.validateSate(msg);
     //有新记录且不繁忙时可采集新记录50条
     if (sum < 1 || DateTime.Now - this.dtwork < tsbusy)
         return;
     //加入采集队列
     Monitor.Enter(dvQueue);
     if (!dvQueue.Contains(this))
         dvQueue.Enqueue(this);
     Monitor.PulseAll(dvQueue);
     Monitor.Exit(dvQueue);
     hdlWh.Set();
     if (dtRunHdl < DateTime.Now.AddSeconds(-30))
         ThreadManager.QueueUserWorkItem(gatherData, null);
 }
Example #22
0
        /// <summary>
        /// ���չ㲥����,��Ҫ��ν�����ȡ������Ϣ
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void cmd_ResponseHandle(object sender, ResponseEventArgs e)
        {
            if (null == sender || !(sender is CommandBase) || null == e || !e.Success || null == e.Response || e.Response.Length < 1)
                return;
            CommandBase cmd = sender as CommandBase;
            string rsl = CommandBase.Parse(cmd.ResponseData, true);
            //��鹦���룺�������ܣ���ȡ������Ϣ����ȡ��ϸ��Ϣ
            string codesearch  = "A1FD000922";
            string codedetailA = "A114010200";
            string codedetailB = "A114010202";
            string code = parseFunCode(rsl);
            string addr = parseAddrMac(rsl);
            if (codesearch != code && codedetailA != code && codedetailB != code)
                return;

            //��ʽ��������ͨ/�����ַ/IP��ַ/�ı�/����
            string[] formatinit ={ "������,10,4;", "�����ַ,4,6", "IP��ַ,17,4;", "", "" };
            string[] formatdtlA ={"������,10,4;", "�����ַ,4,6",
                                    "IP��ַ,47,4;��������,51,4;����IP,55,4;DNS������,59,4;",
                                    "�豸����,15,16;����,31,5;",
                                    "��ҳ�˿�,71,1;����˿�,72,2;"};
            string[] formatdtlB ={ "������,10,4;", "�����ַ,4,6", "","",
                                    "������ʽ,15,1;�����˿�,16,2;��ʱ�Ͽ�ʱ��,18,3;����ʱ��,21,1;������,26,3;����λ,29,1;ֹͣλ,30,1;У��λ,31,1;"};
            formatdtlB[4] += "�ְ�����,32,3;֡���,35,2;Ŀ��˿�1,47,2;Ŀ��˿�2,49,2;Ŀ��˿�3,51,2;Ŀ��˿�4,53,2;Ŀ��˿�5,55,2;Ŀ��˿�6,57,2;Ŀ��˿�7,59,2;Ŀ��˿�8,61,2;";

            //��ȡ��Ϣ�б�
            List<string> infolist = new List<string>();
            if (null == cmd.Tag)
                cmd.Tag = infolist;

            int index = -1;
            infolist = cmd.Tag as List<string>;
            for (int i = 0; i < infolist.Count; i++)
            {
                if (addr != basefun.valtag(infolist[i], "�����ַ"))
                    continue;
                index = i;
                break;
            }
            string info = "";
            if (index > -1)
                info = infolist[index];
            if (codesearch == code)
                info = parseDetail(rsl, info, formatinit[0], formatinit[1], formatinit[2], formatinit[3], formatinit[4], false);
            else if (codedetailA == code)
                info = parseDetail(rsl, info, formatdtlA[0], formatdtlA[1], formatdtlA[2], formatdtlA[3], formatdtlA[4], false);
            else if (codedetailB == code)
                info = parseDetail(rsl, info, formatdtlB[0], formatdtlB[1], formatdtlB[2], formatdtlB[3], formatdtlB[4], false);
            if (index > -1)
                infolist[index] = info;
            else
                infolist.Add(info);

            //���һ����ȡ��ϸ��Ϣ�����
            if (codedetailB == code)
                return;
            //�ٻ�ȡ������Ϣ������ȡ��ϸ��Ϣ
            IPEndPoint srv = new IPEndPoint(IPAddress.Broadcast, infoport);
            CommiTarget target = new CommiTarget(srv, CommiType.UDP);
            target.setProtocol(ptlZnet);
            string strcmd = string.Format(infocmd, addr.Replace("-", " "), codesearch == code ? "A114000200" : "A114000202");
            CommandBase cmdNext = new CommandBase();
            //ʹ����ͬ��ͬ���¼����ɶ�̬���UDP�����������
            cmdNext.EventWh = cmd.EventWh;
            cmdNext.Tag = cmd.Tag;
            cmdNext.ResponseHandle += new EventHandler<ResponseEventArgs>(cmd_ResponseHandle);
            cmdNext.IsResposeHandle = isResponseCmd;
            cmdNext.setCommand(strcmd, true);
            CommiManager.GlobalManager.SendCommand(target, cmdNext);
        }
Example #23
0
        /// <summary>
        /// 在当前没有执行指令响应时利用响应事件保存数据
        /// </summary>
        /// <param name="sender">事件指令实例</param>
        /// <param name="e"></param>
        private void execResponse(object sender, ResponseEventArgs e)
        {
            if (null == sender || null == e || !e.Success)
                return;
            CmdProtocol cmdP = sender as CmdProtocol;
            if (null == cmdP || 0 == this.stateChecking || this.isexecuting)
                return;
            string msg = cmdP.ResponseFormat;
            string suc = basefun.valtag(msg, "Success");
            string cardnum = basefun.valtag(msg, "{卡号}");
            string st = basefun.valtag(msg, "{状态}");
            if ("true" != suc || string.IsNullOrEmpty(cardnum) || "16777215" == cardnum || "0" == cardnum)
                return;
            string info = "";
            Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 执行:" + msg);
            myLog.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 执行:" + msg);
            string[] cols ={ "{卡号}", "{卡类}", "{消费时间}", "{消费金额}", "{卡余额}", "{累计补助金额}", "{消费机号}", "{操作员号}" };
            if ("补助机" == this.devName)
                cols = new string[] { "{卡号}", "{卡类}", "{充值时间}", "{本次补助金额}", "{补助后总额}" };
            for (int c = 0; c < cols.Length; c++)
                info = basefun.setvaltag(info, cols[c], basefun.valtag(msg, cols[c]));
            NameObjectList ps = ParamManager.createParam(info);
            ps["消费机"] = this.devid;
            DateTime dt = DateTime.MinValue;
            string fld = "补助机" == this.devName ? "充值时间" : "消费时间";
            try
            {
                dt = Convert.ToDateTime(ps[fld]);
            }
            catch { }
            if (dt < DateTime.Today.AddYears(-3) || dt > DateTime.Today.AddYears(3))
            {
                NameValueCollection datainfo = new NameValueCollection();
                datainfo["操作"] = "提取消费记录";
                datainfo["报文"] = CommandBase.Parse(cmdP.ResponseData, true);
                ServiceTool.LogMessage(msg, datainfo, EventLogEntryType.FailureAudit);
                if (null == dtobj) return;
                try { dt = Convert.ToDateTime(dtobj); }
                catch { return; }
                ps[fld] = dtobj;
            }
            else
                dtobj = ps[fld];
            bool success = false;
            if ("补助机" == this.devName)
                success = this.query.ExecuteNonQuery("消费接收补助", ps, ps, ps);
            else
                success = this.query.ExecuteNonQuery("采集数据", ps, ps, ps);

            if (!success)
                ServiceTool.LogMessage(info, null, EventLogEntryType.Warning);
        }
Example #24
0
        /// <summary>
        /// 接收广播反馈,需要多次交互获取完整信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void cmd_ResponseHandle(object sender, ResponseEventArgs e)
        {
            if (null == sender || !(sender is CommandBase) || null == e || !e.Success || null == e.Response || e.Response.Length < 1)
                return;
            CommandBase cmd = sender as CommandBase;
            string rsl = CommandBase.Parse(cmd.ResponseData, true);
            //检查功能码:搜索功能,获取网络信息,获取详细信息
            string codesearch  = "A1FD000922";
            string codedetailA = "A114010200";
            string codedetailB = "A114010202";
            string code = parseFunCode(rsl);
            string addr = parseAddrMac(rsl);
            if (codesearch != code && codedetailA != code && codedetailB != code)
                return;

            //格式参数:普通/物理地址/IP地址/文本/数字
            string[] formatinit ={ "功能码,10,5;", "物理地址,4,6", "IP地址,17,4;", "", "" };
            string[] formatdtlA ={"功能码,10,5;", "物理地址,4,6",
                                    "IP地址,47,4;子网掩码,51,4;网关IP,55,4;DNS服务器,59,4;",
                                    "设备名称,15,16;密码,31,5;",
                                    "网页端口,71,1;命令端口,72,2;"};
            string[] formatdtlB ={ "功能码,10,5;", "物理地址,4,6", "","",
                                    "工作方式,15,1;工作端口,16,2;超时断开时间,18,3;心跳时间,21,1;波特率,26,3;数据位,29,1;停止位,30,1;校验位,31,1;"};
            formatdtlB[4] += "分包长度,32,3;帧间隔,35,2;目标端口1,47,2;目标端口2,49,2;目标端口3,51,2;目标端口4,53,2;目标端口5,55,2;目标端口6,57,2;目标端口7,59,2;目标端口8,61,2;";

            //读取信息列表
            List<string> infolist = new List<string>();
            if (null == cmd.Tag)
                cmd.Tag = infolist;

            int index = -1;
            infolist = cmd.Tag as List<string>;
            for (int i = 0; i < infolist.Count; i++)
            {
                if (addr != basefun.valtag(infolist[i], "物理地址"))
                    continue;
                index = i;
                break;
            }
            string info = "";
            if (index > -1)
                info = infolist[index];
            if (codesearch == code)
                info = parseDetail(rsl, info, formatinit[0], formatinit[1], formatinit[2], formatinit[3], formatinit[4], false);
            else if (codedetailA == code)
                info = parseDetail(rsl, info, formatdtlA[0], formatdtlA[1], formatdtlA[2], formatdtlA[3], formatdtlA[4], false);
            else if (codedetailB == code)
                info = parseDetail(rsl, info, formatdtlB[0], formatdtlB[1], formatdtlB[2], formatdtlB[3], formatdtlB[4], false);
            if (index > -1)
                infolist[index] = info;
            else
                infolist.Add(info);

            //最后一步获取详细信息后结束
            if (codedetailB == code)
                return;
            //再获取网络信息,最后获取详细信息
            IPEndPoint srv = new IPEndPoint(IPAddress.Broadcast, infoport);
            CommiTarget target = new CommiTarget(srv, CommiType.UDP);
            target.setProtocol(ptlZnet);
            string strcmd = string.Format(infocmd, addr.Replace("-", " "), codesearch == code ? "A114000200" : "A114000202");
            CommandBase cmdNext = new CommandBase();
            //使用相同的同步事件,可动态检测UDP搜索反馈结果
            cmdNext.EventWh = cmd.EventWh;
            cmdNext.Tag = cmd.Tag;
            cmdNext.ResponseHandle += new EventHandler<ResponseEventArgs>(cmd_ResponseHandle);
            cmdNext.IsResposeHandle = isResponseCmd;
            cmdNext.setCommand(strcmd, true);
            CommiManager.GlobalManager.SendCommand(target, cmdNext);
        }
Example #25
0
 /// <summary>
 /// 触发事件
 /// </summary>
 /// <param name="arg"></param>
 public virtual void RaiseResponse(ResponseEventArgs arg)
 {
     EventHandler<ResponseEventArgs> handle = this.ResponseHandle;
     this.responseData = arg.Response;
     if (null != handle)
         handle(this, arg);
     if (null != this.eventWh)
         this.eventWh.Set();
 }
Example #26
0
 /// <summary>
 /// ��ˢ������ȡ����Ϣ
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void cmdP_ResponseHandle(object sender, ResponseEventArgs e)
 {
     CmdProtocol cmd = sender as CmdProtocol;
     if ("����" == this.tagData)
         return;
     if (!string.IsNullOrEmpty(cmd.ResponseFormat))
     {
         tagData = cmd.ResponseFormat;
         tagData = basefun.setvaltag(tagData, "�豸����", cmd.CmdId);
     }
 }
 /// <summary>
 /// ͣ������ˢ������ȡ����Ϣ
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void cmdP_ResponseHandle(object sender, ResponseEventArgs e)
 {
     CmdProtocol cmd = sender as CmdProtocol;
     if ("����" == this.tagData || null == cmd)
         return;
     CommiTarget commipm = e.Target;
     string tag = cmd.ResponseFormat;
     string ErrorInfo = CommErrorInfo(tag);
     string station = basefun.valtag(Convert.ToString(cmd.Tag), "�豸��ַ");
     switch (commipm.ProtocolType)
     {
         case CommiType.TCP:
         case CommiType.UDP:
             string ip = commipm.SrvEndPoint.ToString();
             error[ip] = "ͨѶ����";
             if (!string.IsNullOrEmpty(ErrorInfo))
                 error[ip] = ErrorInfo;
             break;
         case CommiType.SerialPort:
             string portname = commipm.PortName + ":" + station;
             error[portname] = string.IsNullOrEmpty(ErrorInfo) ? "ͨѶ����" : ErrorInfo;
             break;
     }
     string recordCount = basefun.valtag(tag, "{�¼�¼}");
     string cardnum = basefun.valtag(tag, "{����}");
     cardnum = "0" == cardnum ? "" : cardnum;
     if (string.IsNullOrEmpty(cardnum) && (string.IsNullOrEmpty(recordCount) || int.Parse(recordCount) <= 0))
         return;
     if (!string.IsNullOrEmpty(cardnum) && cardnum == CardMoney)
         return;
     CardMoney = cardnum;
     if ("0" != recordCount)
     {
         string tpl = "ͣ����", cmdNextName = "�ռ���һ����¼";
         CmdProtocol cmdNext = new CmdProtocol(false);
         tag = basefun.setvaltag(tag, "�豸��ַ", station);
         cmdNext.setCommand(tpl, cmdNextName, tag);
         CommiManager.GlobalManager.SendCommand(e.Target, cmdNext);
         if (cmdNext.EventWh.WaitOne(800, false))
         {
             tag = cmdNext.ResponseFormat;
             tag = basefun.setvaltag(tag, "�������", "����������");
             tag = basefun.setvaltag(tag, "�豸����", cmd.CmdId);
             cardnum = basefun.valtag(tag, "{����}");
             string carnum = basefun.valtag(tag, "{���ƺ���}");
             if (string.IsNullOrEmpty(carnum.Replace("0", "")))
                 tag = basefun.setvaltag(tag, "{���ƺ���}", "");
             Debug.WriteLine(DateTime.Now.ToString("ss.fff") + "   tag;" + tag + "  �¼�¼��" + recordCount);
         }
     }
     NameObjectList ps = new NameObjectList();
     ps["����"] = cardnum;
     DataTable tab = this.Query.getTable("��ÿ���Ϣ", ps);
     if (null == tab || tab.Rows.Count < 1)
         return;
     DataRow dr = tab.Rows[0];
     foreach (DataColumn c in tab.Columns)
     {
         string fld = c.ColumnName;
         string val = basefun.valtag(tag, "{" + fld + "}");
         string val2 = basefun.valtag(tag, fld);
         if (string.IsNullOrEmpty(val) && !string.IsNullOrEmpty(val2))
             basefun.setvaltag(tag, "{" + fld + "}", val2);
         if (!string.IsNullOrEmpty(val) || !string.IsNullOrEmpty(val2))
             continue;
         val = Convert.ToString(dr[c]);
         if (string.IsNullOrEmpty(val))
             continue;
         tag = basefun.setvaltag(tag, "{" + fld + "}", val);
     }
     string strNow = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
     if (string.IsNullOrEmpty(basefun.valtag(tag, "{�볡ʱ��}")))
         tag = basefun.setvaltag(tag, "{�볡ʱ��}", strNow);
     if (string.IsNullOrEmpty(basefun.valtag(tag, "{���볡ʱ��}")))
         tag = basefun.setvaltag(tag, "{���볡ʱ��}", strNow);
     if (string.IsNullOrEmpty(basefun.valtag(tag, "{����ʱ��}")))
         tag = basefun.setvaltag(tag, "{����ʱ��}", basefun.valtag(tag, "{���볡ʱ��}"));
     tag = basefun.setvaltag(tag, "�������", "����������");
     tagData = tag;
 }