Decode UART message

fsoender

Member
Joined
Jul 2, 2015
Messages
19
Programming Experience
Beginner
Hi,

Do anyone know how to do following:

I have buttons and Temp on a AVR Development board, I have coded the signals as follow:

Buttons: B01, B02, B03... (When pressed)

Temp: T(Value)


So my question is, how do I split these values coming in from the AVR?

I looks like this in the TeraTerm:

B01,T24,B05,T23,T23.....
 
When you say "looks like this", do you actually mean that you're getting a comma delimited string? If so, how are you currently reading the data? If not, what do you mean?
 
Sorry about the confusion.
Current data comes in like this:

T22
B04
T23
B01

Still a little confusing I'm afraid, or at least ambiguous. Does that mean that you're getting a single string that includes line breaks or that you're getting multiple strings? If it's a single string then you can simply use String.Split, but you need to know what to split on. It might be just a new line character, i.e. '\n' or it might be a carriage return and line feed pair, i.e. "\r\n". You'd use a different overload of String.Split in each case, or you could even specify to split on either if you wanted.
 
Still a little confusing I'm afraid, or at least ambiguous. Does that mean that you're getting a single string that includes line breaks or that you're getting multiple strings? If it's a single string then you can simply use String.Split, but you need to know what to split on. It might be just a new line character, i.e. '\n' or it might be a carriage return and line feed pair, i.e. "\r\n". You'd use a different overload of String.Split in each case, or you could even specify to split on either if you wanted.


Yeah, I'm using "\r\n", So I just have to learn how to read the value after an character like this:

Incoming value:

T22
B01
T23

So, I need to read the:

22
01
23

The "T" will tell me is an temperature value of 22 or 23, and "B" will tell me button 1 was pressed.
 
Hi,

I tried around little bit, and I'm almost there.
By using the code under, I get an error saying: "ArgumentOutOfRangeException was unhandled"

InputData is: T=22
InputDataNew is: 22

How can I fix this problem?



C#:
[FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000]//Write incomming data in text box.

[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]            
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] InputDataNew = InputData.Substring(2);  [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000]// Start reading from T=[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
[FONT=Consolas][SIZE=2] 
[FONT=Consolas][SIZE=2] 
[/SIZE][/FONT] 
[/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] (InputData != [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]String[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].Empty)[/SIZE][/FONT][/SIZE][/FONT]
[FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]
            {
                
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] (InputData.StartsWith([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]"T="[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]))[/SIZE][/FONT][/SIZE][/FONT]
[FONT=Consolas][SIZE=2] 
[/SIZE][/FONT] 
[FONT=Consolas][SIZE=2] 
[FONT=Consolas][SIZE=2]
 
                TempShow(InputDataNew);

            }


        }
[/SIZE][/FONT][/SIZE][/FONT]
 
Think it through. It's telling you that an argument you are providing is out of range. Where is that occurring? What argument are you providing? What is the valid range? Is your argument out of range because you're providing the wrong argument or applying it to the wrong data?
 
Back
Top Bottom