Exemple #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var plcSettings = new PlcSettings();

            Configuration.Bind(nameof(PlcSettings), plcSettings);
            services.AddSingleton(plcSettings);

            services.AddSingleton <Store>();

            //services.AddHostedService<PlcOpc>();
            services.AddHostedService <PlcService>();

            services.AddControllers();
            services.AddSignalR();

            services.Configure <ForwardedHeadersOptions>(options =>
            {
                options.ForwardedHeaders =
                    ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
            });

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "My API", Version = "v1"
                });
            });
        }
Exemple #2
0
        //private readonly ManualResetEvent okToWrite = new ManualResetEvent(true);
        //private CancellationTokenSource _cancelWriteDelay = new CancellationTokenSource();

        public PlcService(ILogger <PlcService> logger, PlcSettings plcSettings, Store store)
        {
            _logger      = logger;
            _plcSettings = plcSettings;
            //_client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            _store     = store;
            _readVars  = store.Variables.Values.Where(v => v.Type != null && v.Plc != null && v.Plc.Action == PlcVariableAction.Read).ToList();
            _writeVars = store.Variables.Values.Where(v => v.Type != null && v.Plc != null && v.Plc.Action == PlcVariableAction.Write).ToList();
        }
Exemple #3
0
 public PlcComms(PlcSettings plcSettings)
 {
     this.plcSettings = plcSettings;
     client           = new TcpClient();
 }
 public PlcOpc(ILogger <PlcOpc> logger, PlcSettings plcSettings, Store store)
 {
     _logger      = logger;
     _plcSettings = plcSettings;
     _store       = store;
 }