B4J Question Pass javaobject as parameter ?

jinyistudio

Well-Known Member
Licensed User
Longtime User
Hi

pac.SetSendCmd(iobuf) always give message : java.lang.RuntimeException: Method: setSendCmd not matched.

Could i pass Iobuf to SetSendCmd as parameter ?


B4X:
Waiting for debugger to connect...
Program started.
Error occurred on line: 23 (LinpacComm)
java.lang.RuntimeException: Method: setSendCmd not matched.
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:129)
    at b4j.example.linpaccomm._setsendcmd(linpaccomm.java:61)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:612)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:226)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
    at b4j.example.main.main(main.java:29)


Main program
B4X:
#Region  Project Attributes
   #CommandLineArgs:
   #MergeLibraries: True
   #AdditionalJar: icpdas-2015
#End Region

Sub Process_Globals
   Dim pac As LinpacComm
   Dim iobuf As LinpacIobuf
End Sub

Sub AppStart (Args() As String)
   pac.Initialize
   iobuf.Initialize
   Log(pac.SetSendCmd(iobuf))
   StartMessageLoop
End Sub


class LinpacComm
B4X:
Sub Class_Globals
    Private Comm As JavaObject
    Private vportno As Int
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
    Comm.InitializeNewInstance("com.icpdas.comm.Comm",Null)
    'Comm.InitializeStatic("com.icpdas.comm.Comm")
End Sub
' Initialize the COM port.
public Sub open(portno As Int,baudrate As Int,databit As Int,parity As Int,stopbit As Int) As Int
    Return Comm.RunMethod("open",Array As Object(portno,baudrate,databit,parity,stopbit))
End Sub   
' Free all the resources used by open. This method must be called
' before the program Exit.
public Sub close(portno As Int)
    Comm.RunMethod("close",Array(portno))
End Sub
'  Create a thread to send a command to module.
public Sub SetSendCmd(ioArg As JavaObject) As Int    
    Return Comm.RunMethod("setSendCmd",Array As Object(ioArg))
End Sub

Java Method Summary
B4X:
 int  setSendCmd(IoBuf ioArg)
Create a thread to send a command to module.

Class LinpacIobuf
B4X:
#DesignerProperty: key: szSend, displayname: , fieldtype: string, defaultvalue:
#DesignerProperty: key: szReceive, displayname: , fieldtype: string, defaultvalue:
'Class module
Sub Class_Globals
   Public iobuf As JavaObject
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
   iobuf.InitializeNewInstance("com.icpdas.comm.IoBuf",Null)   
End Sub
'
public Sub dwBuf As Int()
   Dim n1() As Int=iobuf.GetField("dwBuf")
   Return n1
End Sub
'
public Sub fBuf As Float() 
   Dim n1() As Float=iobuf.GetField("fBuf")
   Return n1
End Sub
'
public Sub setszSend(value As String)
   iobuf.setField("szSend",value)
End Sub
'
public Sub getszSend As String
   Dim s1 As String=iobuf.getField("szSend")
   Return s1
End Sub
'
public Sub getszReceive As String
   Dim s1 As String=iobuf.GetField("szReceive")
   Return s1
End Sub

B4X:
1.3.4 Class IoBuf
java.lang.Object
    |
    +--com.icpdas.comm.IoBuf
The IoBuf class provides a variable that the high level remote I/O modules control method
use.

Field Detail
dwBuf
public int dwBuf[]
Double word length matrix for module control.

fBuf
public float fBuf[]
Floating matrix for module control.

szSend
public java.lang.String szSend
Send a Command string to the module.

szReceive
public java.lang.String szSend
Receives a string from the module.
 
Last edited:

Daestrum

Expert
Licensed User
Longtime User
I would check if you are passing a B4J Int to a routine that wants a java int.
As far as I am aware a B4J Int is really a java Integer, and that will not match to a routine that wants a java int.
 
Upvote 0

jinyistudio

Well-Known Member
Licensed User
Longtime User
Hi Erel, You are right !
 
Upvote 0
Top