protected override void OnStart(string[] args) { _serviceRunning = true; LOG.Info("enter Service.OnStart()"); try { string deviceTag = ConfigurationManager.AppSettings["DeviceTag"]; if (!string.IsNullOrEmpty(deviceTag)) { _deviceTag = deviceTag; LOG.Info(deviceTag); } } catch { } _usbCount = DeviceCounter.GetNanoCount(); usbMonitor.AddUSBEventWatcher(USBEventHandler, USBEventHandler, new TimeSpan(0, 0, 3)); _namedpipeClient.ServerMessage += OnServerMessage; _namedpipeClient.Disconnected += OnDisconnected; _namedpipeClient.AutoReconnect = true; ThreadPool.QueueUserWorkItem(new WaitCallback(ConnectProc), this); _namedpipeClient.Start(); }
private void Form1_Load(object sender, EventArgs e) { _avalonFloatWindow.MainForm = this; ThreadPool.QueueUserWorkItem(new WaitCallback(GetAdProc), this); ThreadPool.QueueUserWorkItem(new WaitCallback(UpdateAdPictureProc), this); string temp = _currentDir.TrimEnd("\\/".ToCharArray()); string parentDir = Path.GetDirectoryName(temp); _bfgMinerDir = Path.Combine(parentDir, Constants.BfgMinerDirName); _bfgMinerPath = Path.Combine(_bfgMinerDir, Constants.BfgMinerFileName); _configPath = Path.Combine(_currentDir, ConfigFileName); LOG.Info("config path: " + _configPath); _appConfig = new AvalonConfig(_configPath); _appConfig.LoadConfig(); _processManager = new ProcessManager(); _summaryQueue = new Queue <SummaryResult>(); //DebugMinerData(); string windowsRoot = Environment.GetEnvironmentVariable("SystemRoot"); string systemDir = Environment.SystemDirectory; string pathValue = string.Format("{0};{1};{2};", _bfgMinerDir, systemDir, windowsRoot); Environment.SetEnvironmentVariable("PATH", pathValue); int screenWidth = Screen.PrimaryScreen.Bounds.Width; int screenHeight = Screen.PrimaryScreen.Bounds.Height; //_avalonFloatWindow.Location = new Point(screenWidth - 186 - 50, 50); _avalonFloatWindow.Location = new Point(screenWidth - 261 - 50, 50); _avalonFloatWindow.USBCount = DeviceCounter.GetNanoCount(); LOG.Info("Form_load, usb count: " + _avalonFloatWindow.USBCount); if (_avalonFloatWindow.USBCount > 0) { RunMinerAndMonitorData(); _avalonFloatWindow.Show(); notifyIcon1.Visible = true; _avalonFloatWindowVisible = true; } else { //_avalonFloatWindow.Show(); notifyIcon1.Visible = false; _avalonFloatWindowVisible = false; this.Visible = this.ShowInTaskbar = false; } _namedpipeServer.ClientConnected += OnClientConnected; _namedpipeServer.ClientDisconnected += OnClientDisconnected; _namedpipeServer.ClientMessage += OnClientMessage; _namedpipeServer.Start(); }
private void USBEventHandler(Object sender, EventArrivedEventArgs e) { int byTimes = 0; if (e.NewEvent.ClassPath.ClassName == "__InstanceCreationEvent") { byTimes = 1; } else if (e.NewEvent.ClassPath.ClassName == "__InstanceDeletionEvent") { byTimes = -1; } LOG.Info(string.Format("old count = {0}, plugin/out: {1}", _usbCount, byTimes)); int deviceCount = 0; foreach (USBWatcher.USBControllerDevice Device in USBWatcher.WhoUSBControllerDevice(e)) { string line = Device.Dependent.TrimEnd("\"\\".ToCharArray()); LOG.Info("line = " + line); //if (line.EndsWith(string.Format("\\{0}", _deviceTag), StringComparison.InvariantCultureIgnoreCase)) if (line.IndexOf(_deviceId) > 0) { deviceCount++; } } _usbCount += (deviceCount * byTimes); if (_usbCount < 0) { _usbCount = 0; } int count = DeviceCounter.GetNanoCount(); if (_usbCount > count) { _usbCount = count; } LOG.Info("=======usb count: " + _usbCount); _lastUSBEventTime = DateTime.Now; RunAndNotifyGui(_usbCount); }
private bool UpdateUSBCount() { bool needUpdate = false; if (DateTime.Now.Subtract(_lastUSBEventTime).TotalMilliseconds > MaxUSBEventGapMilliSeconds) { int usbCount = DeviceCounter.GetNanoCount(); if (_usbCount != usbCount) { _usbCount = usbCount; _requestNotifyUSBCount = true; needUpdate = true; _lastUSBEventTime = DateTime.Now; } } return(needUpdate); }
private void Timer_Elapsed(object sender, ElapsedEventArgs e) { lock (this) { try { Varibale var = new Varibale(); if (Varibale.level_Fetch == 0) { //log_system.saveLogMsg("counter "); Varibale.level_Fetch++; DeviceCounter.deviceCounterConnect(); } else if (Varibale.level_Fetch == 1) { //log_system.saveLogMsg("autoclav"); Varibale.level_Fetch++; Autoclav.ReadFromAutoclav(); } else if (Varibale.level_Fetch == 2) { //log_system.saveLogMsg("frig"); Varibale.level_Fetch = 0; DevOther.DevOtherConnect(); } else { Varibale.level_Fetch = 0; } PublicMehotd.SetDataToDatabase("last_recive", PublicMehotd.RetStringPersianCalender() + " " + PublicMehotd.RetStringLocalTime()); PublicMehotd.SetDataToDatabase("last_recive_int", PublicMehotd.time_php()); // //frmIndex.st_lbl_comment.Text = "ارتباط برقرار است."; if (Varibale.portError) { LogManager log = new LogManager(1, Enum.EnumKindDevice.system, Enum.EnumLevel.high, Enum.EnumLOg.SerialPort_request_connect_Success, "*"); Varibale.portError = false; Varibale.portErrorNumber = 0; //frmIndex.st_pbx_DisconnectDevice.Visible = false; //frmIndex.st_pbx_connectDevice.Visible = true; } CreateSerialPort.CLOSESERIAL("TIMER 1", "PLCE READ NOT CLOSE"); } catch (Exception ex) { log_system.saveLogSystem(ex, "serial port timer connect " + Varibale.devicenumber_autoclav); Varibale.portErrorNumber++; if (!Varibale.portError) { Varibale.portError = true; LogManager log = new LogManager(1, Enum.EnumKindDevice.system, Enum.EnumLevel.high, Enum.EnumLOg.SerialPort_request_connect_ERROR, "*"); //frmIndex.st_pbx_DisconnectDevice.Visible = true; //frmIndex.st_pbx_connectDevice.Visible = false; } //frmIndex.st_lbl_comment.Text = "پورت مشکل دارد" + " خطا " + Varibale.portErrorNumber.ToString(); CreateSerialPort.CLOSESERIAL("TIMER 2", "PLCE READ NOT CLOSE"); if (Varibale.portErrorNumber > 5) { //PublicMehotd.DeactiveAllDevice(); //PublicMehotd.DisconnectToDeviceSerialPort(frmIndex.st_tstrip_message); //LogManager log = new LogManager(0, Enum.EnumKindDevice.system, Enum.EnumLevel.high, Enum.EnumLOg.SerialPort_disconnect_operator, "*"); //frmIndex.st_pbx_DisconnectDevice.Visible = true; //frmIndex.st_pbx_connectDevice.Visible = false; log_system.saveLogSystem(ex, "serial port error a lot of "); } } } }
public string GetCommandLine() { string cmdLine = string.Empty; for (int i = 0; i < PoolInfos.Length; i++) { cmdLine += string.Format(" -o {0}:{1} -O {2}:{3} ", PoolInfos[i].PoolURL, PoolInfos[i].PoolPort, PoolInfos[i].WorkerName, PoolInfos[i].WorkerPassword); } //string[] comPorts = DevicePorts.GetDevicePortArray(); string[] comPorts = DeviceCounter.GetNanoComs(); if (comPorts == null || comPorts.Length == 0) { return(string.Empty); } string comArguments = string.Empty; foreach (string port in comPorts) { comArguments += SerialFlag + " " + PortParamHeader + port.Substring(3) + " "; } string arguments = string.Empty; string[] items = AvalonInfo.Parameters.Split(",".ToCharArray()); bool comArgumentAdded = false; for (int i = 0; i < items.Length; i++) { string item = items[i].Trim(); bool serialFlag = item.Equals(SerialFlag, StringComparison.InvariantCultureIgnoreCase); if (!comArgumentAdded && serialFlag) { arguments += " " + comArguments + " "; comArgumentAdded = true; } if (serialFlag) { i++; continue; } if (!string.IsNullOrEmpty(item)) { arguments += " " + item + " "; } } cmdLine += arguments; cmdLine += " --log-file " + AvalonInfo.Log; cmdLine = cmdLine.Replace("\"", ""); string timeIntervalParameter = string.Empty; switch (_avalonConfig.MHSSeconds) { case 20: break; case 300: timeIntervalParameter = " -l 300"; break; } cmdLine += timeIntervalParameter; return(cmdLine); }