What is the best coding solution for the following scenario? RRS feed

  • Question

  • Hi

    I have a National Instruments data acquisition card that controls up to 3 Panels, and each panel controls and samples 12 Bottles filed with gas that I want to sample and compare. 

    Their is a sequence of steps for each panel. 

    1. I must purge the system for each panel. 
    2. Then I must sample the Standard gas used to compare the other 12 bottles with gas. 

    I need to Kickoff the Purge the Gas a sample of the Base and then Test the 12. So I need to run each panel in parallel. Because the cycle take an Hour to run all 12 per panel. 

    Should I create a Service, or a Web-API and use multi threading or some other technology? 

    I have not done anything like this before. 
    Tuesday, August 6, 2019 5:27 PM

All replies

  • Web API requires that you call the API before it can do something. Sounds like you're interacting with PLCs so the communication would be from your app to the PLCs. Additionally web APIs can be called by any # of people at once so this probably wouldn't work well for your environment.

    If you need to run a job periodically then I'd use a console app run using Task Scheduler. If you need to run the job frequently (less than once a minute) then a service might be a better option. However you'd do better to start as a console app and then add the service-specific logic only after everything is working. The service would be a simple wrapper around the same logic that the console app already had.

    Michael Taylor http://www.michaeltaylorp3.net

    Tuesday, August 6, 2019 5:49 PM
  • Hi Michael,

    Not PLC's but a custom board with 12 relays, in which the NI Card controls. Since one PC Controls 3 Panels, would a Windows Service and the Scheduler work best. 

    I Need to be able to cancel the task. 

    Tuesday, August 6, 2019 6:07 PM
  • Also

    In Auto Mode I want to run all three Panels, I could schedule this, but I also want to run a Panel Manually. 

    Tuesday, August 6, 2019 6:10 PM
  • The difference between a service and a scheduled task/console app (beyond security) is when it runs. A service (generally) runs all the time whereas a task runs when scheduled and a console app runs when you tell it to. Fortunately the code to host these is pretty much the same so start with a console app that you manually call.

    Later, if you want it to run on a schedule, then schedule the console app using Task Scheduler. You can manually stop the task in TS if needed. You can programmatically stop the task as well but this is generally not done. 

    If you need to have it run all the time and periodically send it a "signal" through your panels or whatnot then a service would work. Services however are harder to debug because of security so go here only if you need this functionality. I have found that scheduled tasks are almost always the better option unless you need really short intervals (less than 10 minutes).

    Michael Taylor http://www.michaeltaylorp3.net

    Tuesday, August 6, 2019 6:31 PM
  • Originally services were the Windows version of DOS device drivers. Until recently, there was even a Windows API function called QueryDosDevices (plural) that enumerated all services.

    Expansion cards (devices) require privileged instructions. Also devices such as the keyboard and monitor are system-wide resources that must be shared among (potentially) all applications. You are not clear about how you are interfacing with the card. I assume that a National Instruments card has a device driver but that is not clear. If the vendor provides a relevant device driver (which would be a Windows Service) then it is unlikely you will want to develop a service.

    Without getting into details, my guess is that you will want to create a desktop application. Using something such as WPF.

    So the user (you or whoever) executes the application and then within it executes the procedure you describe. They are not likely to stay at the computer the whole time but when the procedures are done (after an hour?) they can exit from the program and there would be nothing more to be done. Does that sound right?

    Sam Hobbs

    Wednesday, August 7, 2019 6:50 PM