Demo entry 6656332

HBEDriver.java

   

Submitted by anonymous on Oct 31, 2017 at 07:49
Language: Java. Code size: 1.3 kB.

package com.hbe.driver;

import android.util.Log;

public class HBEDriver {
	
	static {
		System.loadLibrary("HBEDriver");
	}
	
	private boolean mOpenFlag;

	private native static int open(String path);
	private native static int openSync(String path);
	private native void close();
	private native void sendData(byte[] buff, int length);
	private native int getData(byte[] buff, int length);
	
	public HBEDriver(){
		mOpenFlag = false;
	}

	public HBEDriver(String path){
		mOpenFlag = false;
		openPort(path);
	}
	
	public void openPort(String path){
		if(mOpenFlag) return;

		if(open(path)==1){
			mOpenFlag = true;
		} else {
			Log.d("hanback", "driver open failed");
		}
	}
	
	public void openSyncPort(String path){
		if(mOpenFlag) return;

		if(openSync(path)==1){
			mOpenFlag = true;
		} else {
			Log.d("hanback", "driver open failed");
		}
	}
	
	public void closePort(){
		if(mOpenFlag==false) return;
		mOpenFlag = false;
		close();
	}

	protected void finalize() throws Throwable{
		closePort();
		super.finalize();
	}
	
	public void sendData(byte[] buff){
		if(mOpenFlag==false) return;
		sendData(buff, buff.length);
	}
	
	public int getData(byte[] buff){
		if(mOpenFlag==false) return -1;
		return getData(buff, buff.length);
	}
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).