Ejemplo n.º 1
0
        /// <summary>
        /// If TCP client receive data from server
        /// </summary>
        /// <param name="data"></param>
        private static void TcpListenTask(byte[] data)
        {
            string dataStr = Encoding.ASCII.GetString(data);

            string[] itemStrings = dataStr.Split(Separators, StringSplitOptions.RemoveEmptyEntries);
            if (itemStrings[0] == "Motor")
            {
                SerialManager tempSerialManager       = SerialManager.GetInstance();
                SerialManager.SerialPortWithGuid port = tempSerialManager.GetPort(RaspberrySerial.PortGuid);

                byte[] serialBytes = new byte[8];
                serialBytes[0] = 0x01;
                for (int i = 1; i < 5; i++)
                {
                    serialBytes[i] = Convert.ToByte(itemStrings[i]);
                }
                int time = Convert.ToInt32(itemStrings[5]);
                serialBytes[5] = (byte)(time / 256);
                serialBytes[6] = (byte)(time % 256);
                serialBytes[7] = 0xFF;
                port.Send(serialBytes);
            }
            else if (itemStrings[0] == "AcquirePicture")
            {
                SendPicture();
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            #region Camera
            RaspberryCamera tempCamera = RaspberryCamera.GetInstance();
            tempCamera.StartStreaming(pictureSize, fps);
            Console.WriteLine("Init Camera --- success");
            #endregion

            #region Init UDP manager

            Console.Write("Init UDP manager");
            UdpManager tempUdpManager = UdpManager.GetInstance();
            tempUdpManager.InitUdp(LocalUdpPort, InterNetwork.UdpListenTaskDelegate);
            Console.WriteLine(" --- success");

            #endregion

            #region Init Serial Manager

            Console.Write("Init SERIAL manager ");
            SerialManager tempSerialManager = SerialManager.GetInstance();
            while (true)
            {
                string[] ports    = SerialManager.GetAllVaildPorts();
                bool     signFind = false;
                foreach (string i in ports)
                {
                    if (i.Contains("USB"))
                    {
                        SerialManager.SerialPortWithGuid portWithGuid = tempSerialManager.Add(i, BaudRate, Parity.None, RaspberrySerial.TargetDataReceivedEventHandler);
                        RaspberrySerial.PortGuid = portWithGuid.Guid;
                        RaspberrySerial.StartReceive(portWithGuid.Serial);
                        Console.Write("Select" + i);
                        signFind = true;
                        break;
                    }
                }
                if (!signFind)
                {
                    Console.WriteLine("The system is waiting for a serial port device");
                    Thread.Sleep(1000);
                }
                else
                {
                    break;
                }
            }
            Console.WriteLine(" --- success");
            #endregion
            if (Debugger.IsAttached)
            {
                while (true)
                {
                    Thread.Sleep(1000);
                }
            }

            Console.ReadLine();
            tempCamera.StopStreaming();
            StateManager.GetInstance().FindServer = false;
            tempSerialManager.GetPort(RaspberrySerial.PortGuid).Serial.Dispose();
            Environment.Exit(0);
        }