i’d like to switch bit with time shorter than 1 ms. I’d prefer do this in C# Windows Forms, but it can be in for example console app in C++, C#. What i want to do is to switch bit and send it via LPT port.
Switching bit in this code is to slow..
PortAccess.Output(888,1);
Thread.Sleep(1);
PortAccess.Output(888,0);
Thread.Sleep(1);
I’ve read this post: How to use QueryPerformanceCounter? , but it’s only timer..
Please help 🙂
There is no easy or obvious way to do this kind of fine-grained timing control in the C#/.NET environment. You can use the
Stopwatchclass to get close, but the resolution isn’t great for real-time work. To use a timer to do something like this – nonsense code but you loop until the time elapsed is your desired interval:Sleepshould not be used for timing anywhere.Sleeponly basically says, “sleep for at least X milliseconds”. SoSleep(1)might sleep for 25ms.And a by-the-way: next to no PCs have parallel ports anymore. This is an ancient – no, the most ancient way to write bits or flip outputs external to a PC. Doing it by directly outputting to a PC IO port is really rubbish too. You could look for an external digital IO device/board/interface with a decent driver – much better idea.