コード例 #1
0
ファイル: Program.cs プロジェクト: eltra-ch/eltra-sdk
        private static void RunOptionsAndReturnExitCode(MasterOptions opts)
        {
            var    appName  = AppDomain.CurrentDomain.FriendlyName;
            var    settings = new MasterSettings();
            var    host     = settings.Host;
            string login    = settings.Identity.AuthData.Login;
            string password = settings.Identity.AuthData.Password;

            if (!string.IsNullOrEmpty(opts.Host))
            {
                host = opts.Host;
            }

            if (!string.IsNullOrEmpty(opts.Login))
            {
                login = opts.Login;
            }

            if (!string.IsNullOrEmpty(opts.Password))
            {
                password = opts.Password;
            }

            var master = new EltraMasterConnector();

            master.Host = host;
            master.ConnectionSettings = new ConnectionSettings()
            {
                UpdateInterval = settings.UpdateInterval, Timeout = settings.Timeout
            };

            var t = Task.Run(async() => {
                Console.WriteLine($"Sign-in login={login}, passwd={password}");

                var di = new UserIdentity()
                {
                    Login = login, Name = settings.Identity.Name, Password = password, Role = settings.Identity.Role
                };

                if (await master.SignIn(di, true))
                {
                    if (!master.StartService(appName, new EposDeviceManager(settings)))
                    {
                        MsgLogger.WriteError(appName, "starting master service failed!");
                    }
                }
            });

            t.Wait();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: adospace/ModbusCore
        private static async void RunAsTcpMaster(MasterOptions options, CancellationToken cancellationToken)
        {
            var memoryMap = new ModbusMemoryMap();

            using var tcpClient = new TcpClient();
            await tcpClient.ConnectAsync(options.Host, options.Port);

            var master = new ModbusTCPMaster(memoryMap, tcpClient.GetStream(), options.DeviceId);

            while (!cancellationToken.IsCancellationRequested)
            {
                if (options.CoilsCount > 0)
                {
                }
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: adospace/ModbusCore
        private static void RunAsMaster(MasterOptions options, CancellationToken cancellationToken)
        {
            switch (options.Mode)
            {
            case CommunicationMode.RTU_SERIAL:
                throw new NotSupportedException();

            case CommunicationMode.ASCI_SERIAL:
                throw new NotSupportedException();

            case CommunicationMode.RTU_TCP:
                throw new NotSupportedException();

            case CommunicationMode.TCP:
                RunAsTcpMaster(options, cancellationToken);
                break;

            default:
                throw new NotSupportedException();
            }
        }