1. Home
  2. Docs
  3. MANUALS AND DATASHEETS
  4. EasyVR 3 Plus Manual
  5. EasyVR Programming
  6. Communication Examples

Communication Examples

These are some examples of actual command and status characters exchanged with the EasyVR module by host programs and the expected program flow with pseudo-code sequences.

The pseudo-instruction SEND transmits the specified character to the module, while RECEIVE waits for a reply character (a timeout is not explicitly handled for simple commands, but should be always implemented if possible).

Also, the OK and ERROR routines are not explicitly defined, since they are host and programming language dependent, but appropriate code should be written to handle both conditions.

Lines beginning with a # (sharp) character are comments.

Please note that in a real programming language it would be best to define some constants for the command and status characters, as well as for mapping numeric arguments, that would be used throughout the program, to minimize the chance of repetition errors and clarify the meaning of the code.

See the Protocol header file for sample definitions that can be used in a C language environment.

Here below all the characters sent and received are written explicitly in order to clarify the communication protocol detailed in the previous sections.

Recommended wake up procedure

# wake up or interrupt recognition or do nothing

# (uses a timeout or max repetition count)

DO

SEND 'b'

LOOP UNTIL RECEIVE = 'o'

Recommended setup procedure

# ask firmware id

SEND 'x'

IF NOT RECEIVE = 'x' THEN ERROR

# send ack and read status (expecting id=0)

SEND ' '

id = RECEIVE

IF id = 'A' THEN

# it’s a VRbot

ELSE IF id = 'B' THEN

# it’s an EasyVR

ELSE

# next generation?

END IF

# set language for SI recognition (Japanese)

SEND 'l'

SEND 'C'

IF RECEIVE = 'o' THEN OK ELSE ERROR

# set timeout (5 seconds)

SEND 'o'

SEND 'F'

IF RECEIVE = 'o' THEN OK ELSE ERROR

Recognition of a built-in or custom SI command

# start recognition in wordset 1

SEND 'i'

SEND 'B'

# wait for reply:

# (if 5s timeout has been set, wait for max 6s then abort

#  otherwise trigger recognition could never end)

result = RECEIVE

IF result = 's' THEN

# successful recognition, ack and read result
SEND ' '
command = RECEIVE – 'A'
# perform actions according to command
ELSE IF result = 't' THEN
# timed out, no word spoken
ELSE IF result = 'e' THEN
# error code, ack and read which one
SEND ' '
error = (RECEIVE – 'A') * 16
SEND ' '
error = error + (RECEIVE – 'A')
# perform actions according to error
ELSE
# invalid request or reply
ERROR
END IF

Adding a new SD command

# insert command 0 in group 3
SEND 'g'
SEND 'D'
SEND 'A'
IF RECEIVE = 'o' THEN OK ELSE ERROR

# set command label to “ARDUINO_2009”
SEND 'g'
SEND 'D'
SEND 'A'
SEND 'Q' # name length (16 characters, digits count twice)
SEND 'A'
SEND 'R'
SEND 'D'
SEND 'U'
SEND 'I'
SEND 'N'
SEND 'O'
SEND '_'
# encode each digit with a ^ prefix
# followed by the digit mapped to upper case letters
SEND '^'
SEND 'C'
SEND '^'
SEND 'A'
SEND '^'
SEND 'A'
SEND '^'
SEND 'J'
IF RECEIVE = 'o' THEN OK ELSE ERROR

Training an SD command

# repeat the whole training procedure twice for best results

# train command 0 in group 3

SEND 't'

SEND 'D'

SEND 'A'

# wait for reply:

#  (default timeout is 3s, wait for max 1s more then abort)

result = RECEIVE

IF RECEIVE = 'o' THEN

# training successful

OK

ELSE IF result = 'r' THEN

# training saved, but spoken command is similar to
# another SD command, read which one
SEND ' '
command = RECEIVE – 'A'
# may notify user and erase training or keep it
ELSE IF result = 's' THEN
# training saved, but spoken command is similar to
# another SI command (always trigger, may skip reading)
SEND ' '
command = RECEIVE – 'A'
# may notify user and erase training or keep it
ELSE IF result = 't' THEN
# timed out, no word spoken or heard
ELSE IF result = 'e' THEN
# error code, ack and read which one
SEND ' '
error = (RECEIVE – 'A') * 16
SEND ' '
error = error + (RECEIVE – 'A')
# perform actions according to error
ELSE
# invalid request or reply
ERROR
END IF

Recognition of an SD command

# start recognition in group 1
SEND 'd'
SEND 'B'
# wait for reply:
result = RECEIVE
IF result = 'r' THEN
# successful recognition, ack and read result
SEND ' '

command = RECEIVE – 'A'

# perform actions according to command

ELSE IF result = 't' THEN

# timed out, no word spoken

ELSE IF result = 'e' THEN

# error code, ack and read which one

SEND ' '

error = (RECEIVE – 'A') * 16

SEND ' '

error = error + (RECEIVE – 'A')

# perform actions according to error

ELSE

# invalid request or reply

ERROR

END IF

Read used command groups

# request mask of groups in use
SEND 'm'
IF NOT RECEIVE = 'k' THEN ERROR
# read mask to 32 bits variable
# in 8 chunks of 4 bits each
SEND ' '
mask = (RECEIVE – 'A')
SEND ' '
mask = mask + (RECEIVE – 'A') * 24
SEND ' '
mask = mask + (RECEIVE – 'A') * 28
...
SEND ' '
mask = mask + (RECEIVE – 'A') * 224

Read how many commands in a group

# request command count of group 3
SEND 'c'
SEND 'D'
IF NOT RECEIVE = 'c' THEN ERROR
# ack and read count
SEND ' '
count = RECEIVE - 'A'
IF count = -1 THEN count = 32

Read a user defined command group

# dump command 0 in group 3
SEND 'p'
SEND 'D'
SEND 'A'
IF NOT RECEIVE = 'd' THEN ERROR
# read command data
SEND ' '
training = RECEIVE – 'A'
# extract training count (2 for a completely trained command)
tr_count = training AND 7
# extract flags for conflicts (SD or SI)
tr_flags = training AND 24
# read index of conflicting command (same group) if any
SEND ' '
conflict = RECEIVE – 'A'
# read label length
SEND ' '
length =  RECEIVE – 'A'
# read label text
FOR i = 0 TO length - 1
SEND ' '
label[i] = RECEIVE
# decode digits
IF label[i] = '^' THEN
SEND ' '
label[i] = RECEIVE – 'A' + '0'
END IF
NEXT

Use general purpose I/O pins

# set IO1 pin to logic low level
SEND 'q'
SEND 'B'
SEND 'A'
IF RECEIVE = 'o' THEN OK ELSE ERROR

# set IO2 pin to logic high level
SEND 'q'
SEND 'C'
SEND 'B'
IF RECEIVE = 'o' THEN OK ELSE ERROR

# set IO2 pin as input with strong pull-up and read state
SEND 'q'
SEND 'C'
SEND 'D'
IF NOT RECEIVE = 'p' THEN ERROR
# ack and read logic level
SEND ' '
pin_level = RECEIVE – 'A'

# set IO3 pin as high impedance input (reading state is optional)
SEND 'q'
SEND 'D'
SEND 'C'
IF NOT RECEIVE = 'p' THEN ERROR

Use custom sound playback

# play a beep at full volume (works with any or no table)
SEND 'w'
SEND 'A'
SEND 'A'
SEND 'P'
IF RECEIVE = 'o' THEN OK ELSE ERROR

# play entry 13 at half volume
SEND 'w'
SEND 'A'
SEND 'N'
SEND 'H'
IF RECEIVE = 'o' THEN OK ELSE ERROR

# play entry 123 (=3*32+26) at max volume
SEND 'w'
SEND 'A' + 3
SEND 'A' + 26
SEND 'A' + 31
IF RECEIVE = 'o' THEN OK ELSE ERROR

Read sound table

# dump sound table
SEND 'h'
IF NOT RECEIVE = 'h' THEN ERROR
# read count of entries and name length
SEND ' '
count = (RECEIVE – 'A') * 32
SEND ' '
count = count + (RECEIVE – 'A')
SEND ' '
length = RECEIVE – 'A'
# read name text
FOR i = 0 TO length - 1
SEND ' '
label[i] = RECEIVE
NEXT

How can we help?