Example #1
0
        static void Main(string[] args)
        {
            var fileName = $"data{Path.DirectorySeparatorChar}binary-{DateTime.Now.ToString("yyyy-MM-dd-HH-mm")}.dat";

            Console.WriteLine($"Filename: {fileName}");
            Console.WriteLine("Starting reading data ...!");

            Stream          stream         = new FileStream(fileName, FileMode.Create);
            ISettingsSerial serialSettings = new SettingsSerial();

            if (System.OperatingSystem.IsWindows())
            {
                serialSettings.PortName = "com3";
            }

            IMBusReader mbusReader = new ReliableMBusReader(stream, serialSettings);

            // IMBusReader mbusReader = new MBusReader.Code.MBusReader(stream, serialSettings);

            mbusReader.Run(true);

            while (!Console.KeyAvailable)
            {
                Thread.Sleep(100);
            }

            mbusReader.Close();
            stream.Close();

            Console.WriteLine("Program end ...!!");
        }
Example #2
0
        protected override Task ExecuteAsync(CancellationToken stoppingToken)
        {
            _logger.LogInformation("Running ...");
            var fileName = $"data{Path.DirectorySeparatorChar}binary-{DateTime.Now.ToString("yyyy-MM-dd-HH-mm")}.dat";

            _logger.LogInformation($"Filename: {fileName}");
            _logger.LogInformation("Starting reading data ...!");

            Stream          stream         = new FileStream(fileName, FileMode.Create);
            ISettingsSerial serialSettings = new SettingsSerial();

            if (System.OperatingSystem.IsWindows())
            {
                serialSettings.PortName = "com3";
            }

            IMBusReader mbusReader = new ReliableMBusReader(stream, serialSettings);

            // IMBusReader mbusReader = new MBusReader.Code.MBusReader(stream, serialSettings);
            mbusReader.Run(true);

            return(Task.CompletedTask);
        }