Exemplo n.º 1
0
        private void frmCommands_Load(object sender, EventArgs e)
        {
            using (var ctx = new OLEDController())
            {
                //Fill the controllers dropdown
                var controllerResult = from row in ctx.Controllers
                                       select row;

                if (controllerResult.Count() == 0)
                {
                    //Add some sample values
                    //Add a controller
                    Controller sampleController;
                    sampleController = new Controller()
                    {
                        ControllerName = "SSD1805"
                    };
                    ctx.Controllers.Add(sampleController);

                    //Add a command
                    ControllerCommand sampleCommand = new ControllerCommand()
                    {
                        ControllerId = 0, CommandName = "GetID", CommandValue = 0x01
                    };
                    ctx.Commands.Add(sampleCommand);

                    //Add a parameter
                    CommandParameters sampleParameters;
                    sampleParameters = new CommandParameters()
                    {
                        CommandId = sampleCommand.CommandId, ParameterIndex = 0, ParameterValue = 15
                    };
                    ctx.Parameters.Add(sampleParameters);
                    sampleParameters = new CommandParameters()
                    {
                        CommandId = sampleCommand.CommandId, ParameterIndex = 1, ParameterValue = 26
                    };

                    sampleController = new Controller()
                    {
                        ControllerName = "SSD1322"
                    };
                    ctx.Controllers.Add(sampleController);

                    ctx.SaveChanges();
                }

                //Configure the dropdown boxes
                cmbController.DataSource    = ctx.Controllers.ToList();
                cmbController.ValueMember   = "ControllerId";
                cmbController.DisplayMember = "ControllerName";

                lbCommands.DataSource    = ctx.Commands.ToList();
                lbCommands.ValueMember   = "CommandId";
                lbCommands.DisplayMember = "CommandName";
            }
        }
Exemplo n.º 2
0
        private void cmdInsert_Click(object sender, EventArgs e)
        {
            using (var ctx = new OLEDController())
            {
                ControllerCommand newCommand = new ControllerCommand()
                {
                    CommandName = txtName.Text, CommandValue = Convert.ToInt32(txtCommand.Text), ControllerId = cmbController.SelectedIndex + 1
                };
                ctx.Commands.Add(newCommand);
                ctx.SaveChanges();

                if (txtParameters.Text != "")
                {
                    //Add each parameter, if listed
                    var parameterString = txtParameters.Text;

                    //Strip out spaces if any
                    parameterString.Replace(" ", string.Empty);

                    //Split the string into it's component parts
                    String[] splitStrings = parameterString.Split(',');

                    int currentIndex = 0;
                    foreach (var entry in splitStrings)
                    {
                        ctx.Parameters.Add(new CommandParameters()
                        {
                            CommandId = newCommand.CommandId, ParameterIndex = currentIndex++, ParameterValue = Convert.ToInt32(entry)
                        });
                    }
                    ctx.SaveChanges();
                }

                lbCommands.DataBindings.Clear();
                lbCommands.DataSource    = ctx.Commands.ToList();
                lbCommands.ValueMember   = "CommandId";
                lbCommands.DisplayMember = "CommandName";
            }
        }
Exemplo n.º 3
0
        private void Form1_Load(object sender, EventArgs e)
        {
            cmbBaud.Items.Clear();
            cmbBaud.Text = "Select a Baud Rate";
            cmbPort.Items.Clear();
            cmbPort.Text = "Select a Port";

            //Fill the port dropdown
            string[] ports = SerialPort.GetPortNames();
            // Display each port name to the console.
            foreach (string port in ports)
            {
                var thisPort = new SerialPort(port);
                if (!thisPort.IsOpen)
                {
                    cmbPort.Items.Add(port);
                }
                else
                {
                    cmbPort.Items.Add(port + " (In Use)");
                }
            }

            using (var ctx = new OLEDController())
            {
                //Fill the baud rate dropdown
                var baudResult = from row in ctx.BaudRates
                                 select row;

                if (baudResult.Count() == 0)
                {
                    //Let's add dummy Values
                    ctx.BaudRates.Add(new BaudRate()
                    {
                        Baud = 19200
                    });
                    ctx.BaudRates.Add(new BaudRate()
                    {
                        Baud = 115200
                    });
                    ctx.SaveChanges();
                    cmbBaud.Items.Add("19200");
                }
                else
                {
                    foreach (var item in baudResult)
                    {
                        cmbBaud.Items.Add(item.Baud);
                    }
                }
                //Fill the controllers dropdown
                var controllerResult = from row in ctx.Controllers
                                       select row;

                if (controllerResult.Count() == 0)
                {
                    //Add some sample values
                    //Add a controller
                    Controller sampleController;
                    sampleController = new Controller()
                    {
                        ControllerName = "SSD1805"
                    };
                    ctx.Controllers.Add(sampleController);
                    ctx.SaveChanges();

                    //Add a command
                    ControllerCommand sampleCommand = new ControllerCommand()
                    {
                        ControllerId = sampleController.ControllerId, CommandName = "GetID", CommandValue = 0x01
                    };
                    ctx.Commands.Add(sampleCommand);
                    ctx.SaveChanges();

                    //Add a parameter
                    CommandParameters sampleParameters;
                    sampleParameters = new CommandParameters()
                    {
                        CommandId = sampleCommand.CommandId, ParameterIndex = 0, ParameterValue = 15
                    };
                    ctx.Parameters.Add(sampleParameters);
                    ctx.SaveChanges();

                    sampleParameters = new CommandParameters()
                    {
                        CommandId = sampleCommand.CommandId, ParameterIndex = 1, ParameterValue = 26
                    };
                    ctx.Parameters.Add(sampleParameters);
                    ctx.SaveChanges();

                    sampleController = new Controller()
                    {
                        ControllerName = "SSD1322"
                    };
                    ctx.Controllers.Add(sampleController);
                    ctx.SaveChanges();
                }

                //Configure the dropdown boxes
                cmbController.DataSource    = ctx.Controllers.ToList();
                cmbController.ValueMember   = "ControllerId";
                cmbController.DisplayMember = "ControllerName";

                //                lbCommands.DataSource = ctx.Commands.ToList();
                //                lbCommands.ValueMember = "CommandId";
                //                lbCommands.DisplayMember = "CommandName";
            }
        }