Android Question Help

billyrudi

Active Member
Licensed User
Hi,
how i can use this code in my progrect?

package com.jhxd.serial;

import android.R.integer;
import android.util.Log;

public class serialService {

static{
try {
System.loadLibrary("serial_jni");
} catch (UnsatisfiedLinkError ule) {
System.err.println("WARNING: Could not load serial_jni library!");
}
}

public static native int serialOpen(String ttyportString);
public static native int serialSetbaud(int fd,int baud);
public static native int serialRead(int fd,byte[] data,int readlen);
public static native int serialWrite(int fd,byte[] data,int writelen);
public static native int serialClose(int fd);
}
 

billyrudi

Active Member
Licensed User
Hi i can use this library because the serial library can not able to write to rs485 device.
I have make a library with Erel Simple Library Compiler
package com.jhxd.serial;
//import java.io.IOException;
import android.R.integer;
import android.util.Log;
//import android.util.Log;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
import anywheresoftware.b4a.objects.streams.File;

@Version(5.0f)
@ShortName("PaoloSerial")

public class serialService{


public static native int serialOpen(String ttyportString);
public static native int serialSetbaud(int fd,int baud);
public static native int serialRead(int fd,byte[] data,int readlen);
public static native int serialWrite(int fd,byte[] data,int writelen);
public static native int serialClose(int fd);

static{
try {
//System.loadLibrary("libserial_jni");
System.load(File.Combine(File.getDirInternal(), "libserial_jni.so"));
} catch (UnsatisfiedLinkError ule) {
System.err.println("WARNING: Could not load serial_jni library!");
}
}


}


and then i have use in b4a this


If File.Exists (File.DirInternal, "libserial_jni.so") Then
File.Copy (File.DirAssets , "libserial_jni.so", File.DirInternal , "libserial_jni.so")
Else
File.Copy (File.DirAssets , "libserial_jni.so", File.DirInternal , "libserial_jni.so")

End If

Dim gg As GSM
Dim chefile As Int

chefile = gg.serialOpen("/dev/ttyS5")
gg.serialSetbaud(chefile,9600) .....
 
Top