-
November 9th, 2013, 06:31 AM
#1
Serial Com VB 2010
hi guys. i`m new to vb and here to seek advice regarding data received in serial com. i`m trying to make external hardware to control Interface in vb, which is arduino. the thing is, both serial works fine, however when i try to send "1" from arduino (even though when i monitor the serial output, it do came out "1") vb receive higher value which is 255. does the data receive thru serial to vb add up as it receive? i already tried to receive string input, end up the same and sometimes dont even works. what did i do wrong in serial receive? thanks in advanced
Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
pic1.Visible = False
pic2.Visible = False
End Sub
Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click
SerialPort1.PortName = "com3"
SerialPort1.BaudRate = 9600
SerialPort1.Encoding = System.Text.Encoding.Default
SerialPort1.Open()
btnOpen.Enabled = False
End Sub
Sub DataReceived()
Dim receiveData As Integer
receiveData = SerialPort1.ReadChar
txtReceive.Text = receiveData
If receiveData = 1 Then
pic1.Visible = True
End If
If receiveData = 2 Then
pic2.Visible = True
End If
End Sub
Delegate Sub ConnectedCallBack()
Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
Dim D As New ConnectedCallBack(AddressOf DataReceived)
Try
Me.Invoke(D)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class
Regards
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|