, for answering the question and has received an EZ-Credit award! Share what you have learned and create a tutorial to help others by clicking here
I've been trying to receive data through the Uart port in EZB V4 and use it in a script. I've successfully been sending special commands to move my motor to exact points through a Kangaroo/Sabertooth combination and that's working great. I've even been able to read how many Bytes are in the buffer useing the below Script. This Script successfully moves my motor to position 113261 at Speed 10000 and returns a reading of 5000 bytes on the debug screen of the script. However I get no info at all when I look at the UARTRead line. Even is I did I don't know how to convert that info into any useful command in my script.
Kangaroo X2 Commands:
P = Postion as read from an encoder on the motor.
S = Speed the Kangaroo lets the Sabertooth move the motor at.
Getp = Command to tell the Kangaroo to send the position it us reading from the encoder at any given moment.
0x0d = Carrage return
$Getp = "Getp"
uartWrite(1, 0, "1, p113261 s10000", 0x0d)
uartWrite(1, 0, "1, Getp", 0x0d)
$x = UartAvailable(0, 0)
print("Bytes in buffer: " + $x)
$Getp = UARTRead(0, 0, $x)
print("Received: " + $Getp)
Basically I want to move my motor to a point and be able to trigger an event or another script before the motor gets there. I know I need a loop that reads the "Getp" info returned from the Kangaroo X2 but I cant find the right code to retrieve it through the Uart port and also be able to use it.
Any help with this code is welcomed.
I have found a few conversations, tutorials and activities that may help with your question. Take a look at these links. I've sorted them by what I believe to be most relevant but that is not always the case as I'm still learning.
Also, consider reviewing the Learn section for informative lessons and activities.
Check it out!
1) Where do you initialize the UART?
2) How many bytes does $x equal?
3) Have you looked at $Getp in the Variable Watcher?
The UART port is initialized in my Start up script (Int) and is sending commands to the Kangaroo just fine.
$x equals 5000 bytes in the debug screen of the script window when the Print command is used.
No I haven't looked at the Variable watcher for the Getp. I'll have a look. Should that give me a hint?
Thanks for the tips so far.
OK, I ran the script again and the Variable Watcher only shows a " next to the $Getp variable.
Dave, could you possibly use the UART Serial Terminal display selection under the General tab?
Thanks for the suggestion. I haven't tried that yet but would need to learn how it works before I do so. I'll give it a go tonight. I did have the EZ Builder Serial port working with the old V3 but had no feedback option.
I am able to see that there's 5KB bytes in the buffer. I think that's the max receive buffer of these UART ports. Do you think there could there be more bytes than this buffer can handle?
I've very new to UART ports and how to use them.
DJ could probably tell us more about how to receive 5 kbytes and then clear the buffer for more data. The EZB Serial port is set up using the EZB4 board number and UART port 0, 1, 2, or 3.
Oh, I see your problem
Check the parameters for the UARTAvailable() and UARTRead() vs UARTWrite() that you used
As for examples, please check the examples folder in EZ-Builder for the UART Example Project.
Ah HA! That did it! It was just that simple. Just a stupid little mistake of not numbering the board properly. Thanks!
Now I get the proper position readout of p113261 . Here's what shows in the script console (Second line from the bottom):
1: $Getp = "Getp"
2: uartWrite(1, 0, "1, p113261 s10000", 0x0d)
5: uartWrite(1, 0, "1, Getp", 0x0d)
7: $x = UartAvailable(1, 0)
9: print("Bytes in buffer: " + $x)
> Bytes in buffer: 11
11: $Getp = UARTRead(1, 0, $x)
13: print("Received: " + $Getp)
> Received: 1,P113261
Thanks so much, I've been stumbling over this all evening. Couldn't have done it without you! Now I think I can finish developing the script.