Welcome to Synthiam!

Program robots using technologies created from industry experts. ARC is our free-to-use robot programming software that makes features like vision recognition, navigation and artificial intelligence easy.

Get Started
Asked — Edited

How To Mask The Serial 8Th Bit

Hi all and DJ,

I'm trying to figure out the syntax to mask the 8th bit of a packet serial command from EZ-B to RobotClaw Motor Controller, any help would be appreciated if it's possible on the EZ-B.

On other MCU's that I have I use this format...

Serout P15, i19200, [128, 0, 127 (255 & 0x7F) ]

Serout - well that's the command for output from the serial port,

in EZ-b that would be SendSerial.

P15 - is the port ...EZ-B D0

i19200 - is the baud rate...EZ-B just 19200 or whatever baud i use..

The 128, 0, 127, (255 & 0x7F) is "address, command, address, (checksum & 0x7F)

the 0x7F is the Hex code to mask the 8th bit.

Sooooo...

EZ-B code...

SendSerial ( D0, 19200, 128, 0, 127, (255 & 0x7F )

but it won't accept the "(255 & 0x7F)"

clear as mud eh!





:)

AI Support Bot
Related Content
Synthiam
Based on your post activity, we found some content that may be interesting to you. Explore these other tutorials and community conversations.
PRO
Synthiam
#1  
255 & 0x7f = 127

So you'd use

Code:


SendSerial ( D0, 19200, 128, 0, 127, 127)


Check the datasheet for the motor controller, as that doesn't look correct. The datasheet i gave a quick look at is here. And the syntax for Simple Serial is...

Code:


# Stop
SendSerial(d0, 19200, 0)

# Channel 1 reverse
SendSerial(d0, 19200, 1)

# Channel 1 stop
SendSerial(d0, 19200, 64)

# Channel 1 forward
SendSerial(d0, 19200, 127)

# Channel 2 reverse
SendSerial(d0, 19200, 128)

# Channel 2 stop
SendSerial(d0, 19200, 192)

# Channel 2 forward
SendSerial(d0, 19200, 255)

# Both Channels Forward
SendSerial(d0, 19200, 127, 255)

# Both Channels Reverse
SendSerial(d0, 19200, 1, 128)

# Turn Left
SendSerial(d0, 19200, 1, 255)

# Turn Right
SendSerial(d0, 19200, 127, 128)
#2  
Thanks for the reply DJ but....

Sorry the device i'm using is the RobotClaw dual 30 amp

The simple serial is ok, it's the packet serial code that I need to use for my bot.

The problem is that the 255 & 0x7F comes up as an error in EZ-B,

the 255 is the checksum for the "128, 0 127, " and the & 0x7F is mask for the 8th bit
PRO
Synthiam
#3  
255 & 0x7f is decimal 127

127 = (255 & 0x7f) = 127 = (255 & 0x7f) = 127:)
#4  
I agree the 0x7F = 127 but the line of code is

SendSerial ( D0, 19200, 128, 0, 127, (255 & 0x7F ))


It still wouldn't work if I sent it like this

SendSerial ( D0, 19200, 128, 0, 127, (255 & 127 ))

because EZ-B doesn't like the & symbol

when I try to save in the script config I get the error...

Syntax Error: (255 & 127 is not in a valid format.
PRO
Synthiam
#6  

Code:


SendSerial ( D0, 19200, 128, 0, 127, 127)


(255 & 0x7f) = 127
#7  
ok so what would the code look like for

SendSerial ( D0, 19200, 128, 3, 89, (220 & 0x7F ))
PRO
Synthiam
#8  

Code:


SendSerial ( D0, 19200, 128, 3, 89, 92)


1) Load Windows Calculator
2) select View and choose Programmer
3) To enter 220 (which is decimal) select DEC from the radio buttons
4) Enter 220
5) Press AND
6) To enter 0x7f (which is hex) select HEX from the radio buttons
7) Enter 7f
8) Press =
9) The answer will be displayed in HEX because that is the last format you used. Simply press DEC to view it in decimal

Windows calculator is actually quite powerful - I use it often

Who ever documented that protocol did a terrible job. I can see performing a bitwise AND operation on a variable, but not a constant. By performing (220 & 0x7f) would use many unneeded cycles of operations within the processor; where simply entering the value would suffice.

:)
#9  
The code is for an Atom Pro 28 to RobotClaw , there must be a reason why it's done that way.
#10  
@DJ

I've setup the RobotClaw and EZ-B and all seems well so far THANKS, and thanks for putting up with my thick brain, I've been using Basic Atom pro for so long that I couldn't see how just the decimal number would work, it's never used that way for programing the Pro.

And now for another question...

This has probably been asked, can all the D ports be used for serial in and out?

And is there a command like "ReceiveSerial" or "GetSerial" etc.
PRO
Synthiam
#11  
There is no GetSerial. There are not enough free clock cycles to receive serial input during PID execution. Our new hardware guy is working on an EZ-Bit for that:)
#12  
Ok,

Why doesn't this line work with the variables

SendSerial (D0, 38400, 128, 6, "$L" , "$CS6" )

The variables work when using the print command but not in the line of code
PRO
Synthiam
#13  

Code:


SendSerial (D0, 38400, 128, 6, $L , $CS6 )
#14  
Won't work.....error: not a valid format *confused*
PRO
Synthiam
#15  
Ah, fixed for the next release:)