コード例 #1
0
        //Back ground work-DoWork, execute command
        private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e)
        {
            int    i, j;
            string DelayTime;

            byte[] sendCommandBuf, responseBuf = new byte[16];
            RemainingCount = CommandCount;
            i = 0;
            j = 0;

            while (i < CommandList.Count)
            {
                //Execute delay function
                if (CommandList[i].Contains("d"))
                {
                    DelayTime = CommandList[i].Trim('d');
                    System.Threading.Thread.Sleep(Int32.Parse(DelayTime));
                    backgroundWorker2.ReportProgress(0, "-> delay " + DelayTime + "ms\r\n");
                }
                //Execute command function
                else
                {
                    sendCommandBuf = StringToByteArray(CommandList[i]);
                    responseBuf    = new byte[16];
                    backgroundWorker2.ReportProgress(0, ResponseCommand[j]);

                    Global.ENUM_CMD result = LakeChabotReader.MANAGED_ACCESS.Command_Test(sendCommandBuf, ref responseBuf);
                    RemainingCount--;

                    // Timeout
                    if (Global.ENUM_CMD.TIME_OUT == result)
                    {
                        backgroundWorker2.ReportProgress(0, "->" + "Time Out!" + "\r\n");
                        return;
                    }
                    // Result Error
                    else if (Global.ENUM_CMD.COMMAND_TEST != result)
                    {
                        backgroundWorker2.ReportProgress(0, "->" + "No Response!" + "\r\n");
                        return;
                    }
                    //Conpute the remaining command count
                    backgroundWorker2.ReportProgress(0, "->" + BitConverter.ToString(responseBuf, 0, responseBuf.Length).Replace("-", " ") + "\r\n");
                    j++;
                }
                i++;
            }
        }
コード例 #2
0
        // This event handler is where the time-consuming work is done.
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            byte[] sendCommandBuf = StringToByteArray(textBoxSendCommand.Text.Replace(" ", ""));
            byte[] responseBuf    = new byte[16];
            worker.ReportProgress(0, "");
            Global.ENUM_CMD result = LakeChabotReader.MANAGED_ACCESS.Command_Test(sendCommandBuf, ref responseBuf);

            if (Global.ENUM_CMD.TIME_OUT == result)
            {// Timeout
                worker.ReportProgress(0, "No Response!");
                return;
            }
            else if (Global.ENUM_CMD.COMMAND_TEST != result)
            {// Result Error
                worker.ReportProgress(0, "No Response!");
                return;
            }

            worker.ReportProgress(0, BitConverter.ToString(responseBuf, 0, responseBuf.Length).Replace("-", " "));
        }