public DynapowerRemoteMonitoringService()
        {
            InitializeComponent();

            Logger.LogMessage("Initializing " + Global.SERVICE_NAME);
            Logger.LogMessage("Looking For Registers to load");
            try
            {
                var fileStream = File.Open(@"c:\program files\dynapower\Registers.csv", FileMode.Open, FileAccess.Read);
                Logger.LogMessage("File Opened");
                var loader = new DeviceRegisterImporter(1, new StreamReader(fileStream));
            }
            catch(Exception ex)
            {
                Logger.LogMessage("Could not load registers. Error: " + ex.Message);
            }
            this.EngineLock = new object();
            this.Engine = new DynapowerRemoteMonitoringServiceEngine();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
#if CLEAN
            SensorCloud.Device dev = new SensorCloud.Device("OAPI00QSRXF6WY79", "229d87b9b90dbff0eabc8130a794b82018a20c3513d975bdce95e64b1ecf9822");
            //SensorCloud.Sensor sensor = dev.GetSensor("");
            int channelsDeleted = 0;
            int notDeleted = 0;
            for (int i = 0; i < 6; i++)
            {
                try
                {
                    var sensor = dev.GetSensor("status" + i.ToString());
                    //var channel = sensor.GetChannel(i.ToString());
                    sensor.DeleteChannel(i.ToString());
                    dev.DeleteSensor(sensor.Name);
                    channelsDeleted++;
                    //sensor.DeleteChannel("volts" + i.ToString());
                }
                catch (Exception ex)
                {
                    notDeleted++;
                }
            }

#elif LOAD
            var fileStream = File.Open(@"A9RD0B6.csv", FileMode.Open, FileAccess.Read);
            var loader = new DeviceRegisterImporter(1,new StreamReader(fileStream));

#elif RUNSERVICE

            //var fileStream = File.Open(@"Registers.csv", FileMode.Open, FileAccess.Read);
            //var loader = new DeviceRegisterImporter(1, new StreamReader(fileStream));
            //var loader2 = new DeviceRegisterImporter(2, new StreamReader(fileStream));
            DynapowerRemoteMonitoringServiceEngine Engine = new DynapowerRemoteMonitoringServiceEngine();
            Engine.StartMonitoring();
            Thread.Sleep(Timeout.Infinite);
#elif QUERY
            var tcpClient = new TcpClient("166.130.63.214", 502);
            var modBusMaster = ModbusIpMaster.CreateIp(tcpClient);
            modBusMaster.Transport.ReadTimeout = 100;
            modBusMaster.Transport.Retries = 5;
            modBusMaster.Transport.WaitToRetryMilliseconds = 100;
            modBusMaster.Transport.WriteTimeout = 100;

            while (true)
            {
                try
                {
                    var results = modBusMaster.ReadInputRegisters(6662, (ushort)1);
                }
                catch (Exception ex)
                {
                    if (!string.IsNullOrEmpty(ex.Message) && ex.Message.ToLower().Contains("transaction"))
                    {
                        //modBusMaster = ModbusIpMaster.CreateIp(new TcpClient("166.130.63.214", 502));
                    }
                }
                System.Threading.Thread.Sleep(1000);
            }
#endif
        }