Asked — Edited
Resolved Resolved by DJ Sures!

Error On Line 25: Missing String Quotes

I'm getting an error message in one of my scripts that is giving me some trouble. It's a random error meaning that it will happen every few times the command is run. It's set in a loop so it will repeat. Sometimes it will even cause the connection between the EZB and computer to cut off. Here'e the error:


Error on line 25: Missing String Quotes or Invalid Expression at index 14: "

and


Error on line 25: Missing String Quotes or Invalid Expression at index 15: "

Here's the script to happens in. Seems to center around the print commands. Once I removed the print command at line 25 and the error skipped to the next one. I've also expanded the sleep() commands thinking it was running too fast but it does not help. Thanks for looking :


# This Script will return the actual position number of the left catrrage
# #from the Kangaroo withough the 1,p in the begining.
# #Returning feedback with the 1,p causes problems.
# #Do Not Delete. Other scripts depend on this script!

# -------------------------------------
# Get Roo position

uartWrite(2, 2, "2, Getp", 0x0d)

:waitForData
Sleep(30)

$y_lft = UartAvailable(2, 2)
Sleep(30)
print("Bytes in buffer:" + $y_lft)

if ($y_lft < 6)
  # Go back and wait for data again because we did not receive the least number of expected bytes.
  goto(waitForData)
endif
Sleep(30)
$Get_Lft_Carrage_P = UARTRead(2, 2, $y_lft)
Sleep(30)
print("Received: " + $Get_Lft_Carrage_P)

Sleep( 50 )

# -------------------------------
# Find out and print if the P is upper or lower case.
# Upper case means motor has finished move ans stoped.
# Lower Case means that motor is still moving.

$P_lft_or_p_lft = GetCharAt($Get_Lft_Carrage_P, 2) #Assign a variable to either a capitol P or Small case p returned by Kangaroo.

Print("P_lft_or_p_lft:" + $P_lft_or_p_lft)

# -----------------------------
# Defeat the P_lft_or_p_lft

if ($P_lft_or_p_lft = "p")
  Goto(Lower_p_Split)
ELSEif ($P_lft_or_p_lft = "P")
  Goto(Upper_P_Split)
endif

Sleep( 50 )

:Lower_p_Split

$Lft_Carrage_Position = Split($Get_Lft_Carrage_P, "p",1) #1,pXXXX is returned. Get everything after the Lower case p (P is case senceitive).
Sleep(30)
print("Received:" + $Lft_Carrage_Position)
Halt()

:Upper_P_Split
$Lft_Carrage_Position = Split($Get_Lft_Carrage_P, "P",1) #1,pXXXX is returned. Get everything after the Upper case P (P is case senceitive).
Sleep(30)
print("Received:" + $Lft_Carrage_Position)


ARC Pro

Upgrade to ARC Pro

With Synthiam ARC Pro, you're not just programming a robot; you're shaping the future of automation, one innovative idea at a time.

#17  

Understood Will. Well Will, will you mind if I assert my will here in all things Will? I insist that Will's project be given full priority if DJ is willing. I'd hate Will to willfully insist that he was first in line. Will , I hear you're a scary and dangerous dude when you're mad and I don't yet have my Will prepared. God willing, it won't have to come to that. (That was a whole lot of Wills):P

PRO
USA
#18  

Ahh yes that was me! Brain fart....can you hear that sound ? That's brain cells dying! Thanks DJ!

Lol Dave!

#19  

After working on this issue for the past few days and trying many different things I'm certain the EZB disconnect issue was that I was calling for information from the same Uart port at the same time by two different scripts. After I reset the timing of these commands the disconnect problem went away.

However no matter what I do I cant get the "random" Missing String Quotes or invalided expression" error to go away.

I rewrote my script to determine if the "P" in 1,p820 is upper or lower case. This tells me simply if my move has completed or is still in process. After disabling all the print commands that we thought were the problem I'm now getting this error in other commands. Here's that script:


# Get Right and Left Channel ARS Kangaroo position
#######################################

Get Right Channel ARS Kangaroo position
uartWrite(2, 2, &quot;1, Getp&quot;, 0x0d)

:waitForData
Sleep(30)

$y = UartAvailable(2, 2)
# Sleep(30)
# print(&quot;Bytes in buffer:&quot; + $y)

if ($y &lt; 6)
  # Go back and wait for data again because we did not receive the least number of expected bytes.
  goto(waitForData)
endif
  # Sleep(30)
$Get_Rt_Carrage_P = UARTRead(2, 2, $y)
# Sleep(30)
# print(&quot;Received:&quot; + $Get_Rt_Carrage_P)

# Sleep( 50 )

# -------------------------------------
# Get Left ARS Kangaroo position
uartWrite(2, 2, &quot;2, Getp&quot;, 0x0d)

:waitForData_2
# Sleep(30)

$y_lft = UartAvailable(2, 2)
# Sleep(30)
#print(&quot;Bytes in buffer:&quot; + $y_lft)

if ($y_lft &lt; 6)
  # Go back and wait for data again because we did not receive the least number of expected bytes.
  goto(waitForData_2)
endif
  # Sleep(30)
$Get_Lft_Carrage_P = UARTRead(2, 2, $y_lft)
# Sleep(30)
#print(&quot;Received: &quot; + $Get_Lft_Carrage_P)

Sleep( 50 )

# ###################################################
# -------------------------------
# Find out and print if the Rt P is upper or lower case.
# Upper case means motor has finished move ans stoped.
# Lower Case means that motor is still moving.

$Rt_P_or_p = GetCharAt($Get_Rt_Carrage_P, 2) #Assign a variable to either a capitol P or Small case p returned by Kangaroo.

#Print(&quot;$Rt_P_or_p:&quot; + $Rt_P_or_p)
Sleep(100)
$Lft_P_or_p = GetCharAt($Get_Lft_Carrage_P, 2) #Assign a variable to either a capitol P or Small case p returned by Kangaroo.

#Print(&quot;Lft_P_or_p:&quot; + $Lft_P_or_p)

This is the latest problem command in the above script getting the Missing String Quotes or Invaded Expression error (and it does not have any quotes in it):


$Rt_P_or_p = GetCharAt($Get_Rt_Carrage_P, 2)

It has got to be as DJ says and be the Variables causing an "Invalided Expression". In the above command I'm trying to extract the 3rd character of something that looks this read: 1,p820. I'm trying to pull the "p" out and store it in a variable. I'm basing this on the example in the Scripting Cheat Sheet:


$char = GetCharAt($x, 2)

Maybe I'm using the wrong command? should I be using the GetByteAt command? Is 1,p820 outside of readable ASCII?


$value = GetByteAt($x, 2) 

Any thoughts? confused

PRO
Synthiam
#20  

It's the wrong UARTRead command. Use UARTReadBinary() and read the data into an array. You split the data into an array anyway.

Quote:

UARTRead( boardIndex, port, numBytes ) Receive ASCII bytes from the Peripheral UART Receive Buffer of the EZ-B v4. The UART receive buffers on the EZ-B v4 are 5,000 bytes. To know how many bytes are available, use the UARTAvailable() function. The Board Index is the EZ-B index starting at 0. The port can be 0, 1 or 2. Look near at the UART Port section lower in this document for the EZ-B Pin’s associated with each UART Port. Example: UARTRead(0, 0, 10) Example: UARTRead(0, 0, UARTAvailable(0, 1))

UARTReadBinary( boardIndex, port, numBytes, variable ) Receive binary bytes from the Peripheral UART Receive Buffer of the EZ-B v4 into the variable as an array. The UART receive buffers on the EZ-B v4 are 5,000 bytes. To know how many bytes are available, use the UARTAvailable() function. The Board Index is the EZ-B index starting at 0. The port can be 0, 1 or 2. Look near at the UART Port section lower in this document for the EZ-B Pin’s associated with each UART Port. Example: UARTReadBinary(0, 0, 10, $variable) Example: UARTReadBinary(0, 0, UARTAvailable(0, 1), $variable)

PRO
Synthiam
#21  

Here...


# Get Right and Left Channel ARS Kangaroo position
uartWrite(2, 2, &quot;1, Getp&quot;, 0x0d)

:waitForData
Sleep(30)

$y = UartAvailable(2, 2)
# Sleep(30)
# print(&quot;Bytes in buffer:&quot; + $y)

if ($y &lt; 6)
  # Go back and wait for data again because we did not receive the least number of expected bytes.
  goto(waitForData)
endif

# Sleep(30)
UartReadBinary(2, 2, $y, $Get_Rt_Carrage_P)

# -------------------------------------
# Get Left ARS Kangaroo position
uartWrite(2, 2, &quot;2, Getp&quot;, 0x0d)

:waitForData_2
# Sleep(30)

$y_lft = UartAvailable(2, 2)
# Sleep(30)
#print(&quot;Bytes in buffer:&quot; + $y_lft)

if ($y_lft &lt; 6)
  # Go back and wait for data again because we did not receive the least number of expected bytes.
  goto(waitForData_2)
endif
  # Sleep(30)
  
UartReadBinary(2, 2, $y, $Get_Lft_Carrage_P)

Sleep( 50 )

# ###################################################
# -------------------------------
# Find out and print if the Rt P is upper or lower case.
# Upper case means motor has finished move ans stoped.
# Lower Case means that motor is still moving.

#Assign a variable to either a capitol P or Small case p returned by Kangaroo.
$Rt_P_or_p = $Get_Rt_Carrage_P[2]

#Print(&quot;$Rt_P_or_p:&quot; + $Rt_P_or_p)

Sleep(100)

$Lft_P_or_p = Get_Lft_Carrage_P[2]

#Print(&quot;Lft_P_or_p:&quot; + $Lft_P_or_p)

#22  

OMG thanks! eek You saved me about two days of struggle and probability saved my marriage in the process. LOL.

Looking through your rewrite I was very close. Just missing a few of the right words and proper brackets. LOL. I'll give it a try. :D

#23  

OK, that seems to be running when I test it in the console and ARC is connected to EZB in the robot.

However, I'm getting the number 80 returned instead of the "P" I'm expecting. Do I need to convert this returned number to a letter "P" somehow in the script after it's returned? If so will this number be different if a lower case "p" or some other numberis returned? If the number 80 is equivalent to a "P" and I know it then this will work.

Sorry, I feel like a blind man here. What do the [] do at the end of: $Lft_P_or_p = $Get_Lft_Carrage_P[2] ?

Here is what is returned in the console:


7: uartWrite(2, 2, &quot;1, Getp&quot;, 0x0d)
9: :waitForData
10: Sleep(30)
12: $y = UartAvailable(2, 2)
13: Sleep(30)
14: print(&quot;Bytes in buffer:&quot; + $y)
&gt; Bytes in buffer:7
16: if ($y &lt; 6)
19: endif
21: Sleep(30)
22: UartReadBinary(2, 2, $y, $Get_Rt_Carrage_P)
24: Sleep(250)
28: uartWrite(2, 2, &quot;2, Getp&quot;, 0x0d)
30: :waitForData_2
31: Sleep(30)
33: $y_lft = UartAvailable(2, 2)
34: Sleep(30)
35: print(&quot;Bytes in buffer:&quot; + $y_lft)
&gt; Bytes in buffer:7
37: if ($y_lft &lt; 6)
40: endif
41: Sleep(30)
43: UartReadBinary(2, 2, $y_lft, $Get_Lft_Carrage_P)
45: Sleep( 250 )
54: $Rt_P_or_p = $Get_Rt_Carrage_P[2]
56: Print(&quot;$Rt_P_or_p:&quot; + $Rt_P_or_p)
&gt; $Rt_P_or_p:80
58: Sleep(100)
60: $Lft_P_or_p = $Get_Lft_Carrage_P[2]
62: Print(&quot;Lft_P_or_p:&quot; + $Lft_P_or_p)
&gt; Lft_P_or_p:80
67: Halt()
Done (00:00:00.9687524)