Identifying Serial Strings As Specific Strings
Identifying Serial Strings As Specific Strings
Identifying Serial Strings As Specific Strings
Identifying Serial Strings As Specific Strings
Identifying Serial Strings As Specific Strings
Identifying Serial Strings As Specific Strings Identifying Serial Strings As Specific Strings Identifying Serial Strings As Specific Strings Identifying Serial Strings As Specific Strings Identifying Serial Strings As Specific Strings Identifying Serial Strings As Specific Strings Identifying Serial Strings As Specific Strings Identifying Serial Strings As Specific Strings
Identifying Serial Strings As Specific Strings Identifying Serial Strings As Specific Strings
Identifying Serial Strings As Specific Strings
Go Back  Xtreme Visual Basic Talk > > > Identifying Serial Strings As Specific Strings


Reply
 
Thread Tools Display Modes
  #1  
Old 07-20-2011, 10:53 PM
Flyingsound115 Flyingsound115 is offline
Newcomer
 
Join Date: Jul 2011
Posts: 18
Question Identifying Serial Strings As Specific Strings


So I've got a microcontroller that sends (to make it simple) sends the string:

XX

To COM18 with a baud rate of 9600 every 1/2 second(s?)

I know how to open the port, and I know how to send stuff to the board but reading it has been very annoying.

So what I would think would happen would be that I declare an string like:

Dim CORRECT1 As String = "XX"

Then I would use the button press event to:

if Inport.readline.tostring = CORRECT1 = true then

msgbox("success!")

end if

What am I doing wrong? is it the double ='s? is it the readline? (as i'm sending it very frequently)?

Please Help!

I'm using 2010
Reply With Quote
  #2  
Old 07-21-2011, 08:34 AM
AtmaWeapon's Avatar
AtmaWeaponIdentifying Serial Strings As Specific Strings AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Odds are the string you get could have additional characters. Use the debugger or message boxes to see what the string really contains.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #3  
Old 07-21-2011, 07:53 PM
Flyingsound115 Flyingsound115 is offline
Newcomer
 
Join Date: Jul 2011
Posts: 18
Default

Quote:
Odds are the string you get could have additional characters. Use the debugger or message boxes to see what the string really contains.
I've tried this and it is not the case. I can't figure out what's happening!
Reply With Quote
  #4  
Old 07-22-2011, 08:29 AM
AtmaWeapon's Avatar
AtmaWeaponIdentifying Serial Strings As Specific Strings AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

I'm not sure I trust your evaluation. If the result of reading from the port is "XX" then your comparison should not fail. If you verified both values are as expected and the result of the comparison is True and the If statement decided to pretend it was false, then you'd be in a seriously messed up state.

One point of style: the "= True" comparison is superfluous. If statements automatically compare their condition to true, so when you add another comparison it's wasteful. In other words, it's like you're doing this:
Code:
Dim result As Boolean = inport.ReadLine().ToString() = CORRECT1
Dim shouldExecute As Boolean = result = True
If shouldExecute Then
    ...
For that matter, why call ToString() on the result of ReadLine()? It's already a string. Why convert a string to a string? Let's make this easier to debug:
Code:
Dim readData As String = inPort.ReadLine()
If readData = CORRECT1 Then
    MessageBox.Show("Success!")
End If
If that doesn't work, you can use the debugger to verify the values or add some diagnostic messages:
Code:
Dim readData As String = inPort.ReadLine()

Dim builder As New Text.StringBuilder()
builder.AppendFormat("Read '{0}' from the port.", readData)
builder.AppendLine()
builder.AppendFormat("This has {0} characters.", readData.Length)
builder.AppendLine()
builder.AppendFormat("It is compared to '{0}', ({1} characters.)", CORRECT1, CORRECT1.Length)
builder.AppendLine()
builder.AppendFormat("The result of that comparison is {0}.", readData = CORRECT1)
MessageBox.Show(builder.ToString())
...
This verifies several things that could be a problem. It verifies the read string doesn't have any extra whitespace characters you can't see by enclosing it in quotes *and* reporting its length. It verifies the CORRECT1 string has a value and the value is what you expect. Finally, it ensures the comparison itself returns the result you expect. If all of this comes out as you expect, then I suspect the problem is elsewhere and you're going to have to proide mroe than 4 lines of code to solve this puzzle.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #5  
Old 07-25-2011, 09:50 PM
Flyingsound115 Flyingsound115 is offline
Newcomer
 
Join Date: Jul 2011
Posts: 18
Default

Quote:
Dim readData As String = inPort.ReadLine()
If readData = CORRECT1 Then
MessageBox.Show("Success!")
End If
YES! This worked thank you so much!
Reply With Quote
Reply

Tags
serial string arduino


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Identifying Serial Strings As Specific Strings
Identifying Serial Strings As Specific Strings
Identifying Serial Strings As Specific Strings Identifying Serial Strings As Specific Strings
Identifying Serial Strings As Specific Strings
Identifying Serial Strings As Specific Strings
Identifying Serial Strings As Specific Strings Identifying Serial Strings As Specific Strings Identifying Serial Strings As Specific Strings Identifying Serial Strings As Specific Strings Identifying Serial Strings As Specific Strings Identifying Serial Strings As Specific Strings Identifying Serial Strings As Specific Strings
Identifying Serial Strings As Specific Strings
Identifying Serial Strings As Specific Strings
 
Identifying Serial Strings As Specific Strings
Identifying Serial Strings As Specific Strings
 
-->