Commit 4e45eb68 by patpat

增加天波580C串口库

parent 774c5e33
package com.common.api.serial;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class Serial {
private static boolean mSupport = false;
public static boolean isSupport() {
return mSupport;
}
public static final int MODE_PRINTER = 0;
public static final int MODE_ICC = 1;
public static final int MODE_PINPAD = 2;
private native static FileDescriptor open(String path, int baudrate, int flags);
public native void close();
private native static int switch_mode(int mode);
/*
* Do not remove or rename the field mFd: it is used by native method
* close();
*/
private FileDescriptor mFd;
private FileInputStream mFileInputStream;
private FileOutputStream mFileOutputStream;
public Serial(String path, int baud, int flags) throws FileNotFoundException, SecurityException, IOException {
// String cmd;
File device = new File(path);
if (!device.exists()) {
throw new FileNotFoundException();
}
mFd = open(path, baud, flags);
if (mFd == null) {
throw new IOException();
}
mFileInputStream = new FileInputStream(mFd);
mFileOutputStream = new FileOutputStream(mFd);
}
public InputStream getInputStream() {
return mFileInputStream;
}
public OutputStream getOutputStream() {
return mFileOutputStream;
}
public int switchMode(int mode) {
return switch_mode(mode);
}
static {
try {
System.loadLibrary("common_serial");
mSupport = true;
} catch (Exception e) {
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment