Dim MapRelays As Map
MapRelay.Initialize
MapRelay.Put("Relay1", "12.26.0.206")
MapRelay.Put("Relay2", "12.16.0.206")
For Each relay As String In MapRelays.Keys
Log(k)
'Populate your Spinner
Spinner1.Add(relay)
Next
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
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 EditText1 As EditText
Dim EditText2 As EditText
Dim EditText3 As EditText
Dim EditText4 As EditText
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Settings")
EditText1.Text = Main.HostName1
EditText2.Text = Main.HostName2
EditText3.Text = Main.HostName3
EditText4.Text = Main.HostName4
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button2_Click
Activity.Finish
End Sub
Sub Button1_Click
Dim s As List
Main.HostName1 = EditText1.Text
Main.HostName2 = EditText2.Text
Main.HostName3 = EditText3.Text
Main.HostName4 = EditText4.Text
s.Initialize
s.Add(Main.HostName1)
s.Add(Main.HostName2)
s.Add(Main.HostName3)
s.Add(Main.HostName4)
File.WriteList(File.DirInternal, "AppSettings", s)
Activity.Finish
End Sub
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim HostName1 As String
Dim HostName2 As String
Dim HostName3 As String
Dim HostName4 As String
Dim ViewExtChs As Boolean
Dim Timer1 As Timer
Dim sock 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 ImageView1 As ImageView
Dim ImageView2 As ImageView
Dim ImageView3 As ImageView
Dim ImageView4 As ImageView
Dim Label1 As Label
Dim Label2 As Label
Dim Label3 As Label
Dim Label5 As Label
Dim Panel1 As Panel
Dim sockBusy As Boolean
Dim busyTime As Long
Dim ModuleConnected As Boolean
Dim CommandBuff As String
Dim NewState As String
Dim StateBuff As String
Dim Spinner1 As Spinner
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Dim s As List
Activity.LoadLayout("Main")
Activity.AddMenuItem("Configuracion", "mnuSettings")
If FirstTime Then
If File.Exists(File.DirInternal, "AppSettings") Then
s = File.ReadList(File.DirInternal, "AppSettings")
HostName1 = s.Get(0)
HostName2 = s.Get(1)
HostName3 = s.Get(2)
HostName4 = s.Get(3)
Else
HostName1 = "172.26.0.206"
HostName2 = "172.16.0.206"
HostName3 = "172.26.0.6"
HostName4 = "172.16.0.6"
End If
Timer1.Initialize("Timer1", 5000)
End If
Spinner1.Add(HostName1)
Spinner1.Add(HostName2)
End Sub
Sub Activity_Resume
Spinner1.Clear
Spinner1.Add(HostName1)
Spinner1.Add(HostName2)
Timer1.Enabled = True
ModuleConnected = False
Panel1.Visible = False
Timer1_Tick
End Sub
Sub Activity_Pause (UserClosed As Boolean)
Timer1.Enabled = False
If sockBusy Then
If AStreams.IsInitialized Then
AStreams.Close
End If
If sock.IsInitialized Then
sock.Close
End If
sockBusy = False
End If
End Sub
Sub Timer1_Tick
If sockBusy Then
If sock.Connected Then
If DateTime.Now - busyTime > DateTime.TicksPerSecond * 10 Then
If AStreams.IsInitialized Then
AStreams.Close
End If
sock.Close
sockBusy = False
End If
End If
Else
Timer1.Interval = 1000
sockBusy = True
sock.Initialize("sock")
sock.Connect(Spinner1.SelectedItem, 6722, 10000)
busyTime = DateTime.Now
End If
End Sub
Sub sock_Connected (Successful As Boolean)
If Successful Then
ModuleConnected = True
AStreams.Initialize(sock.InputStream, sock.OutputStream, "AStreams")
If CommandBuff = "" Then
AStreams.Write("00".GetBytes("ASCII"))
Else
AStreams.Write(CommandBuff.GetBytes("ASCII"))
CommandBuff = ""
End If
Else
SetModuleOffline
End If
End Sub
Sub AStreams_Error
AStreams.Close
SetModuleOffline
End Sub
Sub AStreams_NewData (Buffer() As Byte)
NewState = BytesToString(Buffer, 0, Buffer.Length, "ASCII")
AStreams.Close
ParseModuleState
sock.Close
Panel1.Visible = False
sockBusy = False
End Sub
Sub mnuSettings_Click
StartActivity("Settings")
End Sub
Sub SetModuleOffline
ModuleConnected = False
StateBuff = ""
ImageView1.Bitmap = LoadBitmap(File.DirAssets, "btn_disable.png")
ImageView1.Invalidate
ImageView2.Bitmap = LoadBitmap(File.DirAssets, "btn_disable.png")
ImageView2.Invalidate
ImageView3.Bitmap = LoadBitmap(File.DirAssets, "btn_off.png")
ImageView3.Invalidate
ImageView4.Bitmap = LoadBitmap(File.DirAssets, "btn_off.png")
ImageView4.Invalidate
Panel1.Visible = False
sock.Close
sockBusy = False
End Sub
Sub ParseModuleState
If StateBuff = "" Or NewState.CharAt(0) <> StateBuff.CharAt(0) Then
If NewState.CharAt(0) = "1" Then
ImageView1.Bitmap = LoadBitmap(File.DirAssets, "btn_on.png")
Else
ImageView1.Bitmap = LoadBitmap(File.DirAssets, "btn_off.png")
End If
ImageView1.Invalidate
End If
If StateBuff = "" Or NewState.CharAt(1) <> StateBuff.CharAt(1) Then
If NewState.CharAt(1) = "1" Then
ImageView2.Bitmap = LoadBitmap(File.DirAssets, "btn_on.png")
Else
ImageView2.Bitmap = LoadBitmap(File.DirAssets, "btn_off.png")
End If
ImageView2.Invalidate
End If
If StateBuff = "" Or NewState.CharAt(2) <> StateBuff.CharAt(2) Then
If NewState.CharAt(2) = "1" Then
ImageView3.Bitmap = LoadBitmap(File.DirAssets, "btn_on.png")
Else
ImageView3.Bitmap = LoadBitmap(File.DirAssets, "btn_off.png")
End If
ImageView3.Invalidate
End If
If StateBuff = "" Or NewState.CharAt(3) <> StateBuff.CharAt(3) Then
If NewState.CharAt(3) = "1" Then
ImageView4.Bitmap = LoadBitmap(File.DirAssets, "btn_on.png")
Else
ImageView4.Bitmap = LoadBitmap(File.DirAssets, "btn_off.png")
End If
ImageView4.Invalidate
End If
StateBuff = NewState
End Sub
Sub ImageView1_Click
If ModuleConnected Then
Panel1.Visible = True
If StateBuff.CharAt(0) = "0" Then
CommandBuff = "11"
Else
CommandBuff = "21"
End If
Timer1.Interval = 250
End If
End Sub
Sub ImageView2_Click
If ModuleConnected Then
Panel1.Visible = True
If StateBuff.CharAt(1) = "0" Then
CommandBuff = "12*"
Else
CommandBuff = "22*"
End If
Timer1.Interval = 250
End If
End Sub
Sub ImageView3_Click
StartActivity("Ping1")
End Sub
Sub ImageView4_Click
StartActivity("Ping2")
End Sub
Dim MapRelays As Map
MapRelay.Initialize
MapRelay.Put("Relay1", "12.26.0.206")
MapRelay.Put("Relay2", "12.16.0.206")
For Each relay As String In MapRelays.Keys
Log(k)
'Populate your Spinner
Spinner1.Add(relay)
Next
It should be : Log(relay). There is no k. Jose is doing a great job walking you throughLog(k)
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim HostName1 As String
Dim HostName2 As String
Dim HostName3 As String
Dim HostName4 As String
Dim ViewExtChs As Boolean
Dim Timer1 As Timer
Dim sock 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 ImageView1 As ImageView
Dim ImageView2 As ImageView
Dim ImageView3 As ImageView
Dim ImageView4 As ImageView
Dim Label1 As Label
Dim Label2 As Label
Dim Label3 As Label
Dim Label4 As Label
Dim Panel1 As Panel
Dim sockBusy As Boolean
Dim busyTime As Long
Dim ModuleConnected As Boolean
Dim CommandBuff As String
Dim NewState As String
Dim StateBuff As String
Dim Spinner1 As Spinner
Dim MapRelay As Map
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Dim s As List
Activity.LoadLayout("Main")
Activity.AddMenuItem("Configuracion", "mnuSettings")
If FirstTime Then
If File.Exists(File.DirInternal, "AppSettings") Then
s = File.ReadList(File.DirInternal, "AppSettings")
HostName1 = s.Get(0)
HostName2 = s.Get(1)
HostName3 = s.Get(2)
HostName4 = s.Get(3)
Else
HostName1 = "172.26.0.206"
HostName2 = "172.16.0.206"
HostName3 = "172.26.0.6"
HostName4 = "172.16.0.6"
End If
Timer1.Initialize("Timer1", 5000)
End If
MapRelay.Initialize
MapRelay.Put("Relay1", "12.26.0.206")
MapRelay.Put("Relay2", "12.16.0.206")
For Each relay As String In MapRelay.Keys
Log(relay)
'Populate your Spinner
Spinner1.Add(relay)
Next
For i = 0 To s.Size - 1
MapRelay.Put("HostName" & i , s.Get(i))
Next
End Sub
Sub Activity_Resume
Spinner1.Clear
'Spinner1.Add(HostName1)
'Spinner1.Add(HostName2)
Timer1.Enabled = True
ModuleConnected = False
Panel1.Visible = False
Timer1_Tick
End Sub
Sub Activity_Pause (UserClosed As Boolean)
Timer1.Enabled = False
If sockBusy Then
If AStreams.IsInitialized Then
AStreams.Close
End If
If sock.IsInitialized Then
sock.Close
End If
sockBusy = False
End If
End Sub
Sub Timer1_Tick
If sockBusy Then
If sock.Connected Then
If DateTime.Now - busyTime > DateTime.TicksPerSecond * 10 Then
If AStreams.IsInitialized Then
AStreams.Close
End If
sock.Close
sockBusy = False
End If
End If
Else
Timer1.Interval = 1000
sockBusy = True
sock.Initialize("sock")
sock.Connect(Spinner1.SelectedItem, 6722, 10000)
busyTime = DateTime.Now
End If
End Sub
Sub sock_Connected (Successful As Boolean)
If Successful Then
ModuleConnected = True
AStreams.Initialize(sock.InputStream, sock.OutputStream, "AStreams")
If CommandBuff = "" Then
AStreams.Write("00".GetBytes("ASCII"))
Else
AStreams.Write(CommandBuff.GetBytes("ASCII"))
CommandBuff = ""
End If
Else
SetModuleOffline
End If
End Sub
Sub AStreams_Error
AStreams.Close
SetModuleOffline
End Sub
Sub AStreams_NewData (Buffer() As Byte)
NewState = BytesToString(Buffer, 0, Buffer.Length, "ASCII")
AStreams.Close
ParseModuleState
sock.Close
Panel1.Visible = False
sockBusy = False
End Sub
Sub mnuSettings_Click
StartActivity("Settings")
End Sub
Sub SetModuleOffline
ModuleConnected = False
StateBuff = ""
ImageView1.Bitmap = LoadBitmap(File.DirAssets, "btn_disable.png")
ImageView1.Invalidate
ImageView2.Bitmap = LoadBitmap(File.DirAssets, "btn_disable.png")
ImageView2.Invalidate
ImageView3.Bitmap = LoadBitmap(File.DirAssets, "btn_off.png")
ImageView3.Invalidate
ImageView4.Bitmap = LoadBitmap(File.DirAssets, "btn_off.png")
ImageView4.Invalidate
Panel1.Visible = False
sock.Close
sockBusy = False
End Sub
Sub ParseModuleState
If StateBuff = "" Or NewState.CharAt(0) <> StateBuff.CharAt(0) Then
If NewState.CharAt(0) = "1" Then
ImageView1.Bitmap = LoadBitmap(File.DirAssets, "btn_on.png")
Else
ImageView1.Bitmap = LoadBitmap(File.DirAssets, "btn_off.png")
End If
ImageView1.Invalidate
End If
If StateBuff = "" Or NewState.CharAt(1) <> StateBuff.CharAt(1) Then
If NewState.CharAt(1) = "1" Then
ImageView2.Bitmap = LoadBitmap(File.DirAssets, "btn_on.png")
Else
ImageView2.Bitmap = LoadBitmap(File.DirAssets, "btn_off.png")
End If
ImageView2.Invalidate
End If
If StateBuff = "" Or NewState.CharAt(2) <> StateBuff.CharAt(2) Then
If NewState.CharAt(2) = "1" Then
ImageView3.Bitmap = LoadBitmap(File.DirAssets, "btn_on.png")
Else
ImageView3.Bitmap = LoadBitmap(File.DirAssets, "btn_off.png")
End If
ImageView3.Invalidate
End If
If StateBuff = "" Or NewState.CharAt(3) <> StateBuff.CharAt(3) Then
If NewState.CharAt(3) = "1" Then
ImageView4.Bitmap = LoadBitmap(File.DirAssets, "btn_on.png")
Else
ImageView4.Bitmap = LoadBitmap(File.DirAssets, "btn_off.png")
End If
ImageView4.Invalidate
End If
StateBuff = NewState
End Sub
Sub ImageView1_Click
If ModuleConnected Then
Panel1.Visible = True
If StateBuff.CharAt(0) = "0" Then
CommandBuff = "11"
Else
CommandBuff = "21"
End If
Timer1.Interval = 250
End If
End Sub
Sub ImageView2_Click
If ModuleConnected Then
Panel1.Visible = True
If StateBuff.CharAt(1) = "0" Then
CommandBuff = "12*"
Else
CommandBuff = "22*"
End If
Timer1.Interval = 250
End If
End Sub
Sub ImageView3_Click
StartActivity("Ping1")
End Sub
Sub ImageView4_Click
StartActivity("Ping2")
End Sub
Sub Process_Globals
...
Dim HostName1 As String
Dim HostName2 As String
Dim HostName3 As String
Dim HostName4 As String
...
End Sub
Sub Activity_Create(FirstTime As Boolean)
Dim s As List
....
If FirstTime Then
If File.Exists(File.DirInternal, "AppSettings") Then
s = File.ReadList(File.DirInternal, "AppSettings")
HostName1 = s.Get(0)
HostName2 = s.Get(1)
HostName3 = s.Get(2)
HostName4 = s.Get(3)
Else
HostName1 = "172.26.0.206"
HostName2 = "172.16.0.206"
HostName3 = "172.26.0.6"
HostName4 = "172.16.0.6"
End If
'**********Here you got your hostnames set in their variables, now we put in a map the host name (HostNameX) with their ip address
MapHosts.Initialize
MapHosts.Put("HostName1", HostName1)
MapHosts.Put("HostName2", HostName2)
MapHosts.Put("HostName3", HostName3)
MapHosts.Put("HostName4", HostName4)
'***********************************************
Timer1.Initialize("Timer1", 5000)
End If
For Each host As String In MapHosts.Keys
'Populate your Spinner
Spinner1.Add(host)
Next
End Sub
Private Sub Spinner1_ItemClick (Position As Int, Value As Object)
Log(Value)
'Now, we get the ip from the map
Log(MapHosts.Get(Value))
End Sub
[code]
#Region Project Attributes
#ApplicationLabel: Relé Theos
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: portrait
#CanInstallToExternalStorage: True
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim HostName1 As String
Dim HostName2 As String
Dim HostName3 As String
Dim HostName4 As String
Dim ViewExtChs As Boolean
Dim Timer1 As Timer
Dim sock 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 ImageView1 As ImageView
Dim ImageView2 As ImageView
Dim ImageView3 As ImageView
Dim ImageView4 As ImageView
Dim Label1 As Label
Dim Label2 As Label
Dim Label3 As Label
Dim Label4 As Label
Dim Panel1 As Panel
Dim sockBusy As Boolean
Dim busyTime As Long
Dim ModuleConnected As Boolean
Dim CommandBuff As String
Dim NewState As String
Dim StateBuff As String
Dim Spinner1 As Spinner
Dim MapHosts As Map
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Dim s As List
Activity.LoadLayout("Main")
Activity.AddMenuItem("Configuracion", "mnuSettings")
If FirstTime Then
If File.Exists(File.DirInternal, "AppSettings") Then
s = File.ReadList(File.DirInternal, "AppSettings")
HostName1 = s.Get(0)
HostName2 = s.Get(1)
HostName3 = s.Get(2)
HostName4 = s.Get(3)
Else
HostName1 = "172.26.0.206"
HostName2 = "172.16.0.206"
HostName3 = "172.26.0.6"
HostName4 = "172.16.0.6"
End If
'**********Here you got your hostnames set in their variables, now we put in a map the host name (HostNameX) with their ip address
MapHosts.Initialize
MapHosts.Put("Cáceres", HostName1)
MapHosts.Put("Badajoz", HostName2)
'MapHosts.Put("Hostname3", HostName3)
'MapHosts.Put("Hostname4", HostName4)
'***********************************************
Timer1.Initialize("Timer1", 5000)
End If
'Spinner1.Add(HostName1)
'Spinner1.Add(HostName2)
For Each host As String In MapHosts.Keys
'Populate your Spinner
Spinner1.Add(host)
Next
End Sub
public Sub Spinner1_ItemClick (Position As Int, Value As Object)
Log(Value)
'Now, we get the ip from the map
Log(MapHosts.Get(Value))
End Sub
Sub Activity_Resume
'Spinner1.Clear
'Spinner1.Add(HostName1)
'Spinner1.Add(HostName2)
Timer1.Enabled = True
ModuleConnected = False
Panel1.Visible = False
Timer1_Tick
End Sub
Sub Activity_Pause (UserClosed As Boolean)
Timer1.Enabled = False
If sockBusy Then
If AStreams.IsInitialized Then
AStreams.Close
End If
If sock.IsInitialized Then
sock.Close
End If
sockBusy = False
End If
End Sub
Sub Timer1_Tick
If sockBusy Then
If sock.Connected Then
If DateTime.Now - busyTime > DateTime.TicksPerSecond * 10 Then
If AStreams.IsInitialized Then
AStreams.Close
End If
sock.Close
sockBusy = False
End If
End If
Else
Timer1.Interval = 1000
sockBusy = True
sock.Initialize("sock")
sock.Connect(Spinner1.SelectedItem, 6722, 10000)
busyTime = DateTime.Now
End If
End Sub
Sub sock_Connected (Successful As Boolean)
If Successful Then
ModuleConnected = True
AStreams.Initialize(sock.InputStream, sock.OutputStream, "AStreams")
If CommandBuff = "" Then
AStreams.Write("00".GetBytes("ASCII"))
Else
AStreams.Write(CommandBuff.GetBytes("ASCII"))
CommandBuff = ""
End If
Else
SetModuleOffline
End If
End Sub
Sub AStreams_Error
AStreams.Close
SetModuleOffline
End Sub
Sub AStreams_NewData (Buffer() As Byte)
NewState = BytesToString(Buffer, 0, Buffer.Length, "ASCII")
AStreams.Close
ParseModuleState
sock.Close
Panel1.Visible = False
sockBusy = False
End Sub
Sub mnuSettings_Click
StartActivity("Settings")
End Sub
Sub SetModuleOffline
ModuleConnected = False
StateBuff = ""
ImageView1.Bitmap = LoadBitmap(File.DirAssets, "btn_disable.png")
ImageView1.Invalidate
ImageView2.Bitmap = LoadBitmap(File.DirAssets, "btn_disable.png")
ImageView2.Invalidate
ImageView3.Bitmap = LoadBitmap(File.DirAssets, "btn_off.png")
ImageView3.Invalidate
ImageView4.Bitmap = LoadBitmap(File.DirAssets, "btn_off.png")
ImageView4.Invalidate
Panel1.Visible = False
sock.Close
sockBusy = False
End Sub
Sub ParseModuleState
If StateBuff = "" Or NewState.CharAt(0) <> StateBuff.CharAt(0) Then
If NewState.CharAt(0) = "1" Then
ImageView1.Bitmap = LoadBitmap(File.DirAssets, "btn_on.png")
Else
ImageView1.Bitmap = LoadBitmap(File.DirAssets, "btn_off.png")
End If
ImageView1.Invalidate
End If
If StateBuff = "" Or NewState.CharAt(1) <> StateBuff.CharAt(1) Then
If NewState.CharAt(1) = "1" Then
ImageView2.Bitmap = LoadBitmap(File.DirAssets, "btn_on.png")
Else
ImageView2.Bitmap = LoadBitmap(File.DirAssets, "btn_off.png")
End If
ImageView2.Invalidate
End If
If StateBuff = "" Or NewState.CharAt(2) <> StateBuff.CharAt(2) Then
If NewState.CharAt(2) = "1" Then
ImageView3.Bitmap = LoadBitmap(File.DirAssets, "btn_on.png")
Else
ImageView3.Bitmap = LoadBitmap(File.DirAssets, "btn_off.png")
End If
ImageView3.Invalidate
End If
If StateBuff = "" Or NewState.CharAt(3) <> StateBuff.CharAt(3) Then
If NewState.CharAt(3) = "1" Then
ImageView4.Bitmap = LoadBitmap(File.DirAssets, "btn_on.png")
Else
ImageView4.Bitmap = LoadBitmap(File.DirAssets, "btn_off.png")
End If
ImageView4.Invalidate
End If
StateBuff = NewState
End Sub
Sub ImageView1_Click
If ModuleConnected Then
Panel1.Visible = True
If StateBuff.CharAt(0) = "0" Then
CommandBuff = "11"
Else
CommandBuff = "21"
End If
Timer1.Interval = 250
End If
End Sub
Sub ImageView2_Click
If ModuleConnected Then
Panel1.Visible = True
If StateBuff.CharAt(1) = "0" Then
CommandBuff = "12*"
Else
CommandBuff = "22*"
End If
Timer1.Interval = 250
End If
End Sub
Sub ImageView3_Click
StartActivity("Ping1")
End Sub
Sub ImageView4_Click
StartActivity("Ping2")
End Sub
sock.Connect(Spinner1.SelectedItem, 6722, 10000)
sock.Connect(MapHosts.Get(Spinner1.SelectedItem), 6722, 10000)
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?