Exemplo n.º 1
0
        // This method is run when the mainboard is powered up or reset.
        void ProgramStarted()
        {
            //set display
            this.videoOut.SetDisplayConfiguration(VideoOut.Resolution.Vga800x600);
            //set glide
            window = GlideLoader.LoadWindow(Resources.GetString(Resources.StringResources.Form1));

            txtTime          = (GHI.Glide.UI.TextBlock)window.GetChildByName("txtTime");
            GvData           = (GHI.Glide.UI.DataGrid)window.GetChildByName("GvData");
            BtnReset         = (GHI.Glide.UI.Button)window.GetChildByName("BtnReset");
            txtMessage       = (GHI.Glide.UI.TextBlock)window.GetChildByName("TxtMessage");
            Glide.MainWindow = window;

            //setup grid
            //create grid column
            GvData.AddColumn(new DataGridColumn("Time", 200));
            GvData.AddColumn(new DataGridColumn("Temp", 200));
            GvData.AddColumn(new DataGridColumn("Humid", 200));
            GvData.AddColumn(new DataGridColumn("Light", 200));
            GvData.AddColumn(new DataGridColumn("Gas", 200));


            // Create a database in memory,
            // file system is possible however!
            myDatabase = new GHI.SQLite.Database();
            myDatabase.ExecuteNonQuery("CREATE Table Sensor" +
                                       " (Time TEXT, Temp DOUBLE,Humid DOUBLE,Light DOUBLE,Gas DOUBLE)");
            //reset database n display
            BtnReset.TapEvent += (object sender) =>
            {
                Counter = 0;
                myDatabase.ExecuteNonQuery("DELETE FROM Sensor");
                GvData.Clear();
                GvData.Invalidate();
            };

            //reset lora
            _restPort.Write(false);
            Thread.Sleep(1000);
            _restPort.Write(true);
            Thread.Sleep(1000);


            _loraSerial = new SimpleSerial(GHI.Pins.FEZSpiderII.Socket11.SerialPortName, 57600);
            _loraSerial.Open();
            _loraSerial.DataReceived += _loraSerial_DataReceived;
            //get version
            _loraSerial.WriteLine("sys get ver");
            Thread.Sleep(1000);
            //pause join
            _loraSerial.WriteLine("mac pause");
            Thread.Sleep(1500);
            //antena power
            _loraSerial.WriteLine("radio set pwr 14");
            Thread.Sleep(1500);
            //set device to receive
            _loraSerial.WriteLine("radio rx 0"); //set module to RX
            txtMessage.Text = "LORA-RN2483 setup has been completed...";
            txtMessage.Invalidate();
            window.Invalidate();
            //myDatabase.Dispose();
        }
Exemplo n.º 2
0
        void PrintToLCD(string message)
        {
            String[]  origin_names = null;
            ArrayList tabledata    = null;

            //cek message
            if (message != null && message.Length > 0)
            {
                try
                {
                    if (message == "Radio Error")
                    {
                        return;
                    }
                    var        obj    = Json.NETMF.JsonSerializer.DeserializeString(message) as Hashtable;
                    var        detail = obj["Data"] as Hashtable;
                    DeviceData data   = new DeviceData()
                    {
                        DeviceSN = obj["DeviceSN"].ToString()
                    };
                    data.Data = new DataSensor()
                    {
                        Gas = Convert.ToDouble(detail["Gas"].ToString()), Temp = Convert.ToDouble(detail["Temp"].ToString()), Humid = Convert.ToDouble(detail["Humid"].ToString()), Light = Convert.ToDouble(detail["Light"].ToString())
                    };
                    //update display
                    txtTime.Text    = DateTime.Now.ToString("dd/MMM/yyyy HH:mm:ss");
                    txtMessage.Text = "Data Reveiced Successfully.";
                    txtTime.Invalidate();
                    txtMessage.Invalidate();

                    var TimeStr = DateTime.Now.ToString("dd/MM/yy HH:mm");
                    //insert to db
                    var item = new DataGridItem(new object[] { TimeStr, data.Data.Temp, data.Data.Humid, data.Data.Light, data.Data.Gas });
                    //add data to grid
                    GvData.AddItem(item);
                    Counter++;

                    GvData.Invalidate();
                    window.Invalidate();

                    //add rows to table
                    myDatabase.ExecuteNonQuery("INSERT INTO Sensor (Time, Temp,Humid,Light,Gas)" +
                                               " VALUES ('" + TimeStr + "' , " + data.Data.Temp + ", " + data.Data.Humid + ", " + data.Data.Light + ", " + data.Data.Gas + ")");
                    window.Invalidate();
                    if (Counter > 13)
                    {
                        //reset
                        Counter = 0;
                        myDatabase.ExecuteNonQuery("DELETE FROM Sensor");
                        GvData.Clear();
                        GvData.Invalidate();
                    }

                    /*
                     * // Process SQL query and save returned records in SQLiteDataTable
                     * ResultSet result = myDatabase.ExecuteQuery("SELECT * FROM Sensor");
                     * // Get a copy of columns orign names example
                     * origin_names = result.ColumnNames;
                     * // Get a copy of table data example
                     * tabledata = result.Data;
                     * String fields = "Fields: ";
                     * for (int i = 0; i < result.ColumnCount; i++)
                     * {
                     *  fields += result.ColumnNames[i] + " |";
                     * }
                     * Debug.Print(fields);
                     * object obj;
                     * String row = "";
                     * for (int j = 0; j < result.RowCount; j++)
                     * {
                     *  row = j.ToString() + " ";
                     *  for (int i = 0; i < result.ColumnCount; i++)
                     *  {
                     *      obj = result[j, i];
                     *      if (obj == null)
                     *          row += "N/A";
                     *      else
                     *          row += obj.ToString();
                     *      row += " |";
                     *  }
                     *  Debug.Print(row);
                     * }
                     */
                }
                catch (Exception ex)
                {
                    txtMessage.Text = message + "_" + ex.Message + "_" + ex.StackTrace;
                    txtMessage.Invalidate();
                }
            }
        }