Esempio n. 1
0
        static void Main(string[] args)
        {
            Thread.Sleep(2000);
            var portSettings = ConfigurationManager.AppSettings["COMports"].Split(
                new[] { ",", ", " },
                StringSplitOptions.RemoveEmptyEntries);
            Console.WriteLine("Creating service proxy.");
            var proxy = new SmlComServiceClient(new BasicHttpBinding(), new EndpointAddress("http://localhost:7081/SmlComService"));
            
            var serviceVersion = proxy.GetVersion();
            Console.WriteLine("Service Version: '{0}'.", serviceVersion);

            Console.WriteLine("Resetting all ports.");
            proxy.ResetAllPorts();
            foreach (var portName in portSettings)
            {
                portList.Add(
                   new CommunicationPort
                   {
                       ComPortName = portName,
                       ComTimeOut = TimeSpan.FromSeconds(3),
                       MeterType = MeterType.Basemeter
                   });
            }

            var configuredAt = DateTime.Now;
            Console.WriteLine("{0} - Calling configuration command.", configuredAt);
            var clientGuid = Guid.Empty;

            clientGuid = ConfigurePortsOrExit(proxy, configuredAt, clientGuid);

            Console.ReadLine();

            var serverPorts = proxy.GetPortList();
            foreach (var communicationPort in serverPorts)
            {
                Console.WriteLine("Server port: {0}, init {1}", communicationPort.ComPortName, communicationPort.IsInitialized);
            }

            Console.ReadLine();

            string port = "COM101";
            while (true)
            {
                // read register test
                //ReadRegister(port, proxy, clientGuid, RegisterIds.ActiveEnergyPlus.AsLong());
                ReadRegister(port, proxy, clientGuid, RegisterIds.ActiveEnergyMinus.AsLong());

                WriteManufacturerId(port, proxy, clientGuid, "IVU");
                //WriteMeasurementMode(port, proxy, clientGuid, "MM2");
                //ReadHistoricEnergyLastDay(port, proxy, clientGuid);
                //ReadHistoricEnergyLastWeek(port, proxy, clientGuid);

                //WriteEnableTariffFunction(port, proxy, clientGuid, true);
                //WriteAplusTariff(port, proxy,clientGuid, 2);

                //WritePinCode(port, proxy, clientGuid, "1221");

                //ReadPublicKey(port, proxy, clientGuid);

                //WriteServerId(port, proxy, clientGuid);

                //WriteManufacturerId(port, proxy, clientGuid, "DZG");

                //WriteFactoryMode(port, proxy, clientGuid, false);

                //WriteEnableGridOption(port, proxy, clientGuid, true);

                Thread.Sleep(3000);
            }



            Console.WriteLine();
            Console.WriteLine("Command execution finished.");

            Console.ReadLine();

        }