hello,
I managed to use jamod (connections with WAGO plc) with Eclipse Android
I want to create a library for B4A
everything works fine but when compiling I get an error launching the application.
do you have an idea or this bug.
thank you
my code b4a
'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 port_num As Int
Dim adr_ip As Double
Dim val_bit As Boolean
Dim my_wago As MODBUS_TCP_MASTER_B4A
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 button1 As Button
Dim label1 As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
Activity.LoadLayout("1")
my_wago.Ip("192.168.2.150")
my_wago.Connection
End If
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
Dim x As String
x=my_wago.ReadInput(0,2)
label1.Text=x
End Sub
my code eclipse
package com.exemple.android;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
import java.net.*;
import java.io.*;
import net.wimpi.modbus.*;
import net.wimpi.modbus.msg.*;
import net.wimpi.modbus.io.*;
import net.wimpi.modbus.net.*;
@ShortName("MODBUS_TCP_MASTER_B4A")
@Permissions(values={"android.permission.INTERNET"})
@Version(1.0f)
@Author("Alan1968")
public class modbus_ba4 {
/** Called when the activity is first created. */
/* The important instances of the classes mentioned before */
static TCPMasterConnection con = null; //the connection
static ModbusTCPTransaction trans = null; //the transaction
static ReadInputDiscretesRequest req = null; //the request
static ReadInputDiscretesResponse res = null; //the response
/* Variables for storing the parameters */
static InetAddress addr = null; //the slave's address
static int port = Modbus.DEFAULT_PORT;
static int repeat = 1; //a loop for repeating the transaction
//private static String x;
public static void Ip(String my_ip) throws IOException {
addr=InetAddress.getByName(my_ip);
con = new TCPMasterConnection(addr);
}
public static void Connection () throws Exception{
con.connect();
}
public static String ReadInput (int ref,int count) throws ModbusIOException, ModbusSlaveException, ModbusException{
req = new ReadInputDiscretesRequest(ref, count);
trans = new ModbusTCPTransaction(con);
trans.setRequest(req);
trans.execute();
res = (ReadInputDiscretesResponse) trans.getResponse();
//6. Close the connection
con.close();
return (res.getDiscretes().toString());
}
}
my xml
<?xml version="1.0" encoding="UTF-8"?>
<root>
<doclet-version-NOT-library-version>1.00</doclet-version-NOT-library-version>
<class>
<name>com.exemple.android.modbus_ba4</name>
<shortname>MODBUS_TCP_MASTER_B4A</shortname>
<owner>process</owner>
<permission>android.permission.INTERNET</permission>
<method>
<name>Ip</name>
<comment></comment>
<returntype>void</returntype>
<parameter>
<name>my_ip</name>
<type>java.lang.String</type>
</parameter>
</method>
<method>
<name>ReadInput</name>
<comment></comment>
<returntype>java.lang.String</returntype>
<parameter>
<name>ref</name>
<type>int</type>
</parameter>
<parameter>
<name>count</name>
<type>int</type>
</parameter>
</method>
<method>
<name>Connection</name>
<comment></comment>
<returntype>void</returntype>
</method>
</class>
<version>1.0</version>
<author>Alan1968</author>
</root>
I managed to use jamod (connections with WAGO plc) with Eclipse Android
I want to create a library for B4A
everything works fine but when compiling I get an error launching the application.
do you have an idea or this bug.
thank you
my code b4a
'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 port_num As Int
Dim adr_ip As Double
Dim val_bit As Boolean
Dim my_wago As MODBUS_TCP_MASTER_B4A
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 button1 As Button
Dim label1 As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
Activity.LoadLayout("1")
my_wago.Ip("192.168.2.150")
my_wago.Connection
End If
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
Dim x As String
x=my_wago.ReadInput(0,2)
label1.Text=x
End Sub
my code eclipse
package com.exemple.android;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
import java.net.*;
import java.io.*;
import net.wimpi.modbus.*;
import net.wimpi.modbus.msg.*;
import net.wimpi.modbus.io.*;
import net.wimpi.modbus.net.*;
@ShortName("MODBUS_TCP_MASTER_B4A")
@Permissions(values={"android.permission.INTERNET"})
@Version(1.0f)
@Author("Alan1968")
public class modbus_ba4 {
/** Called when the activity is first created. */
/* The important instances of the classes mentioned before */
static TCPMasterConnection con = null; //the connection
static ModbusTCPTransaction trans = null; //the transaction
static ReadInputDiscretesRequest req = null; //the request
static ReadInputDiscretesResponse res = null; //the response
/* Variables for storing the parameters */
static InetAddress addr = null; //the slave's address
static int port = Modbus.DEFAULT_PORT;
static int repeat = 1; //a loop for repeating the transaction
//private static String x;
public static void Ip(String my_ip) throws IOException {
addr=InetAddress.getByName(my_ip);
con = new TCPMasterConnection(addr);
}
public static void Connection () throws Exception{
con.connect();
}
public static String ReadInput (int ref,int count) throws ModbusIOException, ModbusSlaveException, ModbusException{
req = new ReadInputDiscretesRequest(ref, count);
trans = new ModbusTCPTransaction(con);
trans.setRequest(req);
trans.execute();
res = (ReadInputDiscretesResponse) trans.getResponse();
//6. Close the connection
con.close();
return (res.getDiscretes().toString());
}
}
my xml
<?xml version="1.0" encoding="UTF-8"?>
<root>
<doclet-version-NOT-library-version>1.00</doclet-version-NOT-library-version>
<class>
<name>com.exemple.android.modbus_ba4</name>
<shortname>MODBUS_TCP_MASTER_B4A</shortname>
<owner>process</owner>
<permission>android.permission.INTERNET</permission>
<method>
<name>Ip</name>
<comment></comment>
<returntype>void</returntype>
<parameter>
<name>my_ip</name>
<type>java.lang.String</type>
</parameter>
</method>
<method>
<name>ReadInput</name>
<comment></comment>
<returntype>java.lang.String</returntype>
<parameter>
<name>ref</name>
<type>int</type>
</parameter>
<parameter>
<name>count</name>
<type>int</type>
</parameter>
</method>
<method>
<name>Connection</name>
<comment></comment>
<returntype>void</returntype>
</method>
</class>
<version>1.0</version>
<author>Alan1968</author>
</root>
Last edited: