예제 #1
0
        private static void GetResult(string action)
        {
            try
            {
                Eclock   eclock        = new Eclock();
                string   serialPort    = eclock.GetPort();
                string[] ports         = SerialPort.GetPortNames();
                string   comPortNumber = "";
                string   rtype         = "";

                if (action == "TRAINING")
                {
                    rtype = "T";
                }

                foreach (var item in ports)
                {
                    if (serialPort.Contains(item))
                    {
                        comPortNumber = item;
                    }
                }

                SerialPort comPort = new SerialPort(comPortNumber, 9600, Parity.None, 8, StopBits.One);
                if (!String.IsNullOrEmpty(comPortNumber))
                {
                    DataPath = DataPath.Trim();
                    string entryDirectory = DataPath + "entry\\" + DateRelease;
                    string filepath       = entryDirectory + "\\" + MemberID + ".txt";

                    if (File.Exists(filepath))
                    {
                        string[] entryCollection = ReadText.ReadTextFile(filepath);

                        string resultDirectory = DataPath + "result\\" + DateRelease;
                        string memberDirectory = resultDirectory + "\\" + MemberID;
                        string filepathList    = resultDirectory + "\\" + MemberID + ".txt";

                        if (File.Exists(filepathList))
                        {
                            File.Delete(filepathList);
                        }

                        eclock.SendData("$Stat$", comPort);
                        System.Threading.Thread.Sleep(1000);

                        foreach (var item in entryCollection)
                        {
                            bool transmit = false;
                            while (!transmit)
                            {
                                //eclock.SendData(, comPort);
                                String inComingData = eclock.ReceiveDataResult("$Race$" + rtype + item + "#", comPort);
                                if (inComingData != "")
                                {
                                    PrintData(inComingData, item);
                                    //eclock.SendData("Done" + item + "#", commPort);
                                    transmit = true;
                                }
                            }
                        }

                        eclock.SendData("$Done$|#", comPort);
                    }
                }
                //Console.ReadLine();
                Console.WriteLine("Result Sync Completed....");
                System.Threading.Thread.Sleep(2000);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }