예제 #1
0
        private async void mainPage_Loaded(object sender, RoutedEventArgs e)
        {
            _console            = Console.GetInstance();
            _console.ConsoleBox = _textBoxConsole;
            _console.Init();

            SerialRaspberry raspberrySerial = SerialRaspberry.GetInstance();
            await raspberrySerial.Init("UART0");

            _camera       = Camera.GetInstance();
            _tcpIpManager = TcpIpManager.GetInstance();
            while (true)
            {
                try
                {
                    _captureElement.Source = _camera.CameraCapture;
                    break;
                }
                catch (COMException exception)
                {
                    await Task.Delay(1);
                }
            }

            _camera.StartSendingServiceAsync();
        }
예제 #2
0
        private void UdpTimerCallback(object state)
        {
            byte[]   dataSend = Encoding.ASCII.GetBytes("TEST");
            EndPoint ep       = new IPEndPoint(IPAddress.Broadcast, 0);

            _localUdpSocket.SendTo(dataSend, ep);
            byte[]   buffer         = new byte[256];
            EndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0);

            Flush();
            _localUdpSocket.ReceiveFrom(buffer, ref remoteEndPoint);
            string data = Encoding.ASCII.GetString(buffer);

            string[] parts = data.Split(_separator, StringSplitOptions.RemoveEmptyEntries);
            if (parts[0] == "Motor")
            {
                byte dirA, dirB, speedA, speedB, time1, time2;
                try
                {
                    dirA   = Convert.ToByte(parts[1]);
                    speedA = Convert.ToByte(parts[2]);
                    dirB   = Convert.ToByte(parts[3]);
                    speedB = Convert.ToByte(parts[4]);
                    int time = Convert.ToInt32(parts[5]);
                    time1 = (byte)(time / 0xff);
                    time2 = (byte)(time % 0xff);
                }
                catch (Exception e)
                {
                    Debug.WriteLine("Format error");
                    return;
                }
                SerialRaspberry st        = SerialRaspberry.GetInstance();
                byte[]          tempBytes = new byte[]
                {
                    0x01, dirA, speedA, dirB, speedB, time1, time2, 0xFF
                };
                st.Write(tempBytes);
            }
            else if (parts[0] == "Server")
            {
            }
            else
            {
                throw new LogicErrorException();
            }
        }
예제 #3
0
 public static SerialRaspberry GetInstance()
 {
     return(Instance ?? (Instance = new SerialRaspberry()));
 }