Click here to Skip to main content
15,894,180 members

VB 2008 Atmel μC and PC via RS232/Tank monitoring

aparis asked:

Open original thread
Hi all,i'm asking you a question for first time.
I'm new in VB and i want to connect an Atmel with a PC via rs232,i have also installed the NI Measurement Components into my Visual Studio 2008.
The atmel is sending the value that it is reading from ADC port thru is UART port "Print Value". (i don't send chr(13)-CR)
My code in VB reads correctly the data from COM and print them into a text box.
How can i use these data in order to use them into the tank1.value=integer ?
i have try many conversions but nothing.


Imports System.IO.Ports.SerialPort
Public Class Form1

Public Delegate Sub myDelegate()

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If SerialPort1.IsOpen Then
SerialPort1.Close()
End If

Try
With SerialPort1
.PortName = "Com4"
.BaudRate = 9600
.Parity = IO.Ports.Parity.None
.DataBits = 8
.StopBits = IO.Ports.StopBits.One
.ReceivedBytesThreshold = 1
End With

SerialPort1.Open()


Catch ex As Exception
End Try

End Sub

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

Try
SerialPort1.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try

End Sub

Private Sub DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) _
Handles SerialPort1.DataReceived
TextBox1.Invoke(New myDelegate(AddressOf updateTextBox), New Object() {})
End Sub


Public Sub updateTextBox()
Dim tankval As integer
tankval = AscW(CChar(SerialPort1.ReadExisting))
With TextBox1
.Font = New Font("Garamond", 12.0!, FontStyle.Bold)
.AppendText(SerialPort1.ReadExisting)
.ScrollToCaret()
Tank1.Value = tankval
TextBox2.Text = tankval
End With
End Sub

End Class
Tags: Visual Basic (Visual Basic 8 (2005))

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900