android lcd 显示图片,Android开发中通过AIDL文件中的方法打开钱箱,显示LCD屏幕

下载相关 资源文件 ,在项目中新建如下层级的文件夹,将源文件中的AIDL文件放入其中。

ICallback:打印服务执行结果的回调

ITax:打印服务执行结果的回调

ILcdCallback:顾显反馈结果

根据需求选择aidl文件,IWoyouService是必须的。一般开钱箱使用IWoyouService和ICallback文件即可。

引入AIDL文件

1.找到需要导入工程的aidl文件.通过文本打开,找到文件中的具体包名

package woyou.aidlservice.jiuiv5;

2.依次创建跟之前找到的包名一样的文件夹,我这里是:woyou、aidlservice、jiuiv5。

把对应的aidl文件拷贝到创建的最后一层文件夹里

777045d8b319a377a4a7af1f3dd1e0ba.png

3.如下文件,依次修改属性。右键属性→生成操作→修改为AndroidInterfaceDescription

修改完后重新生成,生成成功后在obj/Debug文件下找到aidl文件说明引入AIDL文件成功

cf8a5f5b4c8720ed649753a17469bf00.png

809feec4b82bc93b0b66195854a871a8.png

调用

创建一个公共类(减少重复代码),也可以不创建直接写在需要调用的地方

usingWoyou.Aidlservice.Jiuiv5;public classServiceConnection : Java.Lang.Object, IServiceConnection

{public IWoyouService woyouService { get; private set; }public voidOnServiceConnected(ComponentName name, IBinder service)

{

woyouService=IWoyouServiceStub.AsInterface(service);

}public voidOnServiceDisconnected(ComponentName name)

{

woyouService= null;

}//public void connectPrinterService(Context con)//{//Context context = con;//Intent intent = new Intent();//ServiceConnection conn = new ServiceConnection();//intent.SetPackage("woyou.aidlservice.jiuiv5");//intent.SetAction("woyou.aidlservice.jiuiv5.IWoyouService");//context.StartService(intent);//context.BindService(intent, conn, Bind.AutoCreate);//}

}

调用,全局方法

privateServiceConnection conn;//连接服务

public voidconnectPrinterService()

{

Context context= this.ApplicationContext;

Intent intent= newIntent();

conn= newServiceConnection();

intent.SetPackage("woyou.aidlservice.jiuiv5");

intent.SetAction("woyou.aidlservice.jiuiv5.IWoyouService");

context.StartService(intent);

context.BindService(intent, conn, Bind.AutoCreate);

}

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

private void BtnPosOpenBox_Click(objectsender, EventArgs e)

{//通过ES/POS指令的方式开钱箱

byte[] aa = new byte[5];

aa[0] = 0x10;

aa[1] = 0x14;

aa[2] = 0x00;

aa[3] = 0x00;

aa[4] = 0x00;try{if (conn.woyouService == null)

{

connectPrinterService();

}if (conn.woyouService != null)

{//打开钱箱,也可以直接使用conn.woyouService.OpenDrawer(null)方法开钱箱

conn.woyouService.SendRAWData(aa, null);return;

}

Message.Show(MessageText.MSG_OPEN_ERROR_PLEASE_RETRY,this);

}catch(RemoteException e1)

{

e1.PrintStackTrace();

}

}

开钱箱

注意LCD屏幕和第二屏是不一样的,是两种不同的东西

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

private void Btn_Click(objectsender, EventArgs e)

{try{if (woyouService == null)

{

connectPrinterService();

}if (woyouService != null)

{//1 初始化 2 唤醒LCD 3休眠LCD 4清屏

woyouService.SendLCDCommand(1);//设置状态

woyouService.SendLCDCommand(2);

woyouService.SendLCDString("小杨!", null);//设置显示内容//conn.woyouService.SendLCDDoubleString("金额:", "800", null) ;

return;

}

Message.Show("打开失败,请重试!", this);

}catch(RemoteException e1)

{

e1.PrintStackTrace();

}

}

显示LCD屏幕

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值