Esempio n. 1
0
        private static void Host_PostDistanceDeviceEncrypt(object sender, Chromium.Remote.Event.CfrV8HandlerExecuteEventArgs e)
        {
            try
            {
                string pwd          = e.Arguments[0].StringValue;
                string clientnumber = e.Arguments[1].StringValue;

                byte[] bys = PortAgreement.DistanceDeviceEncryption(clientnumber, pwd);
                SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, bys);
                ReceivedManager.SetReceivedFunction <DistanceDeviceEncrypt>();
            }
            catch (Exception ex)
            {
                Log4Helper.ErrorInfo(ex.Message, ex);
                ViewCallFunction.ViewAlert(ex.Message);
            }
        }
Esempio n. 2
0
 private void DeviceNewPwd()
 {
     byte[] bys = PortAgreement.DistanceDeviceEncryption(ClientNumber, NewPwd);
     SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, bys);
 }
Esempio n. 3
0
        private static void OnTimerEvent(object sender, ElapsedEventArgs e)
        {
            m_StartTimer = true;
            byte[] by = null;
            try
            {
                for (int i = 0; i < 3; i++)
                {
                    if (m_StopTimer)
                    {
                        return;
                    }
                    foreach (string portName in SearchSerialPort.SerialPortNames)
                    {
                        if (m_StopTimer)
                        {
                            return;
                        }

                        m_Over = false;
                        if (m_SerialPort == null)
                        {
                            m_SerialPort = SerialPortManager.CreateSerialPort();
                            m_SerialPort.DataReceived += SerialPortDataReceived;
                        }

                        m_SerialPort.PortName = portName;
                        try
                        {
                            m_SerialPort.BaudRate = WinApi.B19200;
                            m_SerialPort.Open();

                            if (!SerialPortManager.Device1.SerialPortDevice.IsOpen)
                            {
                                if (m_StopTimer)
                                {
                                    return;
                                }
                                try
                                {
                                    by = PortAgreement.DistanceDeviceEncryption(DefaultParams.DEVICEDEFAULTCLIENTNUMBER, DefaultParams.DEVICEDEFAULTPASSWORD);
                                    m_SerialPort.Write(by);

                                    bool ret = WaitResult(SerialPortManager.Device1);
                                    if (ret)
                                    {
                                        continue;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Log4Helper.ErrorInfo(ex.Message, ex);
#if DEBUG
                                    Console.WriteLine(ex.Message);
#endif
                                }
                            }

                            m_SerialPort.SetBaudRate(WinApi.B9600);
                            Thread.Sleep(50);

                            if (!SerialPortManager.Device2.SerialPortDevice.IsOpen)
                            {
                                int address = 1;
                                try
                                {
                                    for (int number = 1; number <= 50; number++)
                                    {
                                        address = number;
                                        if (m_StopTimer)
                                        {
                                            return;
                                        }
                                        by = PortAgreement.CorridorReadCardData(number);
                                        m_SerialPort.Write(by);
                                        Thread.Sleep(50);
                                        if (m_Over)
                                        {
                                            ReplaceSerialPort(SerialPortManager.Device2);
                                            break;
                                        }
                                    }

                                    if (m_Over)
                                    {
                                        continue;
                                    }
                                    bool ret = WaitResult(SerialPortManager.Device2);
                                    if (ret)
                                    {
                                        continue;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Log4Helper.ErrorInfo(ex.Message, ex);
#if DEBUG
                                    Console.WriteLine(ex.Message);
#endif
                                }
                                finally
                                {
                                    SerialPortManager.Device2Address = address;
                                }
                            }

                            m_SerialPort.Close();
                        }
                        catch
                        {
                            continue;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log4Helper.ErrorInfo(ex.Message, ex);
#if DEBUG
                Console.WriteLine(ex.Message);
#endif
            }
            finally
            {
                by = null;
                m_Validation.Dispose();
                if (m_SerialPort != null && m_SerialPort.IsOpen)
                {
                    m_SerialPort.Close();
                }
                m_SerialPort = null;
                if (!m_StopTimer && (!SerialPortManager.Device1.SerialPortDevice.IsOpen && !SerialPortManager.Device2.SerialPortDevice.IsOpen))
                {
                    ViewCallFunction.ViewConnectionFailedMessage();
                }
                m_StartTimer = false;
            }
        }