123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- package com.example;
- import android.os.Looper;
- import android.util.Log;
- import com.hboxs.base_library.constant.Name;
- import com.orhanobut.hawk.Hawk;
- import top.keepempty.sph.library.SerialPortConfig;
- import top.keepempty.sph.library.SerialPortHelper;
- /**
- * 发票工具类
- */
- public class FaPiaoUtils {
- private static final String TAG = "FaPiaoUtils";
- /**
- * 静态内部类控制单例
- */
- private static class FaPiaoHolder {
- final static FaPiaoUtils instance = new FaPiaoUtils();
- }
- /**
- * 获取单例
- *
- * @return
- */
- public static FaPiaoUtils getInstance() {
- return FaPiaoHolder.instance;
- }
- private SerialPortHelper serialPortHelper;
- public SerialPortHelper getSerialPortHelper() {
- return serialPortHelper;
- }
- public void initFaPiao() {
- if (Hawk.get(Name.RAYMEN_POS_PAY, false)) {
- /**
- * 串口参数
- */
- SerialPortConfig serialPortConfig = new SerialPortConfig();
- serialPortConfig.mode = 0;
- serialPortConfig.path = "/dev/" + Hawk.get(Name.OXSERIALPORT, "ttyS1"); //串口地址: /dev/ttyS1
- serialPortConfig.baudRate = 9600; //波特率: 9600
- serialPortConfig.dataBits = 7; //数据位: 7
- serialPortConfig.parity = 'E'; //校验位: even
- serialPortConfig.stopBits = 1; //停止位: 1
- if (Looper.myLooper() == null) {
- Looper.prepare();
- }
- // 初始化串口
- serialPortHelper = new SerialPortHelper(16);
- // 设置串口参数
- serialPortHelper.setConfigInfo(serialPortConfig);
- // 开启串口
- serialPortHelper.openDevice();
- Looper.loop();
- }
- if (Hawk.get("MDB_COIN", false)) {
- /**
- * 串口参数
- */
- boolean a=false;
- SerialPortConfig serialPortConfig = new SerialPortConfig();
- serialPortConfig.mode = 0;
- serialPortConfig.path = "/dev/" +"ttyS2";//串口地址:(品澳ttyS3com2冰淇淋ttyS2com2)
- serialPortConfig.baudRate = 9600; //波特率: 9600
- serialPortConfig.dataBits = 8; //数据位: 8
- serialPortConfig.parity = 'N'; //校验位: none
- serialPortConfig.stopBits = 1; //停止位: 1
- Log.d(TAG, "投币测试: 0");
- if (Looper.myLooper()==null){
- Log.d(TAG, "投币测试: 1");
- Looper.prepare();
- a=true;
- Log.d(TAG, "投币测试: 2");
- }
- // 初始化串口
- serialPortHelper = new SerialPortHelper(16);
- // 设置串口参数
- serialPortHelper.setConfigInfo(serialPortConfig);
- // 开启串口
- serialPortHelper.openDevice();
- if (a){
- Log.d(TAG, "投币测试: 3");
- Looper.loop();
- Log.d(TAG, "投币测试: 4");
- }
- Log.d(TAG, "投币测试: 5");
- }
- }
- }
|