Hello. I have a tiny Arduino sketch that sends random data via Bluetooth Module (I am using HC-06) every 5 seconds and I have a VB.NET windows Application that receives and manages the data. The data would look like this
for example:
"(255**255**255)"
My VB.Net Application receives current data being sent by the Bluetooth Module, pops up a message box with the current received data and adds the data to a RichTextBox control. So the whole process should look like this:
1. String:
"(100**390**222)" gets sent via Bluetooth in Arduino code
2. Message Box pops up with the present data
"(100**390**222)"
3. String gets added to the RichTextBox control
...
Instead, it doesn't actually send the whole string at one instance, here's the actual process:
1. String:
"(100**390**222)" gets sent via Bluetooth in Arduino code
2. Message Box pops up with the present data
"("
3. String gets added to the RichTextBox control
4. Message Box pops up with the present data
"100**390**222)"
5. String gets added to the RichTextBox control
...
Sometimes, it sends the first two characters then the rest. Why doesn't it send the whole string at one instance and is there a fix to that?
What I have tried:
Here is my Arduino sketch:
#include <SoftwareSerial.h>
SoftwareSerial BTserial(15, 17);
uint8_t SomeFirstNumber, SomeSecondNumber, SomeThirdNumber;
void setup()
{
BTserial.begin(38400);
}
void loop()
{
SomeFirstNumber = random(255);
SomeSecondNumber = random(255);
SomeThirdNumber = random(255);
BTserial.print("(" + String(SomeFirstNumber) + "**" + String(SomeSecondNumber) + "**" + String(SomeThirdNumber) + ")");
delay(5000);
}
Here's my VB.Net Application:
https://images2.imgbox.com/9f/54/djv2xbck_o.png[
^]
Source:
Delegate Sub SetTextCallback(ByVal [text] As String)
Private Sub Open_Port(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_OpenPort.Click
Dim bException As Boolean = False
SerialPort1.PortName = "COM3"
SerialPort1.BaudRate = 38400
SerialPort1.Parity = IO.Ports.Parity.None
SerialPort1.StopBits = IO.Ports.StopBits.One
SerialPort1.DataBits = 8
Try
SerialPort1.Open()
Catch ex As Exception
bException = True
MsgBox(ex.Message, MsgBoxStyle.Exclamation)
End Try
If Not bException Then
MsgBox("Success!", MsgBoxStyle.Information)
End If
End Sub
Private Sub Close_Port(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_ClosePort.Click
SerialPort1.Close()
End Sub
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
ReceivedText(SerialPort1.ReadExisting())
End Sub
Private Sub ReceivedText(ByVal [text] As String)
If RichTextBox_Output.InvokeRequired Then
Dim x As New SetTextCallback(AddressOf ReceivedText)
Me.Invoke(x, New Object() {(text)})
Else
MsgBox([text])
RichTextBox_Output.Text += [text]
RichTextBox_Output.ScrollToCaret()
SerialPort1.DiscardOutBuffer()
End If
End Sub
I tried explaining as best as I could. Thank you in advance!