
mtiberia
There is an issue when sending ASCII code through the UART ports. For some reason the ASCII code is getting lost in the translation. It is hit or miss, some codes make it through fine and some don't get sent at all. Error saying that the expression is not in quotes. If the code is sent the received transmission shows a question mark. I have included an example with the ASCII code 255, it gets sent but RX is a ? and not the y with two dots above it.
If you can correct this issue with the scripting you would have me sold on the EZ B.
Great platform and fun to use.
Thanks DJ
Start 1: UARTInit(0,1,1000000)
7: $handshake=GetAsByte(255) # ASCII code 255
8: UARTWrite(0,1,$handshake) # not all codes will be TX
10: Print($handshake)
ÿ # symbol that code represents
14: Sleep(1000)
16: $x = UartAvailable(0, 1)
18: print("Bytes in buffer: " + $x)
Bytes in buffer: 1
20: $TX_DATA = UARTRead(0, 1, $x)
22: print("Received: " + $TX_DATA)
Received: ? # RX Issue or TX issue
25: Print ("done")
done
Well, the value would be wrong from what you expect
That's what i'm spending time helping you with.
Would you like me to give you the solution or would you prefer if I helped point you in the right direction so you can feel the achievement of discovering the answer yourself?
Please give me the solution.
darn it
I was hoping you weren't going to say that! lol okay give me a bit because i'm in a dinner meeting
I added a nice debug viewer for you in the Variable Watcher. You can now see the hex values, which will help for your diagnosing.
The issue that you have been experiencing is writing and reading from the UART too quickly. This is because you are testing by connecting the TX and RX together of a UART. The EZ-B and it's connection to the controlling device is multi threaded. This means that commands are sent in another thread of the CPU. You will need to sleep() before reading from the UART.
Normally, you would always need to sleep() a little to wait for the other device to respond. The other device that you are connecting too over the UART will have a small fraction of thinking time. It will then respond over it's connection speed. The sleep() should not be significant, but it is something you will need to practice.
A smarter programming model is to wait until the desired number of bytes have been received before processing the packet.
I have attached an example you can preview. Here it is
auart.EZB
That makes sense to me to me now. I keep forgetting how fast things really happen in the scripting.
Maybe instead of sleeping a bit I can read a bunch of sensors or run a motion for my robot?
Use that extra time to do something else.
Thanks DJ I'm learning a lot.
Hope you enjoy the new Variable Watcher in the latest ARC as well
It lets you view the Hex values of the variable and length - super useful for what you are doing
I just got home from work and tried the example with the data I want to be able to TX. Here's what I got.
All unsigned byte value to 127 are TX and RX correctly Start 1: uartInit(0, 1, 1000000) 5: uartwrite(0, 1, "127") 7: sleep(100) 9: $x = uartavailable(0, 1) 11: $y = uartRead(0, 1, $x) 13: print("Bytes Read: " + $x) > Bytes Read: 1 15: $test=GetByte($y) 17: print("Read: " + $test) > Read: 127 Done (00:00:00.2496069)
All unsigned byte values from 128 to 255 are TX and RX incorrectly Start 1: uartInit(0, 1, 1000000) 5: uartwrite(0, 1, "255") 7: sleep(100) 9: $x = uartavailable(0, 1) 11: $y = uartRead(0, 1, $x) 13: print("Bytes Read: " + $x) > Bytes Read: 1 15: $test=GetByte($y) 17: print("Read: " + $test) > Read: 63 Done (00:00:00.2183817
All unsigned byte values greater than 255 will get an error, which is correct Start 1: uartInit(0, 1, 1000000) 5: uartwrite(0, 1, "256") > Error on line 5: Value was either too large or too small for an unsigned byte. Done (00:00:00.0311750)
Sorry to be a pain.
I will try to set up a development testing environment for this tonight. and will be able to test this out on the EZB4. I was crazy busy making a few other tutorial that i posted here.