package com.device.zk_r322a;

import android_serialport_api.SerialPort;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

public class ZKR322AControl {
	private  SerialPort mSerialPort = null;
	private   InputStream mInputStream = null;

	public ZKR322AControl() throws SecurityException, IOException {
		mSerialPort = new SerialPort(new File("/dev/ttyS1"), 115200,0);
		mInputStream = mSerialPort.getInputStream();
	}
	
	public String getData() {
		if (mInputStream == null) return "";
		try {
			int size = mInputStream.available();
			byte[] buffer = new byte[size];
			size = mInputStream.read(buffer);
			if (size > 0) {
				return new String(buffer);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return "";
	}
	
	public void start() {
//		GpioJNI.gpio_switch_scan_trig(1);
	}
	
	public void stop() {
//		GpioJNI.gpio_switch_scan_trig(0);
	}
	
	public void close() {
		if (mSerialPort != null) {
			mSerialPort.close();
		}
	}
	
	
	public void initScan() {
//		GpioJNI.gpio_switch_scan_rf_ired(0);
//		GpioJNI.gpio_switch_scan_power(1);
	}
}
