#Region Module Attributes
#FullScreen: False
#IncludeTitle: True
#ApplicationLabel: TestTcpIp
#VersionCode: 1
#VersionName:
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim Socket1 As Socket
Dim AStreams As AsyncStreams
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim Wert01 As Long
Dim Wert02 As Long
Dim Wert03 As Long
Dim Wert04 As Long
Dim btnConnect As Button
Dim lblMsg As Label
Dim label1 As Label
Private btnAN As Button
Private btnAUS As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
Socket1.Initialize("Socket1")
If FirstTime = True Then
End If
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btnConnect_Click
Select Case btnConnect.Text
Case "Connect"
btnConnect.Text = "Disconnect"
Socket1.Initialize("Socket1")
Socket1.Connect("192.168.178.29",2000,5000)
btnConnect.Enabled = True
Case "Disconnect"
btnConnect.Text = "Connect"
Socket1.Close
AStreams.Close
'ExitApplication
Case Else
End Select
End Sub
Sub Socket1_Connected(Connected As Boolean)
If Connected = True Then
ToastMessageShow("Connected",True)
AStreams.Initialize(Socket1.InputStream,Socket1.OutputStream,"Astreams")
Else
ToastMessageShow("Server not available",True)
AStreams.Close
Socket1.Close
btnConnect.Text = "Connect"
End If
btnConnect.Enabled = True
End Sub
Sub AStreams_NewData (Buffer() As Byte)
Dim msg As String
Dim cMsg As String
msg = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
Dim unsignedi As Int
Dim signedb As Byte
'
' msg = BytesToString(Buffer, 0, Buffer.Length, "ASCII")
'
For i = 0 To msg.Length -1
signedb = Buffer(i)
unsignedi = Bit.And(0xff, signedb)
cMsg = cMsg & Chr(unsignedi)
Next
Dim msg_trennen() As String = Regex.Split("\|",msg)
Select Case msg_trennen(0).Trim
Case "34FirstConnect"
lblMsg.Text = msg_trennen(1)
End Select
'Log(cMsg)
'lblMsg.Text = " / " & msg.Length & " - " & msg
label1.Text = cMsg
End Sub
private Sub btnAN_Click
Wert01 = 255
Wert02 = 255
Wert03 = 255
Wert04 = 255
CallSub(Me, SchaltZustandSenden)
End Sub
private Sub btnAUS_Click
Wert01 = 0
Wert02 = 0
Wert03 = 0
Wert04 = 0
CallSub(Me, SchaltZustandSenden)
End Sub
Private Sub SchaltZustandSenden()
CallSub2(Me, "SEND_TO_DEVICE", CreateMap("WERT1":WERT1, "WERT2":WERT2, "WERT3":WERT3, "WERT4":WERT4))
End Sub
#Region "Commandos"
private Sub SEND_TO_DEVICE(MAPE As Map)
SendComando("1|" & MAPE.Get("WERT1") & "|" & MAPE.Get("WERT2") & "|" & MAPE.Get("WERT3") & "|" & MAPE.Get("WERT4") & CRLF)
End Sub
#End Region
Sub SendComando(msg As String)
Dim Buffer() As Byte
msg = msg & CRLF
Buffer = msg.GetBytes("ISO-8859-1")
AStreams.Write(Buffer)
AStreams.Write2(Buffer,0,Buffer.Length)
End Sub