Пример #1
0
        override public bool Connect(string ip, ref string errorMessage)
        {
            try
            {
                if (Connected)
                {
                    if (!Disconnect(ref errorMessage))
                    {
                        return(false);
                    }
                }

                reader = new ReaderAccessor(ip);

                if (reader.Connect())
                {
                    ipOrComport = ip;
                    Connected   = true;
                    return(true);
                }
                else
                {
                    errorMessage = String.Concat("連線失敗, IP : ", ip, ", ErrorCode : ", reader.LastErrorInfo.ToString());
                    return(false);
                }
            }
            catch (Exception ex)
            {
                errorMessage = String.Concat("連線失敗 : ", ex.ToString());
                return(false);
            }
        }
Пример #2
0
 /// <summary>
 /// 條碼讀取器連線,傳入條件:1.liveviewForm物件、2.readerAccessor物件、3.讀取器IP
 /// 回傳:成功:true、失敗:false
 /// </summary>
 /// <param name="liveviewForm">liveviewForm物件</param>
 /// <param name="readerAccessor">readerAccessor物件</param>
 /// <param name="ip">讀取器IP</param>
 /// <returns></returns>
 public static bool ReadConnect(LiveviewForm liveviewForm, ReaderAccessor readerAccessor, string ip)
 {
     liveviewForm.EndReceive();
     liveviewForm.IpAddress = readerAccessor.IpAddress = ip;
     liveviewForm.BeginReceive();
     return(readerAccessor.Connect());
 }
Пример #3
0
 /// <summary>
 /// 连接相机
 /// </summary>
 /// <param name="ip"></param>
 public void ConnectToCammera(string ip)
 {
     //Stop liveview.
     liveviewForm.EndReceive();
     //Set ip address of liveview.
     liveviewForm.IpAddress = ip;
     //Start liveview.
     liveviewForm.BeginReceive();
     //Set ip address of ReaderAccessor.
     m_reader.IpAddress = ip;
     //Connect TCP/IP.
     m_reader.Connect((data) =>
     {
         //Define received data actions here.Defined actions work asynchronously.
         //"ReceivedDataWrite" works when reading data was received.
         string camData = Encoding.ASCII.GetString(data);
         if (NewReaderDataEvent != null)
         {
             NewReaderDataEvent(camData, m_index);
         }
         //this.Dispatcher.BeginInvoke(new delegateUserControl(ReceivedDataWrite), Encoding.ASCII.GetString(data));
     });
 }
Пример #4
0
        static void Main(string[] args)
        {
            ReaderAccessor m_reader   = new ReaderAccessor();
            ReaderSearcher m_searcher = new ReaderSearcher();

            //LER ARGUMENTO
            try
            {
                string CodConfig = args[0].ToString();
                string Ipconfig  = args[1].ToString();
                //string CodConfig = "123456";
                //string Ipconfig = "192.168.100.1";

                string codComparacao = CodConfig;//Codigo de comparação
                Console.WriteLine("Enviar codigo para camera: " + codComparacao);

                //CONECTAR COM A CAMERA
                try
                {
                    //Stop liveview.
                    // liveviewForm1.EndReceive();
                    //Set ip address of liveview.
                    //liveviewForm1.IpAddress = Ipconfig;
                    ////Start liveview.
                    //liveviewForm1.BeginReceive();
                    ////Set ip address of ReaderAccessor.
                    m_reader.IpAddress = Ipconfig;
                    //Connect TCP/IP.
                    m_reader.Connect((data) =>
                    {
                        //Define received data actions here.Defined actions work asynchronously.
                        //"ReceivedDataWrite" works when reading data was received.
                        //BeginInvoke(new delegateUserControl(ReceivedDataWrite), Encoding.ASCII.GetString(data));
                    });

                    //TRANSFORMAR CODIGO E ENVIAR
                    try
                    {
                        //transf string em hex
                        codComparacao = toHex(CodConfig);
                        // Mandar código de comparacao
                        ReceivedDataWrite(m_reader.ExecCommand("WP,402," + codComparacao));
                        ReceivedDataWrite(m_reader.ExecCommand("SAVE"));
                        Console.WriteLine(String.Format("Código enviado..."));
                    }

                    catch (Exception ex2)
                    {
                        Console.WriteLine(String.Format("Não foi possível enviar o código de comparação!  Erro {0}/r/n", ex2.Message));
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(String.Format("Falha na comunicação!  Erro {0}/r/n", ex.Message));
                }
            }
            catch
            {
                Console.WriteLine(String.Format("Não há argumento para alterar o código!  Erro {0}/r/n"));
            }

            //FECHAR PORTA
            m_reader.CloseFtp();
            //Console.Clear();

            //Console.ReadKey();
        }