c# - Brokering IO requests in a static class -


I have a single, static broker class with a group of 'drivers' The network IO that creates the request for the tool I have examples of a device class that tells the device to read the data through the drivers.

The broker is present to meet the requests of other sections because we have a limited number of concurrent connections which we can do.

The problem occurs when devices share the same driver type and make overlapping calls for data. Driver is a shared resource and both can not serve at the same time.

Here is a meaningful implementation (not running, how do I just do it):

Public static zero ReadDataItem (driver type driver type, string IP, Datatam Aadress Address, Action & Lieutenant (ILIIT & LT; USARRT & gt; & gt; Callback) {// Type var driver = Recovery driver (driverType), one of three drivers can return one of the examples; If (! Driver! Initial) {// Note: Make sure the connection is set to correct PLC} Task & lt; IList & lt; Ushort & gt; & Gt; Results = Tasks. Factor StartNew (() => Driver. Redidite (address)); Callback (result.Result); }

Obviously, if two devices call with the same driver, then there is no mechanism for 'queue' to request.

Does anyone have any idea how can I wait for the call to the calling client for the data?

You can probably use it for:

  static reading For s_semaphore = new semaphorcil (1); Public stable async works & lt; IList & lt; Ushort & gt; & Gt; ReadDataItem (Driver Type Driver Type, String IP, Data IT Address Address, Action & LT; IELIT & UT Left; gt; & gt; Callback) {{driver = Recovery Driver (Driver Type)) using {if (Driver! ) {// Note: Make sure the connection is set to correct PLC) // You can use different semaphores, // await s_semaphore.WaitAsync () based on the type of driver; Try {return ask ask.Factory.StartNew (() => driver.readDataItem (address)); } Finally {s_semaphore.Release (); }}}  

Comments

Popular posts from this blog

Editing Python Class in Shell and SQLAlchemy -

import - Python ImportError: No module named wmi -

uislider - In a MATLAB GUI, how does one implement a continuously varying slider from a GUIDE created .m file? -