Пример #1
0
        /// <summary>
        /// Entry point for application.
        /// Starts the user CLI loop
        /// </summary>
        /// <param name="args"></param>
        public static void Main(String[] args)
        {
            bool ConnectedToLabVIEW = true;

            BlackfinEngine engine = new BlackfinEngine();

            engine.StartEngine();

            Socket clientLabVIEW = null;

            try
            {
                // connect to the people counter dvice
                IPAddress  ipinet   = IPAddress.Parse("192.168.253.27");
                IPEndPoint endPoint = new IPEndPoint(ipinet, 4505);

                Console.WriteLine("Connecting to the device at " + ipinet.ToString());

                Socket skt = new Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                skt.Connect(endPoint);

                Blackfin        blackfin = new Blackfin();
                BlackfinConsole console  = new BlackfinConsole(blackfin);

                engine.AddNewCounterEndPoint(blackfin, skt, (bf, error, something, type) =>
                {
                    Console.WriteLine("Comms Error!");
                    if (type == BlackfinEngine.ConnectionErrorType.FATAL)
                    {
                        console.Disconnect();
                    }
                });

                Console.WriteLine("Device Connected.\n");
                console.DoConsoleCommandLoop(clientLabVIEW);
                //console.resetCounts(clientLabVIEW);
                engine.RemoveCounterEndPoint(blackfin);
                Console.WriteLine("Disconnected from device");
            }
            catch (Exception ex)
            {
                Console.WriteLine("error: ..." + ex.Message);
                Thread.Sleep(10000);
            }

            engine.ShutdownEngine();
        }
Пример #2
0
        /// <summary>
        /// Entry point for application.
        /// Starts the user CLI loop
        /// </summary>
        /// <param name="args"></param>
        public static void Main(String[] args)
        {
            bool ConnectedToLabVIEW = false;

            BlackfinEngine engine = new BlackfinEngine();

            engine.StartEngine();

            Socket clientLabVIEW = null;

            while (true)
            {
                if (!ConnectedToLabVIEW)
                {
                    try
                    {
                        // connect to labview TCP server
                        IPAddress  ipinet2   = IPAddress.Parse("127.0.0.1");
                        IPEndPoint endPoint2 = new IPEndPoint(ipinet2, 4619);

                        Console.WriteLine("Connecting to the LabVIEW at " + ipinet2.ToString());

                        clientLabVIEW = new Socket(endPoint2.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                        clientLabVIEW.Connect(endPoint2);
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Can not connect to the labVIEW! Re-trying in 10 seconds ...\n");
                        Thread.Sleep(10000);
                        continue;
                    }

                    Console.WriteLine("LabVIEW Connected.\n");
                    ConnectedToLabVIEW = true;
                }

                try
                {
                    // connect to the people counter dvice
                    IPAddress  ipinet   = IPAddress.Parse("192.168.50.60");
                    IPEndPoint endPoint = new IPEndPoint(ipinet, 4505);

                    Console.WriteLine("Connecting to the device at " + ipinet.ToString());

                    Socket skt = new Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                    skt.Connect(endPoint);

                    Blackfin        blackfin = new Blackfin();
                    BlackfinConsole console  = new BlackfinConsole(blackfin);

                    engine.AddNewCounterEndPoint(blackfin, skt, (bf, error, something, type) =>
                    {
                        Console.WriteLine("Comms Error!");
                        if (type == BlackfinEngine.ConnectionErrorType.FATAL)
                        {
                            console.Disconnect();
                        }
                    });

                    Console.WriteLine("Device Connected.\n");
                    console.DoConsoleCommandLoop(clientLabVIEW);
                    engine.RemoveCounterEndPoint(blackfin);
                    Console.WriteLine("Disconnected from device");
                }
                catch (Exception)
                {
                    Console.WriteLine("Can not connect to the Device! Re-trying in 10 seconds ...\n");
                    Thread.Sleep(10000);
                }
            }

            engine.ShutdownEngine();
        }