Serial callback in "byte" mode triggered even though no bytes are available to read
3 views (last 30 days)
Show older comments
I am using a serial port object to control stepper motors like this:
sObject_motor = serialport('COM3',115200);
sObject_motor.Timeout = 2;
sObject_motor.ByteOrder = "little-endian";
configureCallback(sObject_motor,"byte",8,@FAS_serialReadCallbackFunction);
There should be always at least 8 bytes sent by the controller as a response to any command (assuming the communication is set up correctly).
According to the above the callback should be executed when there are at least 8 bytes in the buffer to read.
However I keep getting error like this (not always, but randomly):
Warning: Error occurred while executing the listener callback for event DataWritten defined for class asyncio.InputStream:
Error using FAS_serialReadCallbackFunction (line 5)
Expected input number 2, count, to be nonzero.
The line 5 in my callback function is just:
serialans = read(sObject,sObject.NumBytesAvailable,"uint8");
When I set up a break point at this line and peek at the NumBytesAvailable property indeed it shows that there are no bytes available to read.
But this function should be triggered only when there are at least 8 bytes availble to read!
This causes the communication to fail randomly.
I am using 'pause' command after issuing every command to the controler but still this does not seem right.
Any help or suggestions is much appreciated.
4 Comments
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!