Hello.
I am trying to connect two sensors via bluetooth serial port. Data came every 400 ms when timer tick in form $data1#data2*. When I separate to text fields, program is slowing down, and i don`t know why?
Here is code, so if can somebody help. Thanks!
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Dim btnOpen As Button
Dim cmbPort As ComboBox
Dim txtinput As TextField
Dim txtInput2 As TextField
Dim txtinput3 As TextField
Dim txtLog As TextArea
Dim lblStatus As Label
Dim lblTime As Label
Private sp As Serial
Private tmr As Timer
Private textreader1 As TextReader
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("1") 'Load the layout file.
MainForm.Show
MainForm.Title = "BLUETOOTH SERIAL"
MainForm.BackColor = fx.Colors.Blue
sp.Initialize("Serial1")
tmr.Initialize("Timer1", 400)
cmbPort.Items.AddAll(sp.ListPorts)
txtinput.Style = "-fx-font-size: 40;"
txtInput2.Style = "-fx-font-size: 30;"
txtinput3.Style = "-fx-font-size: 30;"
End Sub
Sub cmbPort_SelectedIndexChanged(Index As Int, Value As Object)
btnOpen.Enabled = Index > -1 'enable the button if there is a selected item
End Sub
Sub btnOpen_Action
If btnOpen.Text = "Connect" Then
sp.Open(cmbPort.Value)
textreader1.Initialize(sp.GetInputStream)
tmr.Enabled = True
txtinput.Enabled = True
btnOpen.Text = "Disconnect"
lblStatus.text = "Status: Connected"
Else
If btnOpen.Text = "Disconnect" Then
tmr.Enabled = False
sp.Close
btnOpen.Text = "Connect"
End If
End If
End Sub
Sub MainForm_Closed
sp.Close
End Sub
Sub Timer1_Tick
Dim n1 As Int,n2 As Int,n3 As Int, temp_str As String, S As String
temp_str=textreader1.ReadLine
txtinput3.text = temp_str
n1=temp_str.IndexOf("$")
n2=temp_str.IndexOf("#")
n3=temp_str.IndexOf("*")
S=temp_str.SubString2(n2+1,n3)
txtInput2.Text = temp_str.SubString2(n1+1,n2)
txtinput.Text = S
End Sub
I am trying to connect two sensors via bluetooth serial port. Data came every 400 ms when timer tick in form $data1#data2*. When I separate to text fields, program is slowing down, and i don`t know why?
Here is code, so if can somebody help. Thanks!
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Dim btnOpen As Button
Dim cmbPort As ComboBox
Dim txtinput As TextField
Dim txtInput2 As TextField
Dim txtinput3 As TextField
Dim txtLog As TextArea
Dim lblStatus As Label
Dim lblTime As Label
Private sp As Serial
Private tmr As Timer
Private textreader1 As TextReader
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("1") 'Load the layout file.
MainForm.Show
MainForm.Title = "BLUETOOTH SERIAL"
MainForm.BackColor = fx.Colors.Blue
sp.Initialize("Serial1")
tmr.Initialize("Timer1", 400)
cmbPort.Items.AddAll(sp.ListPorts)
txtinput.Style = "-fx-font-size: 40;"
txtInput2.Style = "-fx-font-size: 30;"
txtinput3.Style = "-fx-font-size: 30;"
End Sub
Sub cmbPort_SelectedIndexChanged(Index As Int, Value As Object)
btnOpen.Enabled = Index > -1 'enable the button if there is a selected item
End Sub
Sub btnOpen_Action
If btnOpen.Text = "Connect" Then
sp.Open(cmbPort.Value)
textreader1.Initialize(sp.GetInputStream)
tmr.Enabled = True
txtinput.Enabled = True
btnOpen.Text = "Disconnect"
lblStatus.text = "Status: Connected"
Else
If btnOpen.Text = "Disconnect" Then
tmr.Enabled = False
sp.Close
btnOpen.Text = "Connect"
End If
End If
End Sub
Sub MainForm_Closed
sp.Close
End Sub
Sub Timer1_Tick
Dim n1 As Int,n2 As Int,n3 As Int, temp_str As String, S As String
temp_str=textreader1.ReadLine
txtinput3.text = temp_str
n1=temp_str.IndexOf("$")
n2=temp_str.IndexOf("#")
n3=temp_str.IndexOf("*")
S=temp_str.SubString2(n2+1,n3)
txtInput2.Text = temp_str.SubString2(n1+1,n2)
txtinput.Text = S
End Sub
