Giter Club home page Giter Club logo

Comments (2)

detectivejd avatar detectivejd commented on May 28, 2024

Please!, I need to help with this code, The worker services are different applications and they are installed in a raspberry pi as deamon services in Linux

Service to Ticket Impress
image

Service to Bill Impress
image

I don´t know if on the code have fails or not, I was looking for information in Google but all that I found was useless and I didn´t work it.

Ticket Impress -> Program.cs

using ViewParking.Tickets.Raspberry.Impresion;

IHost host = Host.CreateDefaultBuilder(args)
    .UseSystemd()
    .ConfigureServices(services =>
    {
        services.AddSingleton<IHostedService, Worker>();
    })
    .Build();

await host.RunAsync();

Ticket Impress -> Worker.cs

namespace ViewParking.Tickets.Raspberry.Impresion;

public class Worker : BackgroundService
{
    private readonly ILogger<Worker> _logger;

    public Worker(ILogger<Worker> logger)
    {
        _logger = logger;
    }

    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
    {
        var configuration = new ConfigurationBuilder()
            .AddJsonFile("appsettings.json", true, true)
            .AddEnvironmentVariables()
            .Build();

        var properties = configuration.GetSection("Default");
        var tiempoCicloChequeo = properties.GetValue<int>("TiempoCicloServicioMilisegundos");
        var entrada = new EntradaImpresion();

        Console.Clear();

        while (!stoppingToken.IsCancellationRequested)
        {
            await Task.Delay(tiempoCicloChequeo, stoppingToken);
            entrada.Iniciar();            
        }
    }
}

Bill Impress -> Program.cs

using ViewParking.Facturas.Raspberry;

IHost host = Host.CreateDefaultBuilder(args)
    .UseSystemd()
    .ConfigureServices(services =>
    {
        services.AddSingleton<IHostedService, Worker>();
    })
    .Build();

await host.RunAsync();

Bill Impress -> Worker.cs

using ViewParking.Facturas.Raspberry.Impresion;

namespace ViewParking.Facturas.Raspberry
{
    public class Worker : BackgroundService
    {
        private readonly ILogger<Worker> _logger;

        public Worker(ILogger<Worker> logger)
        {
            _logger = logger;
        }

        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            var configuration = new ConfigurationBuilder()
                .AddJsonFile("appsettings.json", true, true)
                .AddEnvironmentVariables()
                .Build();

            var properties = configuration.GetSection("Default");
            var tiempoCicloChequeo = properties.GetValue<int>("TiempoCicloServicioMilisegundos");
            var entrada = new EntradaImpresion();

            Console.Clear();

            while (!stoppingToken.IsCancellationRequested)
            {
                await Task.Delay(tiempoCicloChequeo, stoppingToken);
                entrada.Iniciar();
            }
        }
    }
}

You response me, please!.

from esc-pos-.net.

igorocampos avatar igorocampos commented on May 28, 2024

Hi, that's too much information, and your code is not even presented with syntax highlight. Very hard to follow, especially with a lot of Spanish embedded in naming and all.
Anyhow, from what I could understand, you have 1 printer connected but 2 different apps running at the same time wishing to use the printer, but only the first application is able to do so, the second one is throwing an error. Is that it?

If that's the case, you have a race condition between your apps when consuming the printer resource. If you really wish to implement it like that (separate applications using the same printer) you would need a printing spooler, where you would have to manage the readiness of the printer, and most likely a printing queue, so there are no conflicts when trying to use it.

from esc-pos-.net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.