zoukankan      html  css  js  c++  java
  • Android开发中通过AIDL文件中的方法打开钱箱,显示LCD屏幕

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

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

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

    ILcdCallback:顾显反馈结果

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

     引入AIDL文件

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

      package woyou.aidlservice.jiuiv5;

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

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

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

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

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

    using Woyou.Aidlservice.Jiuiv5;
    
    public class ServiceConnection : Java.Lang.Object, IServiceConnection
        {
            public IWoyouService woyouService { get; private set; }
    
            public void OnServiceConnected(ComponentName name, IBinder service)
            {
                woyouService = IWoyouServiceStub.AsInterface(service);
            }
    
            public void OnServiceDisconnected(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);
            //}
        }

     调用,全局方法

    private ServiceConnection conn;
    
    //连接服务
    public void connectPrinterService()
            {
                Context context = this.ApplicationContext;
                Intent intent = new Intent();
                conn = new ServiceConnection();
                intent.SetPackage("woyou.aidlservice.jiuiv5");
                intent.SetAction("woyou.aidlservice.jiuiv5.IWoyouService");
                context.StartService(intent);
                context.BindService(intent, conn, Bind.AutoCreate);
            }
     private void BtnPosOpenBox_Click(object sender, 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屏幕和第二屏是不一样的,是两种不同的东西

    private void Btn_Click(object sender, 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屏幕
  • 相关阅读:
    P2024 [NOI2001]食物链[扩展域并查集]
    poj1733 Parity game[带权并查集or扩展域]
    BZOJ1079 [SCOI2008]着色方案[组合计数DP]
    P1801 黑匣子[对顶堆]
    poj3784 Running Median[对顶堆]
    P1196 [NOI2002]银河英雄传说[带权并查集]
    poj1456 Supermarket[另类的并查集做法]
    P1955 [NOI2015]程序自动分析[离散化+并查集]
    BZOJ1306 [CQOI2009]match循环赛/BZOJ3139 [Hnoi2013]比赛[dfs剪枝+细节题]
    android的模拟器-Genymotion
  • 原文地址:https://www.cnblogs.com/Swaggy-yyq/p/14069559.html
Copyright © 2011-2022 走看看