Should I use the stream for asynchronous access to my device connected to the PCI bus?

I have a piece of equipment that connects to a computer via a PCI bus. I access the hardware through the .NET shell around the device driver.

I do not have any specifications about how the device performs a PCI mutation. This brings me to my first question.

1) Do devices connected via PCI guarantee data delivery at a certain speed?

2) When communicating with the device, I want my user interface to remain responsive. Is it a good idea to start communicating with the device in a thread (threadpool), or is the overhead associated with this too complicated than quick access to the PCI bus?

Edit:
The question has been rewritten. It reflected too much of the end of a long working day.
The requirement that the stream be a thread pool thread has been removed.

+4
source share
3 answers

Are devices connected via PCI a guarantee of data delivery at a certain speed?

No. As I understand it, PCI is a shared bus with mastering the bus , which allows one device to temporarily use the full bandwidth of the bus. In non-server environments , which typically means a throughput of 133 MB / s. When you have several I / O cards on the PCI bus, you can see how bandwidth can become scarce under load. Incorrect devices can also adversely affect latency; some controllers freeze until its drive responds to I / O, but has provided this abnormal situation.

When communicating with the device, I want my user interface to remain responsive. Is it a good idea to start communication with a device in a thread (threadpool), or is the overhead associated with it too large compared to how quick access to the PCI bus is?

When writing user-centric software, it is always useful to separate the interface from I / O or other potentially lengthy processes. For example, the modern Android SDK provides this in its HTTP client - it throws an exception if the HTTP request is executed in the user interface thread.

Depending on which version of the .NET platform you are targeting, you have several options for separating device messages from the user interface. See “Parallel Processing” and Concurrency in the .NET Framework for a high-level overview of various parameters. Threading is a low-level abstraction, and it may be easier and less error-prone to use a higher-level abstraction, such as Tasks or C #, asynchronous and pending keywords .

+3
source

In general, anytime you have the ability to write code without being tied to a stream, it is often a good idea to do this. That way, you have the freedom to disable the user interface thread when and if it becomes a responsive issue. Designing your API for this I / O using Async methods also allows your options to open in the future in a good way.

Regardless of whether the stream you are on, the stream of the stream, or the one you create yourself, seems inappropriate if you do not need to occupy it for long periods of time. And if you can do Async I / O, then the threadpool thread should be fine.

+4
source

I think using a long background thread makes sense when you need to monitor the status of equipment. TaskCreationOptions.LongRunning looks good.

Also, using the new async / await function for C # to interact with the device asynchronously makes sense to me. I'm not sure this will help, but here is a snippet to illustrate how I usually deal with hardware interactions (WinUSB devices are often used for me):

class Controller : IDisposable // to dispose the unmanaged resources related to the hardware { // this will be used to call back to the UI private static readonly SynchronizationContext DefaultContext = new SynchronizationContext(); public Controller() { Task.Factory.StartNew(this.Monitor, ct, TaskCreationOptions.LongRunning); } public async Task<Result> ActionOnHardwareAsync(object parameter) { // you may need to synchronize with the monitor method here. } // This method monitors hw status, calling back to the UI when something happens private void Monitor(object state) { // Do some stuffs... this.synchronizationContext.Post(~ your SendOrPostCallback here ~, ~ event from the hw ~); } } 
+2
source

All Articles