How to read variables over UART/RS232?

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
Niro
Posts: 77
Joined: Mon Jan 03, 2011 8:58 pm
Has thanked: 29 times
Been thanked: 10 times

How to read variables over UART/RS232?

Post by Niro »

Dear all,

I have a problem reading values of variables over UART/RS232 from my ATMega328. I want to transmit the name of the variable maybe as string from a terminal program to the microcontroller and then send the value of this variable back over RS232 to the terminal?
Does anyone know how to recognize the variables name from the sent string with FlowCode or C and then use it with the microcontroller?
I wasn't able to convert the string into a 'real' usable variables name.

Many thanks!
Niro

User avatar
Steve
Matrix Staff
Posts: 3434
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times

Re: How to read variables over UART/RS232?

Post by Steve »

There's no direct way to do this. You would need to do something like the following (assuming VAR_NAME and VAR_VAL are the two things transmitted over RS232):

Code: Select all

read VAR_NAME

if (VAR_NAME = "MyVar1") then VAR_VAL = MyVar1
if (VAR_NAME = "MyVar2") then VAR_VAL = MyVar2
if (VAR_NAME = "MyVar3") then VAR_VAL =  MyVar3
(...etc...)

send VAR_VAL
As you need to hardcode the actual variable names in this construct, you might as well use a single byte value to identify the variable. Then you could use a switch statement on this variable value to set your variables (assuming VAR_IDX is the byte value read over RS232 which identifies the variable):

Code: Select all

read VAR_IDX

switch (VAR_IDX)
  case 1: VAR_VAL = MyVar1
  case 2: VAR_VAL = MyVar2
  case 3: VAR_VAL = MyVar3
  (...etc...)

send VAR_VAL

Niro
Posts: 77
Joined: Mon Jan 03, 2011 8:58 pm
Has thanked: 29 times
Been thanked: 10 times

Re: How to read variables over UART/RS232?

Post by Niro »

Hi Steve,

unfortunately, thats the answer I was expecting :-(
So, I'm going to hardcode it...

Best regards,
Niro

Post Reply