loading
 
sending extended ascii in variable
Roland from South Africa  [107 posts]
11 year

If I have a variable, say, position = 82

How Do I get the value 82 to send out an "R" ? I want to send out the single byte, as 'position' will later actually be 160 - 223, or hA0 to hDF in the program

so in the 'Send now' serial window on a loop-back, I type \82 and get;
send  \82
recv   R

good. Exactly what I want.

But if I set my variable with the Set Variable function
send_cmd      [position]

I get
send \82
recv  \82

or if I do
send_cmd      \[position]

I get
send \[position]
recv  \[position]

What is the right syntax?
Steven Gentner from United States  [1446 posts] 11 year
Roland,

The variable is only evaluated once so a nested command will not work. So when you put

[send_cmd]

and its contents are \[position] then the variable will exand to just \[position] but not evaluate its content. Its a common issue in programming, you only eval the contents once. What you are missing is that you see to specify

\[send_cmd]

in the serial module and then in VB or whatever

SetVariable "send_cmd", GetVariable("position")

which takes the content of position and assigns it to send_cmd. What you are doing is assigning the value "position" to the variable send_cmd which is why you are confused.

STeven.
Roland from South Africa  [107 posts] 11 year

Hi Steven

Double lines \\ came through in the email, so I don't know if that is confusing things. This is not about loops, or nested loops, only about how to get upper ASCII values out the serial port.

In the serial port window, the variable to send is, say "ket"

If I go the 'Send Now' window, and type R, and send it out. The cable is a loop back. I get R back. So far so good. But I can also type 'backslash'82, and the return character is R. I'm not going to use the backslash line as the email somehow doubles it up.
If I use, as you say;
ket = 82
SetVariable "ket", ket
SetVariable "messsage", GetVariable("ket")

then it send out the digits 82, and not R

Here we're just uring R as an example, but I want to send ASCII 192, a single byte, out the port from a VB script. It will then echo back, since it's non-printable in the window as 'backslash'192.

Please could you tell me what I should type, as indicated by the attached pic, in the script and the serial box. I've tried all the combinations I can think of.

Help appreciated.
Roland



 
Steven Gentner from United States  [1446 posts] 11 year
Roland,

If your Send Sequence you would insert a single backslash just before the [keypad_cmd]

The single backslash tells the system to get the value of the variable and send a single 1 byte number. In your example that would mean the binary value 82 would be sent ... or interpreted as a character the letter R.

You should be able to type that into the Send Now and see the 'R' (assuming the radio button is set to Ascii) be returned.

Can you give it a quick try and see what happens?

STeven.

Roland from South Africa  [107 posts] 11 year

Hi Steven

Sorry, had to get some shuteye. No. I tried that already, see pic. I was hoping you could fire up a screen and confirm.

Roland


 
Steven Gentner from United States  [1446 posts] 11 year
Works for me. Using the attached robofile and the following Arduino script:

void setup()
{
  Serial.begin(9600);
}

unsigned char tst[2];

void loop()
{
  while (Serial.available()>0)
  {
    tst[0] = Serial.read();

    Serial.write(tst, 1);
  }
}

I'd recommend checking that your robofile actually has keypad_cmd set before the Serial module and that something else is not unsetting it.

While screenshots are nice, perhaps you could instead include your robofile.

STeven.
program.robo
Roland from South Africa  [107 posts] 11 year

Thanks.
Gee, odd. I set it up tonight and it works. mmm, looks like when I got around to the right syntax, I was sending to the COM port with my controller on, and not the echo port. It was a very long day........

More questions to come... but I'll send the file. Didn't think of that :-)

Roland

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index