コード例 #1
0
        /// <summary>
        /// �ڲ����ڴ����շ��Ķ����߳�
        /// �����ڲ�ʵ��ͬ���շ�
        /// </summary>
        private void DealwithCommunicationRoute()
        {
            while (!_StopTheadFlag)
            {
                if (_DataBlockQueue.QueueLength == 0)
                {
                    Thread.Sleep(20);
                    continue;
                }

                FxCommandArgs arg = _DataBlockQueue.Pick();
                if (arg == null)
                {
                    continue;
                }

                FxCommandResponse result = _SerialDeamon.Send(arg.ChannelNo, arg.Data, arg.Data.Length);

                if (result.ResultCode == ResultCodeConst.rcFailt)
                {
                    // �������ʧ�ܣ����ۼ���ʧ��ʱ�䣬����E�ʱֵ����Ҫ��UI�������з���
                    if (DateTime.Now.Subtract(_FirstFailtTime).TotalSeconds > 30)
                    {
                        _FirstFailtTime = DateTime.Now;
                    }
                    else if (_FirstFailtTime == DateTime.MaxValue)
                    {
                        _FirstFailtTime = DateTime.Now;
                    }
                }
                else if (result != null)
                {
                    _FirstFailtTime = DateTime.MaxValue;

                    switch (arg.Cmd)
                    {
                    case 1:                                                         // �����...
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                }

                if (_WaitHandle != null)
                {
                    arg.Result = result;
                    _WaitHandle.Set();
                }

                //if (arg.OnSendHandle != null) {
                //    arg.OnSendHandle.OnPackageRecived(result);
                //}
            }
            System.Diagnostics.Debug.Assert(false, "�˳��߳��ˣ���");
            _Thead = null;
        }
コード例 #2
0
        /// <summary>
        /// ͬ������ÁE������ȴ�����
        /// �����ڲ�ʵ�ַ��Ͷ��С��Լ���ʱ����
        /// </summary>
        /// <param name="response">ÁE���</param>
        /// <param name="channelNo">ͨ���ţ�Ĭ��0</param>
        /// <param name="cmdData">ÁE����ݣ��� 0xAA,0xCC,0x83 ��ͷ��byte[] </param>
        /// <param name="timeout">����ʱ�趨</param>
        public FxCommandResponse SendCall(short cmd, byte channelNo, byte[] cmdData, TimeSpan timeout)
        {
            if (cmdData == null)
            {                          // ���ÁE�߻�й�ԁE���Ĭ�Ϲ�ԁE޲�����ÁE�E				FxCommandResponse prm = new FxCommandResponse(ResultCodeConst.rcNotSettting, cmdData);
                //cmdData = _CommanderHelper.MakeSmart(response, targetPort, prm);
            }

            FxCommandArgs arg = new FxCommandArgs(cmd, cmdData, channelNo);

            return(SendCall(arg, timeout));
        }
コード例 #3
0
        /// <summary>
        /// 同步发送命令,并等待返回
        /// 函数内部实现发送队列、以及超时机制
        /// </summary>
        /// <param name="response">命令字</param>
        /// <param name="channelNo">通道号,默认0</param>
        /// <param name="cmdData">命令内容,以 0xAA,0xCC,0x83 开头的byte[] </param>
        /// <param name="timeout">最大超时设定</param>
        public FxCommandResponse SendCall(short cmd, byte channelNo, byte[] cmdData, TimeSpan timeout)
        {
            if (cmdData == null)                            // 如果命令没有构造,则默认构造无参数的命令
            {
                FxCommandResponse prm = new FxCommandResponse(ResultCodeConst.rcNotSettting, cmdData);
                //cmdData = _CommanderHelper.MakeSmart(response, targetPort, prm);
            }

            FxCommandArgs arg = new FxCommandArgs(cmd, cmdData, channelNo);

            return(SendCall(arg, timeout));
        }
コード例 #4
0
        /// <summary>
        /// ҁE�����ÁE�E		/// ������Ӧ��ʵ���� IDataPackageEvent�������ṩ����
        /// </summary>
        /// <param name="cmdArgs">������OnSendHandle��ԱӦ��Ϊ�հ�</param>
        /// <param name="onSendHandle">������Ҫ���û����ṩ�ص���E/param>
        //public void PostCall(CommandEventArgs cmdArgs, IDataPackageEvent onSendHandle)
        //{
        //    System.Diagnostics.Debug.Assert(onSendHandle != null, "�����߱�ЁE���IDataPackageEvent���ҽ����ô�ȁE�����");

        //    if (cmdArgs.OnSendHandle == null) cmdArgs.OnSendHandle = onSendHandle;
        //    _DataBlockQueue.Add(cmdArgs);
        //}

        /// <summary>
        /// ͬ������ÁE�E		/// </summary>
        /// <param name="cmdArgs">������OnSendHandle��Ա��ЁE�ֵΪ����������</param>
        public FxCommandResponse SendCall(FxCommandArgs cmdArgs, TimeSpan timeout)
        {
            if (cmdArgs == null)
            {
                return(null);
            }

            if (_WaitHandle == null)
            {
                _WaitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
            }

            _DataBlockQueue.Add(cmdArgs);

            _WaitHandle.WaitOne(timeout, true);
            _WaitHandle.Close();
            _WaitHandle = null;

            return(cmdArgs.Result);
        }
コード例 #5
0
 /// <summary>
 /// ҁE�����ÁE�E		/// ���ڷ��ͺ�Ͳ��ܵġ�ҁE�ÁE���
 /// </summary>
 /// <param name="cmdArgs">������OnSendHandle��ԱӦ��Ϊ�հ�</param>
 public void PostCall(FxCommandArgs cmdArgs)
 {
     _DataBlockQueue.Add(cmdArgs);
 }
コード例 #6
0
        /// <summary>
        /// ҁE�����ÁE��������̷���
        /// �����ڲ�ʵ�ַ��Ͷ��С��Լ���ʱ����
        /// </summary>
        /// <param name="response">ÁE���</param>
        /// <param name="cmdData">ÁE����ݣ��� 0xAA,0xCC,0x83 ��ͷ��byte[] </param>
        public void PostCall(short cmd, byte[] cmdData)
        {
            FxCommandArgs cmdArgs = new FxCommandArgs(cmd, cmdData);

            _DataBlockQueue.Add(cmdArgs);
        }