-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid while (!_closeHandler) { ... } in XBeeFrameHandler.Start() #49
Comments
Hello @nicolaiw, I will refactor this as soon as possible. I think there are some more refactoring actions necessary. Some code is not very c# style I think. |
I could reduce the CPU usage (same machine) by refactor the while loop which reads from the serial port. The previous versions always checked for BytesToRead in a while loop which is not necessary and very inefficient. The refactored version waits until data available through ReadByte(). After that it reads the rest of the data. I think it could be done even more elegant. Instead of using ReadByte() to wait for data we might use the SerialPort.Read(byte[] buffer, int offset, int count) methode to read the header, parse it for the payload length and read the payload. I'm not sure but this might be Hardware/Dongle dependent (size of the header). I guess this won't be decrease the cpu usage but might be more elegant. About 34% CPU usage still seems too high. I think there is another loop or something like that which utilizes the CPU. @Mr-Markus @andreasfedermann @andreasfedermann Best regards |
Hi Nicolai, sorry for being offline that long but I’ve moved. So I had less time to write some code. My aim for this week is to test your code changes. Best regards! |
Hi @andreasfedermann, Best, |
This might be resolved with a TaskCompletionSource. This might be a breaking change because we have to change the Start() method to return a Task instead of void.
Here is an example of a refactored while loop with a TaskCompletionSource:
https://github.com/zigbeenet/ZigbeeNet/blob/master/src/ZigBeeNet/Transaction/ZigBeeTransaction.cs#L82
The text was updated successfully, but these errors were encountered: