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
How to read variables over UART/RS232?
Moderator: Benj
- 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?
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):
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_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_VALCode: 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