예제 #1
0
        static void Main()
        {
            EventClient eventClient = new EventClient();

            eventClient.Connect("127.0.0.1", 9777);
            eventClient.SendHelo("XBMC Client Demo", IconType.ICON_PNG, "icon.png");
            System.Threading.Thread.Sleep(1000);
            eventClient.SendNotification("XBMC Client Demo", "Notification Message", IconType.ICON_PNG, "/usr/share/xbmc/media/icon.png");
            System.Threading.Thread.Sleep(1000);
            eventClient.SendButton("dpadup", "XG", ButtonFlagsType.BTN_DOWN | ButtonFlagsType.BTN_NO_REPEAT, 0);
            System.Threading.Thread.Sleep(1000);
            eventClient.SendPing();
            System.Threading.Thread.Sleep(1000);
            eventClient.SendMouse(32768, 32768);
            System.Threading.Thread.Sleep(1000);
            eventClient.SendLog(LogTypeEnum.LOGERROR, "Example error log message from XBMC Client Demo");
            System.Threading.Thread.Sleep(1000);
            eventClient.SendAction("Mute");
            System.Threading.Thread.Sleep(1000);
            eventClient.SendBye();
        }
예제 #2
0
        static void Main(string[] args)
        {
            LocEvClient = new EventClient();
            LocEvClient.Connect(new[] { "fetching", "errors" }, PropertyUpdate, ShowError, UpdateLocalConnectionStatus);
            var configName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "L2M.xml");

            if (File.Exists(configName))
            {
                // чтение конфигурационного файла
                var      xdoc      = XDocument.Load(configName);
                XElement listenTcp = xdoc.Element("Config").Element("ListenTcp");
                ReadConfigParameters(listenTcp, out IPAddress ipAddress, out int ipPort, out int sendTimeout, out int receiveTimeout);
                // запуск потока для прослушивания запросов от устройства по протоколу Modbus Tcp
                var listener = new BackgroundWorker {
                    WorkerSupportsCancellation = true, WorkerReportsProgress = true
                };
                listener.DoWork          += ModbusListener_DoWork;
                listener.ProgressChanged += ModbusListener_ProgressChanged;
                var tcptuning = new TcpTuning
                {
                    Address        = IPAddress.Any,
                    Port           = ipPort,
                    SendTimeout    = sendTimeout,
                    ReceiveTimeout = receiveTimeout,
                };
                listener.RunWorkerAsync(tcptuning);
                // чтение параметров для опрашивающих потоков
                foreach (XElement fetchingTcp in xdoc.Element("Config").Element("Fetching").Elements("ChannelTcp"))
                {
                    ReadConfigParameters(fetchingTcp, out ipAddress, out ipPort, out sendTimeout, out receiveTimeout);
                    var parameters = FillParameters(fetchingTcp);
                    var fetcher    = new BackgroundWorker {
                        WorkerSupportsCancellation = true, WorkerReportsProgress = true
                    };
                    fetcher.DoWork          += LogikaFetcher_DoWork;
                    fetcher.ProgressChanged += LogikaFetcher_ProgressChanged;
                    tcptuning = new TcpTuning
                    {
                        Address        = ipAddress,
                        Port           = ipPort,
                        SendTimeout    = sendTimeout,
                        ReceiveTimeout = receiveTimeout,
                        Parameters     = parameters,
                    };
                    fetcher.RunWorkerAsync(tcptuning);
                }
            }
            else
            {
                return;
            }
            // Если запускает пользователь сам
            if (Environment.UserInteractive)
            {
                var s = WcfEventService.EventService;
                s.Start();
                try
                {
                    Console.WriteLine("MODBUS listening service loaded.");
                    Console.WriteLine("Ver. 0.4\n");
                    Console.WriteLine("Press any key for exit...");
                    Console.ReadKey();
                }
                finally
                {
                    s.Stop();
                }
            }
            else
            {
                var servicesToRun = new ServiceBase[] { new WinService() };
                ServiceBase.Run(servicesToRun);
            }
        }
예제 #3
0
 private void MainClientForm_Load(object sender, EventArgs e)
 {
     locEvClient.Connect(new[] { "config", "fetching", "archives" }, PropertyUpdate, ShowError, UpdateLocalConnectionStatus);
 }