Canada
Asked — Edited

Uart Question When Tx And Receiving Unsigned Chr

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


ARC Pro

Upgrade to ARC Pro

Become a Synthiam ARC Pro subscriber to unleash the power of easy and powerful robot programming

PRO
Synthiam
#1  

The value being received is correct - what the symbol looks like (i.e. a y with dots of a ?) is due to Windows Locale interpreting the character and should not be used to determine if it is the correct variable:)

Use the GetByteAt() command or GetByte() command to return the ascii ordinal value.

*Note: I removed the other duplicate post. We can use this one

#2  

Thanks DJ I should have tried that first. I appreciate your patience.

#3  

I just tried your suggestion and I received the value 63 which is the code for " ? ". I believe there may be a bug in the EZ Scipt.
The following is from the console after running the script.

Start 1: $handshake=GetAsByte(255) 2: $AX_ID=GetAsByte(14)
3: $length=GetAsByte(7) 4: $AX_Write_Data=GetAsByte(3) 5: $table=GetAsByte(30) 6: $LSB=GetAsByte(188) 7: $MSB=GetAsByte(2) 8: $LSB2=GetAsByte(30) 9: $MSB2=GetAsByte(0) 10: $checksum=GetAsByte(237) 13: $test=$handshake+$handshake+$AX_ID+$length+$AX_Write_Data+$table+$LSB+$MSB+$LSB2+$MSB2+$checksum 18: UARTWrite(0,1,$test) 28: $x = UartAvailable(0, 1) 30: print("Bytes in buffer: " + $x) > Bytes in buffer: 11 32: $RX_DATA = UARTRead(0, 1, $x) 34: print("Received: " + $RX_DATA) > Received: ?? 36: $Data_0=GetByteAt($RX_DATA,0) 37: $Data_2=GetByteAt($RX_DATA,2) 39: Print ($Data_0 +" "+ $Data_2) > 63 14 # 63 is the question mark and 14 is the correct number Done (00:00:00.4523841)

PRO
Synthiam
#4  

Do you have a logic analyzer? I believe it might help you diagnose the issue.

If you would like to experiment without a Logic Analyzer, you can use the Serial Terminal (EZB) found in the General section of Project -> Add Control

What device are you connecting to?

#5  

I'm using the EZ-B port D5 and sending it to the Dynamixel servo, ID14 and using a return data line to the EZ-B port D6.

#6  

I just sent the same instruction from D5 to D6 without the Dynamixel servo and received the same result.

There are no issues if a send text with quotation marks its only when I send unsigned char.

#7  

I did a little research.

I think you have data framing issue within the coding for the EZ Script. Check the settings for the data frame size and or the parity and stop bits.

PRO
Synthiam
#8  

The EZ-B has no data framing issues in our testing. And unless there is a physical defect with the STM32 ARM Processors, the UARTs are working as expected. The ez-b firmware has all UARTs set for...


  USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  USART_InitStructure.USART_StopBits = USART_StopBits_1;
  USART_InitStructure.USART_Parity = USART_Parity_No;
  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

Perhaps your wire has line noise. Can you show me a logic analyzer screenshot of the framing error you are referring to?

Also, keep in mind that your script is constantly Initializing the UART in the first line of code. You only need to initialize it once - perhaps in a different script or Connection Script?

Every time you run the code the UART is being physically re-initialized. That's like starting and stopping your car's engine at every street light.:)

#9  

@DJ.... For clarification you only need to call UARTInit once per ARC session?.... Is there a timeout or will it stay initialized until you close out your ARC session?

PRO
Synthiam
#10  

The UARTInit() will initialize the UART until the EZ-B v4 has been power cycled

#11  

@DJ .... Sweet...helps to make my code more efficient..... Love leaning new stuff about the ezb...

#12  

I don't want to keep beating a dead horse but for my peace of mind could you two guys try this example and let me know what you RX.

I have a jumper wire connecting D5 and and D6.

Try substituting different values in the $test.

UARTInit(0,1,1000000)

$test1=GetAsByte(125) $test2=GetAsByte(180) $test3=GetAsByte(75) $test4=GetAsByte(255)

$data=$test1+$test2+$test3+$test4

UARTWrite(0,1,$data)

$x = UartAvailable(0, 1)

print("Bytes in buffer: " + $x)

$RX_DATA = UARTRead(0, 1, $x)

print("Received: " + $RX_DATA)

Print(GetByteAt($RX_DATA,0)) Print(GetByteAt($RX_DATA,1)) Print(GetByteAt($RX_DATA,2)) Print(GetByteAt($RX_DATA,3))

PRO
Synthiam
#13  

What do you expect $data to look like when you do this?


$test1=GetAsByte(125)
$test2=GetAsByte(180)
$test3=GetAsByte(75)
$test4=GetAsByte(255)

$data=$test1+$test2+$test3+$test4

Tell me what you expect to see in $data?

Do you expect to see many bytes? Or do you expect to see the values of each variable added together?

#14  

The $data should come out as a list with 125,180,75,and 255. It just saves typing a separate line for each value and sending it.

Even if I send the data one at a time a still don't RX the proper value.

I'm sorry I used python to send data to the Dynamixel servos and Arduino nano. and it is working.

PRO
Synthiam
#15  

In all programming languages, that will add the values together into one value. Only strings can be appended with the + symbol. (including Arduino, which uses C++)

String example


$x = "banana"
$y = "apple"

$z = $x + $y

Math example...


$x = 1
$y = 5

$z = $x + $y

What do you think $z would equal in each example?

#16  

I understand but did you try running the script ? What values are you RX in your console ?

PRO
Synthiam
#17  

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?:D

#18  

Please give me the solution.

PRO
Synthiam
#19  

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

PRO
Synthiam
#20  

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

#21  

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.

PRO
Synthiam
#22  

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

#23  

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.

#24  

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.

PRO
Synthiam
#26  

I'll take a look at it tomorrow when i'm at the office - in my tests, I was pushing 255 with the uart without any issues - and receiving 255. But, i'll take a look to make sure there isn't something I have overlooked

What do you think about the new Variable Watcher? Now that you can view Hex values?

#27  

I have tested this and confirmed mtiberia findings.

Here is my Test Bed.

User-inserted image

This is my results

I hope this can help.

Could the issue have to do with 7bit and 8bit as 7bit can count only to 0-127 and 8bit can store 0-255? <- Just thinking....

#28  

I think you may be correct. It's only when using the UART through the EZ script because EZ B can communicate with the dynamical servos that need the 8 bits to represent values from 0 to 255.

#31  

YESSSSSSS Awseome thanks DJ !

Now you can give Masimo Banzi a run for his money. I'm surprised he hasn't made you offer you can't refuse.

Forget about it.

Thanks

#32  

@mtiberia ...

Quote:

".I'm surprised he hasn't made you offer you can't refuse."
In a couple years it will be the other way around....;)