I have a VB form communicating with an arduino over wifi.
I would like to send more things at a time As long as I keep it as it is... it works OK If I try to send more info I get an exception that the bounds of the array are exceeded...
I can't find anywhere where the bounds of the array are being set. If I try to set them, I get a bunch of errors down where the array is being used
Why can I not use more than 3 elements of the array "dataseparate"?
If I try to send more things separated by commas from the arduino, I get a similar error on the VB form
thank you
Realolman
I would like to send more things at a time As long as I keep it as it is... it works OK If I try to send more info I get an exception that the bounds of the array are exceeded...
I can't find anywhere where the bounds of the array are being set. If I try to set them, I get a bunch of errors down where the array is being used
Why can I not use more than 3 elements of the array "dataseparate"?
If I try to send more things separated by commas from the arduino, I get a similar error on the VB form
thank you
Realolman
VB.NET:
'// create by Nur Ahmad'
'//github.com/wiwidnadw
'//Youtube channel : Digitalneering
'//Support my platform on github and Youtube by Like, share and subs ! Enjoy
REM Modified from Forum !!!!!
Imports System.ComponentModel
Imports System.IO
'Imports System.Net
Imports System.Net.Sockets
'Imports System.Reflection.Emit
Public Class Form1
Dim client As TcpClient
Dim Rx As StreamReader
Dim Tx As StreamWriter
Dim rawdata As String
Dim dataseparate As Array
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Create a list of strings by using a
' collection initializer.
Dim millis As New List(Of ULong) From
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
For Each milli As ULong In millis
Console.Write(milli & " ")
Next
ToolStripStatusLabel1.Text = "Form Ready"
CheckForIllegalCrossThreadCalls = False
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
'connect'
Try
client = New TcpClient(IP_address.Text, "1000")
If client.GetStream.CanRead = True Or client.GetStream.CanWrite Then
Rx = New StreamReader(client.GetStream)
Tx = New StreamWriter(client.GetStream)
Threading.ThreadPool.QueueUserWorkItem(AddressOf Connected)
Button3.Visible = False
Button4.Visible = True
Button4.Enabled = True
End If
Catch ex As Exception
MsgBox("Failed to connect")
End Try
End Sub
Function Connected()
If Rx.BaseStream.CanRead = True Then
btnTime.Enabled = True
Try
While Rx.BaseStream.CanRead = True
rawdata = Rx.ReadLine
ToolStripStatusLabel1.Text = rawdata
dataseparate = rawdata.Split(",")
Label2.Text = dataseparate(0)
Label5.Text = dataseparate(1)
Label7.Text = dataseparate(2)
lblPin3.Text = dataseparate(3)
'lblPin4.Text = dataseparate(4)
'lblPin5.Text = dataseparate(5)
'lblPin6.Text = dataseparate(6)
'lblPin7.Text = dataseparate(7)
'lblPin8.Text = dataseparate(8)
'lblPin9.Text = dataseparate(9)
'lblPin10.Text = dataseparate(10)
'lblPin11.Text = dataseparate(11)
'lblPin12.Text = dataseparate(12)
End While
Catch ex As Exception
btnTime.Enabled = False
client.Close()
MsgBox(ex.Message)
ToolStripStatusLabel1.Text = "Disconnected!"
End Try
Rx.DiscardBufferedData()
End If
Return True
End Function
Function MSG1(ByVal Data As String)
REM Creates a messageBox for new threads to stop freezing
ToolStripStatusLabel1.Text = Data
Return True
End Function
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
'disconnect'
'Timer1.Enabled = False
client.Close()
Button3.Visible = True
Button4.Visible = False
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'led 1'
SendToServer("led1" & vbCr)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
'led 2'
SendToServer("led2" & vbCr)
End Sub
Function SendToServer(ByVal data As String)
Try
tbxSent.Text = data
Tx.WriteLine(data)
Tx.Flush()
Catch ex As Exception
MsgBox(ex.Message)
End Try
tbxSent2.Text = data
Return True
End Function
Private Sub IP_address_TextChanged(sender As Object, e As EventArgs) Handles IP_address.TextChanged
End Sub
Private Sub Label7_Click(sender As Object, e As EventArgs) Handles Label7.Click
End Sub
Private Sub Label2_Click(sender As Object, e As EventArgs) Handles Label2.Click
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs)
End Sub
Private Sub btnSendReturn_Click(sender As Object, e As EventArgs) Handles btnSendReturn.Click
SendToServer(vbCr)
End Sub
Private Sub Label6_Click(sender As Object, e As EventArgs) Handles Label6.Click
End Sub
Private Sub Label3_Click(sender As Object, e As EventArgs) Handles Label3.Click
End Sub
Private Sub Form1_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing
Try
client.Close()
Button3.Visible = True
Button4.Visible = False
Catch ex As Exception
'MsgBox(ex.Message)
MsgBox("Form Closed... resources released")
End Try
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles btnTime.Click
lblTime.Text = (DateTime.Now.ToString("HH:mm:ss"))
SendToServer("time")
SendToServer(DateTime.Now.ToString("HH:mm:ss"))
End Sub
Private Sub btnData_Click(sender As Object, e As EventArgs) Handles btnData.Click
SendToServer("data")
End Sub
End Class
Last edited by a moderator: