Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: mcardoso on November 11, 2019, 10:31:45 AM
-
I have been successfully using Mach 4 and my computer's embedded serial port for some months now (using the LUARS232 module included with Mach 4). I definitely had some trouble understanding it at the beginning, but now it is a framework for serial communications with my servo drives and works great.
At the recommendation of several members and admins on this forum, I have implemented rigorous error checking and handling throughout all of my scripting. Unfortunately this has been giving me new headaches by... catching errors ;D
I have been able to correct my code to fix all but a handful of errors, mostly thrown by calls to the serial API. Those calls do return error codes to help troubleshoot, however I have been completely unable to find documentation on the RS232 module, either within the Mach 4 documentation or on the greater internet.
For example, I have the line of code:
local err, data_read, size = p:read(4096, 100)
where 4096 is the length of buffer to be read and 100 is the timeout in ms.
This returns the error code "09", but I cannot find ANYTHING to tell me what "09" indicates or how to correct it. I am at a loss.
Any suggestions where to look would be greatly appreciated.
Thanks! - Mike
-
I believe it's a time error, if I was looking at the correct source code?
https://github.com/srdgame/librs232
-
jbuehn,
Thanks so much for taking the time to respond. I am not well versed in GitHub. Could you point me to where you found that information? I've been clicking through the files but have not found it yet.
-Mike
-
line 89
https://github.com/srdgame/librs232/blob/master/bindings/lua/luars232.c
-
Wow, quite burried in there. Will experiment with the timeout value tonight.
Also it seems like there is a p:flush() command which I might try instead of reading the max buffer length to empty the port.
-
Making progress! Turns out the Error "09" (Timeout) will occur whenever there is not data available to be read from the buffer. This is a normal condition for me (e.g. read until the buffer is empty) so I need to adjust my error checking to not abort my script if a timeout error is generated.