Exemplo n.º 1
0
        public RemoteControlForm()
        {
            InitializeComponent();

            MessageBuilder messageBuilder = new MessageBuilder();

            serialMessenger = new SerialMessenger(port, speed, messageBuilder);


            MessageBox.Show("Ready, Set, Go!", "Get Ready!", MessageBoxButtons.OK);

            readMessageTimer          = new Timer();
            readMessageTimer.Interval = 500;
            readMessageTimer.Tick    += new EventHandler(ReadMessageTimer_Tick);

            MessageBox.Show("Ready Set go!", "Get Ready", MessageBoxButtons.OK);

            try
            {
                serialMessenger.Connect();
                readMessageTimer.Enabled = true;
                Console.WriteLine("Connected!");
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }


            Console.WriteLine();
        }
Exemplo n.º 2
0
        public static void OnMessage(SerialMessenger sender, byte[] message, int offset, int length)
        {
            var str = new string(Encoder.GetChars(message, 0, length));

            Debug.Print(str);
            ReadTemp();
        }
Exemplo n.º 3
0
        public void Initialize(string comPort)
        {
            mes     = new SerialMessenger(comPort, "\n");
            ComPort = comPort;

            //Serial Port Options
            if (mes.Port.IsOpen)
            {
                mes.Port.Close();
            }
            mes.Port.PortName               = comPort;
            mes.Port.BaudRate               = 19200;
            mes.Port.Parity                 = Parity.None;
            mes.Port.DataBits               = 8;
            mes.Port.StopBits               = StopBits.One;
            mes.Port.RtsEnable              = false;
            mes.Port.DtrEnable              = false;
            mes.Port.Handshake              = Handshake.None;
            mes.Port.ReadTimeout            = 222;
            mes.Port.DiscardNull            = true;
            mes.Port.ReceivedBytesThreshold = 1;
            mes.Start();

            //Clear the line
            mes.SendMessage(0x03, (resp) => { });
        }
Exemplo n.º 4
0
        public void Initialize(string com)
        {
            mes     = new SerialMessenger(com, "\n");
            ComPort = com;

            //Serial Port Options
            if (mes.Port.IsOpen)
            {
                mes.Port.Close();
            }
            mes.Port.PortName               = com;
            mes.Port.BaudRate               = 19200;
            mes.Port.Parity                 = Parity.None;
            mes.Port.DataBits               = 8;
            mes.Port.StopBits               = StopBits.One;
            mes.Port.RtsEnable              = false;
            mes.Port.DtrEnable              = false;
            mes.Port.Handshake              = Handshake.None;
            mes.Port.ReadTimeout            = 222;
            mes.Port.WriteTimeout           = 222;
            mes.Port.DiscardNull            = true;
            mes.Port.ReceivedBytesThreshold = 1;
            mes.Start();

            GetCurrentDepthMM();
        }
Exemplo n.º 5
0
        public main()
        {
            InitializeComponent();
            MessageBuilder messageBuilder = new MessageBuilder('#', '%');

            serialMessenger = new SerialMessenger("COM5", 115200, messageBuilder);
            DataSet ds = db.GetData("SELECT * FROM user WHERE iduser = 1");

            if (!ds.GetXml().Contains("iduser"))
            {
                menuNav.SelectedIndex = 3;
            }
        }
Exemplo n.º 6
0
 public void Render(VirtualCanvas canvas, SerialMessenger M)
 {
     ComPort.Initialize();
     Joystick.Initialize(JoystickSocket, JoystickIRQHandler);
     canvas.SetOrientation(Orientation.Landscape);
     canvas.DrawFill((ushort)BasicColor.White);
     while (true)
     {
         var input = Joystick.Get();
         SendJoystickInput(input);
         DisplayJoystickInput(canvas, input.X, input.Y);
     }
 }
Exemplo n.º 7
0
        public void Render()
        {
            var SendContext = new BasicTypeSerializerContext();
            var ComPort     = new SerialMessenger();

            ComPort.Initialize();
            int contentSize = 0;

            BasicTypeSerializer.Put(SendContext, (UInt16)RGBLedDisplayCommand.RunDemo);
            var buffer = SendContext.GetBuffer(out contentSize);

            ComPort.Send(buffer, 0, (byte)contentSize);
            Thread.Sleep(1000);
            ComPort.Dispose();
        }
Exemplo n.º 8
0
        /// <summary>
        /// Is used to select the comm ports and create the serial messanger instances
        /// </summary>
        private void SerialMessangerCreationDialog()
        {
            ComPortSelector newDialog = new ComPortSelector();
            DialogResult    result    = newDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                MessageBuilder messageBuilder = new MessageBuilder('#', '%');

                serialMessengerlock = new SerialMessenger(newDialog.CommLock, 115200, messageBuilder);
                serialMessengerTv   = new SerialMessenger(newDialog.CommTv, 115200, messageBuilder);
            }
            else
            {
                //throw new Exception("DialogResult not OK");
                MessageBox.Show("DialogResult not OK");
                SerialMessangerCreationDialog();
            }
        }
Exemplo n.º 9
0
        public void Render(VirtualCanvas canvas)
        {
            var SendContext = new BasicTypeSerializerContext();
            var ComPort     = new SerialMessenger();

            ComPort.Initialize();
            canvas.SetOrientation(Orientation.Landscape);
            var text = canvas.TouchscreenShowDialog(DialogType.Alphanumeric);

            Debug.Print("User text: " + text);
            int contentSize = 0;

            BasicTypeSerializer.Put(SendContext, (UInt16)RGBLedDisplayCommand.DisplayMarquee);
            BasicTypeSerializer.Put(SendContext, text, true);
            var buffer = SendContext.GetBuffer(out contentSize);

            ComPort.Send(buffer, 0, (byte)contentSize);
            Thread.Sleep(1000);
            ComPort.Dispose();
        }
Exemplo n.º 10
0
 public void OnMessage(SerialMessenger sender, byte[] message, int offset, int length)
 {
 }
Exemplo n.º 11
0
        public void Render(VirtualCanvas canvas, Joystick Joystick)
        {
            canvas.SetOrientation(Orientation.Landscape);
            canvas.DrawFill(ColorHelpers.GetRGB24toRGB565(255, 255, 255));
            canvas.DrawString(80, 4, ColorHelpers.GetRGB24toRGB565(0, 0, 0), VerdanaBold14.ID, "Capture The Dot");
            canvas.DrawButton(
                32, 197,
                250, 36,
                VerdanaBold14.ID, 20,
                ColorHelpers.GetRGB24toRGB565(0, 0, 0),
                ColorHelpers.GetRGB24toRGB565(255, 255, 255),
                ColorHelpers.GetRGB24toRGB565(0, 0, 0),
                "Click To Exit",
                RoundedCornerStyle.All);
            canvas.Execute();

            var SendContext = new BasicTypeSerializerContext();
            var ComPort     = new SerialMessenger();

            ComPort.Messenger += OnMessage;
            ComPort.Initialize(bufferSize: 1024);

            int contentSize = 0;

            BasicTypeSerializer.Put(SendContext, (UInt16)RGBLedDisplayCommand.RunPong);
            var buffer = SendContext.GetBuffer(out contentSize);

            ComPort.Send(buffer, 0, (byte)contentSize);

            UInt16 LeftX      = 0;
            UInt16 RightY     = 0;
            UInt16 LastLeftX  = 1;
            UInt16 LastRightY = 1;

            canvas.Touch += TouchEventHandler;
            while (LastTouchIsValid == 0)
            {
                var joystickData = Joystick.Get();
                //Debug.Print("RawX: " + joystickData.X + ", RawY: " + joystickData.Y);

                LeftX  = (UInt16)MapRange(50, 950, 0, 15, joystickData.X);
                RightY = (UInt16)MapRange(50, 950, 0, 9, joystickData.Y);
                //Debug.Print("LeftX: " + LeftX + ", RightY: " + RightY);

                if (LeftX != LastLeftX || RightY != LastRightY)
                {
                    BasicTypeSerializer.Put(SendContext, (UInt16)RGBLedDisplayCommand.UpdateJoystick);
                    BasicTypeSerializer.Put(SendContext, (UInt16)LeftX);
                    BasicTypeSerializer.Put(SendContext, (UInt16)RightY);
                    buffer = SendContext.GetBuffer(out contentSize);
                    ComPort.Send(buffer, 0, (byte)contentSize);
                    Thread.Sleep(10);
                }
                canvas.TouchscreenWaitForEvent(TouchScreenEventMode.NonBlocking);
            }
            canvas.Touch      -= TouchEventHandler;
            ComPort.Messenger -= OnMessage;

            BasicTypeSerializer.Put(SendContext, (UInt16)RGBLedDisplayCommand.Reset);
            buffer = SendContext.GetBuffer(out contentSize);
            ComPort.Send(buffer, 0, (byte)contentSize);

            ComPort.Dispose();
        }
Exemplo n.º 12
0
        public void Render(VirtualCanvas canvas)
        {
            var SendContext = new BasicTypeSerializerContext();
            var ComPort     = new SerialMessenger();

            ComPort.Messenger += OnMessage;
            ComPort.Initialize(bufferSize: 1024);

            int contentSize = 0;

            BasicTypeSerializer.Put(SendContext, (UInt16)RGBLedDisplayCommand.Reset);
            var buffer = SendContext.GetBuffer(out contentSize);

            ComPort.Send(buffer, 0, (byte)contentSize);

            DrawPlayground(canvas);
            canvas.Touch += TouchEventHandler;
            var    exit = false;
            ushort r = 127, g = 0, b = 0;

            while (!exit)
            {
                LastTouchIsValid = 0;
                canvas.TouchscreenWaitForEvent(TouchScreenEventMode.NonBlocking);
                if (LastTouchIsValid != 0)
                {
                    if (LastTouchX >= 260 && LastTouchY >= 42 && LastTouchX <= 290 && LastTouchY <= 72)   // red
                    {
                        r         = 127;
                        g         = 0;
                        b         = 0;
                        LastColor = ColorHelpers.GetRGB24toRGB565(255, 0, 0);
                    }
                    else if (LastTouchX >= 260 && LastTouchY >= 77 && LastTouchX <= 290 && LastTouchY <= 107)   // green
                    {
                        r         = 0;
                        g         = 127;
                        b         = 0;
                        LastColor = ColorHelpers.GetRGB24toRGB565(0, 255, 0);
                    }
                    else if (LastTouchX >= 260 && LastTouchY >= 112 && LastTouchX <= 290 && LastTouchY <= 142)   // blue
                    {
                        r         = 0;
                        g         = 0;
                        b         = 127;
                        LastColor = ColorHelpers.GetRGB24toRGB565(0, 0, 255);
                    }
                    else if (LastTouchX >= 80 && LastTouchY >= 150 && LastTouchX <= 80 + 160 && LastTouchY <= 170)   // reset
                    {
                        canvas.DrawRectangleFilled(
                            79, 40,
                            241, 141,
                            ColorHelpers.GetRGB24toRGB565(255, 255, 255));
                        DrawGrid(canvas);
                        BasicTypeSerializer.Put(SendContext, (UInt16)RGBLedDisplayCommand.Reset);
                        buffer = SendContext.GetBuffer(out contentSize);
                        ComPort.Send(buffer, 0, (byte)contentSize);
                        Thread.Sleep(250);
                    }
                    else if (LastTouchX >= 80 && LastTouchY >= 42 && LastTouchX < 240 && LastTouchY < 140)   // canvas
                    {
                        var x = (LastTouchX - 80) / 10;
                        var y = (LastTouchY - 42) / 10;
                        if (LastSquareX != x || LastSquareY != y)
                        {
                            LastSquareX = x;
                            LastSquareY = y;
                            canvas.DrawRectangleFilled(80 + (x * 10) + 1, 42 + (y * 10) + 1, 80 + (x * 10) + 1 + 8, 42 + (y * 10) + 1 + 8, LastColor);
                            canvas.Execute();
                            BasicTypeSerializer.Put(SendContext, (UInt16)RGBLedDisplayCommand.SetPixel);
                            BasicTypeSerializer.Put(SendContext, (ushort)x);
                            BasicTypeSerializer.Put(SendContext, (ushort)y);
                            BasicTypeSerializer.Put(SendContext, r);
                            BasicTypeSerializer.Put(SendContext, g);
                            BasicTypeSerializer.Put(SendContext, b);
                            buffer = SendContext.GetBuffer(out contentSize);
                            ComPort.Send(buffer, 0, (byte)contentSize);
                        }
                    }
                    else if (LastTouchX >= 32 && LastTouchY >= 197 && LastTouchX <= 32 + 250 && LastTouchY <= 197 + 36)   // exit
                    {
                        exit = true;
                    }
                }
            }
            canvas.Touch -= TouchEventHandler;
            ComPort.Dispose();
        }
Exemplo n.º 13
0
 public void OnMessage(SerialMessenger sender, byte[] message, int offset, int length)
 {
     MessageReceivedEvent.Set();
 }
Exemplo n.º 14
0
        public void Render(VirtualCanvas canvas)
        {
            var Pot         = new NetduinoGo.Potentiometer(GoSockets.Socket1);
            var SendContext = new BasicTypeSerializerContext();
            var ComPort     = new SerialMessenger();

            ComPort.Messenger += OnMessage;
            ComPort.Initialize();

            int contentSize = 0;

            BasicTypeSerializer.Put(SendContext, (UInt16)RGBLedDisplayCommand.Reset);
            var buffer = SendContext.GetBuffer(out contentSize);

            MessageReceivedEvent.Reset();
            ComPort.Send(buffer, 0, (byte)contentSize);
            MessageReceivedEvent.WaitOne(100, true);

            DrawPlayground(canvas);
            canvas.Touch += TouchEventHandler;
            var exit = false;

            while (!exit)
            {
                LastTouchIsValid = 0;
                canvas.TouchscreenWaitForEvent(TouchScreenEventMode.NonBlocking);
                ushort color = Wheel((ushort)MapRange(0, 1, 0, 384, Pot.GetValue()));
                if (color != LastColor)
                {
                    LastColor = color;
                    canvas.DrawRectangleFilled(184, 153, 213, 179, LastColor);
                    canvas.Execute();
                }
                if (LastTouchIsValid != 0)
                {
                    if (LastTouchX >= 80 && LastTouchY >= 42 && LastTouchX < 240 && LastTouchY <= 140)
                    {
                        var x = (LastTouchX - 80) / 10;
                        var y = (LastTouchY - 42) / 10;
                        canvas.DrawRectangleFilled(80 + (x * 10) + 1, 42 + (y * 10) + 1, 80 + (x * 10) + 1 + 8, 42 + (y * 10) + 1 + 8, LastColor);
                        canvas.Execute();
                        BasicTypeSerializer.Put(SendContext, (UInt16)RGBLedDisplayCommand.SetPixel);
                        BasicTypeSerializer.Put(SendContext, (int)x);
                        BasicTypeSerializer.Put(SendContext, (int)y);
                        BasicTypeSerializer.Put(SendContext, (uint)LastColor);
                        buffer = SendContext.GetBuffer(out contentSize);

                        MessageReceivedEvent.Reset();
                        ComPort.Send(buffer, 0, (byte)contentSize);
                        MessageReceivedEvent.WaitOne(100, true);
                    }
                    else if (LastTouchX >= 32 && LastTouchY >= 197 && LastTouchX <= 32 + 250 && LastTouchY <= 197 + 36)
                    {
                        exit = true;
                    }
                }
            }
            canvas.Touch -= TouchEventHandler;
            ComPort.Dispose();
            Pot.Dispose();
        }