예제 #1
0
        //------------------------------------------------------------------------------------------------------------------------
        #endregion

        #region Functions
        //------------------------------------------------------------------------------------------------------------------------
        public override bool Initialize(mNodeConfig mNodeConfig, string PluginConfig, string UserConfig)
        {
            //init base
            if (base.Initialize(mNodeConfig, PluginConfig, UserConfig) == false)
            {
                return(false);
            }

            //read config
            if (!string.IsNullOrWhiteSpace(PluginConfig))
            {
                try { Config = (PluginConfig ?? "").FromJSON <PluginConfig>(); } catch { Config = new PluginConfig(); }
            }


            //init
            try
            {
                SetupSerialPortThing();

                DebugEx.TraceLog("Successful start of DevelopmentTools plugin.");
            }
            catch (Exception ex) { DebugEx.Assert(ex, "Could not init"); }

            //done
            return(true);
        }
예제 #2
0
        //------------------------------------------------------------------------------------------------------------------------
        #endregion

        #region Functions
        //------------------------------------------------------------------------------------------------------------------------
        public override bool Initialize(mNodeConfig mNodeConfig, string PluginConfig, string UserConfig)
        {
            //init base
            if (base.Initialize(mNodeConfig, PluginConfig, UserConfig) == false)
            {
                return(false);
            }


            //initialize native system (threads etc)
            try
            {
                if (Native.Initialize(ThingKeyPrefix) != 0)
                {
                    DebugEx.TraceLog("Could not initialize native system");
                }
                else
                {
                    DebugEx.TraceLog("Initialized native system");

                    // Get things
                    var json   = Native.GetThings();
                    var things = json.FromJSON <List <Thing> >();
                    DebugEx.TraceLog($"Things:{things.Count} - {things[0].Name}");

                    // Fix keys
                    foreach (var t in things)
                    {
                        t.ThingKey = ThingKey.BuildFromArbitraryString("$NodeKey$", t.ThingKey);
                        foreach (var p in t.Ports)
                        {
                            p.PortKey = PortKey.BuildFromArbitraryString("$ThingKey$", p.PortKey);
                        }
                    }

                    // Add things
                    AddThing(things);


                    //start command retriver
                    isRunning = true;
                    CommandRetrieverThread = new Thread(commandRetrieverHeartbeatEntryPoint);
                    CommandRetrieverThread.IsBackground = true;
                    CommandRetrieverThread.Start();
                }
            }
            catch (Exception ex) { DebugEx.TraceError(ex, "Failed to init plugin"); return(false); }


            //init plugin
            DebugEx.TraceLog("C++11 Plugin up and running !! ");

            //done
            return(true);
        }
예제 #3
0
        //------------------------------------------------------------------------------------------------------------------------
        #endregion

        #region Functions
        //------------------------------------------------------------------------------------------------------------------------
        public override bool Initialize(mNodeConfig mNodeConfig, string PluginConfig, string UserConfig)
        {
            //init base
            if (base.Initialize(mNodeConfig, PluginConfig, UserConfig) == false)
            {
                return(false);
            }

            //run
            try
            {
                var result = so_calculate(4, 5);
                DebugEx.TraceLog("Calling .so native function 4+5=" + result);
            }
            catch (Exception ex) { DebugEx.TraceError(ex, "Could not call .so native fuction"); }

            //initialize native system (threads etc)
            try
            {
                if (initialize() != 0)
                {
                    DebugEx.TraceLog("Could not initialize native system");
                }
                else
                {
                    DebugEx.TraceLog("Initialized native system");

                    //start command retriver
                    isRunning = true;
                    CommandRetrieverThread = new Thread(commandRetrieverHeartbeatEntryPoint);
                    CommandRetrieverThread.IsBackground = true;
                    CommandRetrieverThread.Start();
                }
            }
            catch (Exception ex) { DebugEx.TraceError(ex, "Could not call .so native fuction"); }

            //init plugin
            DebugEx.TraceLog("Sample Plugin up and running !! ");

            //done
            return(true);
        }
예제 #4
0
파일: PluginMain.cs 프로젝트: sm6uax/plegma
        //------------------------------------------------------------------------------------------------------------------------
        #endregion

        #region Functions
        //------------------------------------------------------------------------------------------------------------------------
        public override bool Initialize(mNodeConfig mNodeConfig, string PluginConfig, string UserConfig)
        {
            YConfig   = Config.Init(PluginWorkingDirectory);
            ActiveCfg = YConfig.GetActiveConf();

            //init base
            if (base.Initialize(mNodeConfig, PluginConfig, UserConfig) == false)
            {
                return(false);
            }

            //init
            try
            {
                DebugEx.TraceLog("FLIC: InitFlicClient from flic plugin initialize");
                //init plugin
                _InitFlicClient();
            }
            catch (Exception ex) { DebugEx.Assert(ex, "Could not init"); }
            //done
            return(true);
        }
예제 #5
0
파일: PluginMain.cs 프로젝트: sm6uax/plegma
        //------------------------------------------------------------------------------------------------------------------------
        public override bool Initialize(mNodeConfig mNodeConfig, string PluginConfig, string UserConfig)
        {
            //init base
            if (base.Initialize(mNodeConfig, PluginConfig, UserConfig) == false)
            {
                return(false);
            }

            //add a sample notfication context menu item (systray icon)
            _add_sample_NotificationContextMenuItem();

            //show sample notification
            UI_ShowNotification(UI.InformationType.Info, "", "Plugin test notification");

            //create a test text thing
            var thing = AddThing(ThingTools.TextThing.CreateThing(NodeKey));

            //init plugin
            DebugEx.TraceLog("Test plugin up and running !! ");
            //done
            return(true);
        }
예제 #6
0
파일: PluginMain.cs 프로젝트: sm6uax/plegma
        //------------------------------------------------------------------------------------------------------------------------
        #endregion

        #region Functions
        //------------------------------------------------------------------------------------------------------------------------
        public override bool Initialize(mNodeConfig mNodeConfig, string PluginConfig, string UserConfig)
        {
            //init base
            if (base.Initialize(mNodeConfig, PluginConfig, UserConfig) == false)
            {
                return(false);
            }

            //set queue handler
            SendQueue.SetHandler(s =>
            {
                if (SendToCloudPort != null)
                {
                    SetPortState(SendToCloudPort.PortKey, s);
                }
            });

            //init
            try
            {
                var ports = SerialPort.GetPortNames();
                DebugEx.TraceLog("Serial Ports found: " + string.Join(",", ports));

                var port = ports?.Where(p => p.Contains("USB")).FirstOrDefault();
                if (port != null && !port.IsNullOrEmpty())
                {
                    DebugEx.TraceLog("Selected Port: " + port);

                    //replace this with entry from conf
                    mySerial = new SerialPort(port, 9600);
                    if (mySerial.IsOpen)
                    {
                        try
                        {
                            mySerial.Close();
                            mySerial.Dispose();
                        }
                        catch { }
                    }
                    mySerial.DataReceived  += MySerial_DataReceived;
                    mySerial.ErrorReceived += MySerial_ErrorReceived;
                    mySerial.ReadTimeout    = 2000;
                    mySerial.NewLine        = "\r\n";
                    mySerial.Open();

                    _IsRunning = true;
                    StartSerialPortReadThread();

                    SendQueue.Start();
                    SendQueue.Pause();
                }
                else
                {
                    DebugEx.Assert("The USB port does not exist");
                }
            }
            catch (Exception ex) { DebugEx.Assert(ex, "Could not init"); }

            //setup
            SetupSerialPortThings();

            //done
            return(true);
        }