I share my lib
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
			
			
			
				B4X:
			
		
		
		#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#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.
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 plc(4) As Modbus_B4A_120815 '4 plc
Dim timer1 As Timer
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("Layout1")
timer1.Initialize("timer1",250)
timer1.Enabled=True
DisableStrictMode
Log(plc(0).Set_plc("192.168.2.50",1,502,2000))'wago
Log(plc(1).Set_plc("192.168.2.56",255,502,2000))'phoenix
Log(plc(2).Set_plc("192.168.2.58",1,502,2000))'wago
Log(plc(3).Set_plc("192.168.2.60",255,502,2000))'phoenix
plc(3).Connect
plc(2).Connect
plc(1).Connect
plc(0).Connect
End Sub
Sub Activity_Resume
Log(plc(0).Set_plc("192.168.2.50",1,502,2000))'wago
Log(plc(1).Set_plc("192.168.2.56",255,502,2000))'phoenix
Log(plc(0).Set_plc("192.168.2.58",1,502,2000))'wago
Log(plc(1).Set_plc("192.168.2.60",255,502,2000))'phoenix
plc(3).Connect
plc(2).Connect
plc(1).Connect
plc(0).Connect
End Sub
Sub Activity_Pause (UserClosed As Boolean)
plc(3).Disconnect
plc(2).Disconnect
plc(1).Disconnect
plc(0).Disconnect
End Sub
Sub timer1_tick
If plc(0).isConnect=True Then Log(plc(0).TCP_ReadCoils(512,16))'wago (Qx0 to Qx15)
If plc(1).isConnect=True Then Log(plc(1).TCP_ReadMultipleRegisters(16,8))'zelio %MW16 to %MW23
If plc(2).isConnect=True Then Log(plc(2).TCP_ReadInputDiscretes(0,16))'phoenix
If plc(3).isConnect=True Then Log(plc(3).TCP_ReadMultipleRegisters(12288,16))'wago (%MW0 to %MW15)
End Sub
Sub DisableStrictMode
   Dim jo As JavaObject
   jo.InitializeStatic("android.os.Build.VERSION")
   If jo.GetField("SDK_INT") > 9 Then
     Dim policy As JavaObject
     policy = policy.InitializeNewInstance("android.os.StrictMode.ThreadPolicy.Builder", Null)
     policy = policy.RunMethodJO("permitAll", Null).RunMethodJO("build", Null)
     Dim sm As JavaObject
     sm.InitializeStatic("android.os.StrictMode").RunMethod("setThreadPolicy", Array(policy))
   End If
End Sub 
				 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		