#Region Project Attributes
#MainFormWidth: 500
#MainFormHeight: 500
#End Region
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private sp As Serial
Private astreamO As AsyncStreamsObject
Private client As Socket
Private port As Int = 32118
Dim btnConnect As Button
Private btnSendFile As Button
Private cmbPort As ComboBox
Private btn_BT_Connect As Button
Private Tipo_Conexao As String
Private diretorio As String
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.Title = "myApp"
MainForm.RootPane.LoadLayout("Up_Data") 'Load the layout file.
MainForm.Show
MainForm.BackColor = fx.Colors.White
sp.Initialize("")
cmbPort.Items.AddAll(sp.ListPorts)
End Sub
Sub MainForm_Closed
astreamO.Close
sp.Close
End Sub
Sub btnConnect_Action
astreamO.Initialize(Me, "astreamO")
client.Initialize("client")
client.Connect(txtIP.Text,port, 30000)
File.WriteString(File.DirApp, "ip.txt", txtIP.Text)
Tipo_Conexao = "Wifi"
End Sub
Sub StartAstream(s As Socket)
astreamO.Start(s.InputStream, s.OutputStream)
End Sub
Sub StartAstream_Serial(s As Serial)
astreamO.Start(s.GetInputStream, s.GetOutputStream)
End Sub
Sub client_Connected (Successful As Boolean)
If Successful Then
StartAstream(client)
Tipo_Conexao = "Wifi"
Else
Log("Error: " & LastException)
txt_Eventos.Text = txt_Eventos.Text & "Error: " & LastException & CRLF
End If
End Sub
Sub Server_NewConnection (Successful As Boolean, NewSocket As Socket)
If Successful Then
StartAstream(NewSocket)
fx.Msgbox(MainForm, LastException.Message, "Exception")
Else
fx.Msgbox(MainForm, "Error", "Error")
End If
End Sub
Sub AstreamO_Terminated
client.Close
client.Initialize("client")
sp.Close
sp.Initialize("")
End Sub
Sub astreamO_NewObject(Key As String, Value As Object)
Dim fileName As String = Value
Log("File " & Key & " received - size: " & File.Size(astreamO.TempFolder, fileName))
If File.Exists(diretorio, Key) Then
File.Delete(diretorio, Key)
End If
File.Copy(astreamO.TempFolder, fileName, diretorio, Key)
End Sub
Sub btnSendFile_Action
If astreamO.IsConnected = True Then
Dim res As Int
diretorio = File.DirData("myApp")
astreamO.WriteFile("zEPI.cfg", diretorio & "\Temp", "txtfile.txt")
Else
fx.Msgbox(MainForm, "Not Connected", "Warning")
End If
End Sub
Sub btn_BT_Connect_Action
Tipo_Conexao = "Bluetooth"
Try
sp.Initialize("")
sp.Open(cmbPort.Value)
Catch
If LastException.Message.Contains("Port busy.") = True Then
Dim rspt As Int
rspt = fx.Msgbox2(MainForm, "Port " & cmbPort.Items.Get(cmbPort.SelectedIndex) & " is busy" & CRLF & CRLF & "Want to close it and try again?", "Warning", "Yes", "", "No", fx.MSGBOX_CONFIRMATION)
If rspt = fx.DialogResponse.POSITIVE Then
sp.Close
sp.Initialize("")
End If
End If
Return
End Try
astreamO.Initialize(Me, "astreamO")
StartAstream_Serial(sp)
End Sub