-
Notifications
You must be signed in to change notification settings - Fork 24
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
Serial1.flush() - I believe is doing the old behaviour and output buffers? #28
Comments
@KurtE, you're right. I will commit in this regard. |
I erased the wrong code. Since the flush function is only meaningful for DMA or Interrupt, we will modify the flush function accordingly if we change the TX function later. |
@OpusK, Probably goes without saying, but the difficult part of this change is that there is probably other code that relies on the old semantics of flush(). Example in dynamixel_sdkthe file port_handler_arduino.cpp there is a function PortHandlerArduino::clearPort(), which calls flush, expecting to clear out anything that was queued... Note; on Teensy 3.x boards, the serial class has an additional method clear(), which is probably non-standard which does what the old flush did... |
The original meaning of the code is to clear the TX buffer. However, since DXL uses UART only, it follows the polling function of OpenCM UARTClass::write() function and does not use a separate internal buffer. Therefore, there is no buffer to clear, and it seems that there will be no problem in using this modified code. Please let me know if I misunderstand this :) |
Hard for me to say, what the semantics you are expecting here. For example in my own dynamixel library, when I am sending packets, I do both, example: And if I look at your other implementations for the PortHandler?::clearPort, you see:
So the Linux and Mac, it clears both TX and RX and it looks like on Windows it clears RX... So your guess is as good as mine, what is actually needed here. (Edited) - cut and pasted wrong linux function |
Oh, now I understand what you are saying. So, as you say, we need to create a separate function that can clear the RX buffer and call it in clearPort (). Thank you :) |
Looks good! |
Later, when using DMA mode, it was treated as simply reading the data with a timeout in consideration of the buffer synchronization problem. Please let me know if you have a better idea :) |
@OpusK - as you said, I believe you have addressed the issue. If at some point DMA or interrupt mode is implemented and an Output buffer is defined and used, than the new flush behavior sound be implemented at that time. So I agree with you that this issue should be closed |
@KurtE - Thanks for your feedback :) |
Prior to Arduino 1.0, Serial1.flush() would throw away all of the buffered input.
Where as after that Serial1.flush() would wait for all buffered output to fully go out the device as you can see in the Arduino reference: https://www.arduino.cc/reference/en/language/functions/communication/serial/flush/
Looking at the Sources:
UARTClass.cpp:
Which if you look in drv_uart.c you see:
Note: reading through sources, I am unsure if you need a new Arduino flush behavior?
That is typically on Arduino if you do something like:
The call would the majority of time simply put the data into an output buffer and return immediately. The exception, is if you tried to write more data into the queue than what would fit, in which case the call would not return until enough data was sent that the last parts of your write would fit into buffer.
That is why some platforms have also added call: Serial1.availableForWrite(), which would give you the current free space on the output buffer, such that you could than write less than that and know you were not going to block.
The reason I noticed this was looking at DynamixelSDK port_handler_arduino.cpp at:
The setTxEnable() and setTxDisable(), just set the appropriate IO port for the correct direction. So was unclear how the underlying call p_dxl_Serial->write on who waited for the underlying call:
Serial1.write(packet, length) to complete...
Not sure how much should change here... But for example I do have code that does use things like:
EDIT: noticed you do have Serial1.availableForWrite, but not sure it is correct?
Where:
Which appears to be dealing with RX queue, not the TX...
The text was updated successfully, but these errors were encountered: