Dim AStream As AsyncStreamsText
Dim Client As Socket
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Main")
Client.Initialize("Client")
End sub
Sub CBConnect_Click
If Client.IsInitialized=False Then Client.Initialize("Client")
Client.Connect("192.168.2.7",40000, 20000)
End Sub
Sub Client_Connected (Successful As Boolean)
If Successful Then
If AStream.IsInitialized Then AStream.Close
ToastMessageShow("Connected", False)
AStream.Initialize(Me,"AStream",Client.InputStream,Client.OutputStream)
TBReceive.text="Verbinding tot stand gebracht"
EnDisable(True)
Else
ToastMessageShow(LastException.Message, True)
End If
End Sub
Public Sub Send (Mess As String)
If Client.Connected=False Then
CBConnect_Click
End If
If AStream.IsInitialized = False Then AStream.Initialize(Me,"AStream",Client.InputStream,Client.OutputStream)
P1.Enabled=False
AStream.Write(Mess&CRLF)
End Sub
Dim BStream As AsyncStreamsText
Dim server As ServerSocket
Sub AppStart (Args() As String)
Dim i As Int
sp.initialize("AStream")
Log(sp.ListPorts)
sp.Open("/dev/ttyUSB0")
sp.SetParams(9600,8,1,0)
For i=0 To 23
table(i).Initialize
Next
AStream.Initialize(Me, "AStream",sp.GetInputStream,sp.GetOutputStream)
server.Initialize(40000,"server")
server.listen
DateTime.DateFormat="dd MMM yy "
DateTime.TimeFormat="HH 'uur' mm 'min' ss 'sec'"
controller.Initialize
Pin1.Initialize(1, False) 'GpioPinDigitalOutput
StartMessageLoop
End Sub
Sub server_NewConnection (Successful As Boolean, NewSocket As Socket) 'internet
If Successful Then
BStream.Initialize(Me, "BStream",NewSocket.InputStream, NewSocket.OutputStream)
Else
Log (LastException.Message)
End If
server.Listen
End Sub
Sub BStream_NewText(Text As String)
Dim reply As String
Pin1.Pulse(300)
If Text= "1" Then
reply=elecconsumption & cr
BStream.Write(reply)
End sub