• Lv0
    粉丝3

积分69 / 贡献0

提问0答案被采纳0文章5

[经验分享] OpenHarmony打印驱动开发指导 原创

dongzhengkuan 显示全部楼层 发表于 2023-11-6 15:24:57

一、DevEco Studio下载和安装

(1)下载DevEco Studio(3.1.0.501版本)

下载链接

(2)安装时可以自定义勾选安装选

*

二、创建demo工程

(1)安装成功后打开DevEco选项下载node.js和ohpm选项,执行Next然后根据提示安装SDK

(2)SDK下载成功后创建项目,选择Empty Ability,选择项目基本信息(SDK使用最新的9,Model使用默认的Stage)

(3)创建项目成功初始化项目资源时可能会出现以下报错,如果出现打开C:\Users\xxx\.ohpm,编辑.ohpm文件,添加strict_ssl=false,然后重启DecEco Studio

(4)下载OpenHarmony SDK,默认下载的是HarmonyOS SDK,写demo时可以使用OpenHarmony SDK,方便后面配置自动签名

三、编写OpenHarmony打印驱动配置信息

(1)创建DirverExtensionAbility:在项目根目录entry/src/main/ets目录下右键创建extensionAbility文件夹,在extensionAbility文件夹右键创建DirverExtensionAbility.ts文件

// @ts-nocheck
import DriverExtension from '@ohos.app.ability.DriverExtensionAbility'

export default class DriverExtensionAbility extends DriverExtension{
  onInit(want) {
    console.log('onInit, want: ' + want);
  }

  onRelease() {
    console.log('onRelease');
  }
}

(2)将编译好的驱动文件(filter/backend/ppd)文件放入到entry/src/main/resources/rawfile文件夹中,其中ppd中对应filter的名字需要拼接上当前应用的包名和entry名(确保驱动的唯一性)

(3)修改entry/src/build-profile.json5 的 runtimeOS 为 OpenHarmony

(4)在entry/src/main/module.json5配置驱动信息

{
  "module": {
    "name": "entry",
    "type": "entry",
    "description": "$string:module_desc",
    "mainElement": "EntryAbility",
    "deviceTypes": [
      "default",
      "tablet"
    ],
    "deliveryWithInstall": true,
    "installationFree": false,
    "pages": "$profile:main_pages",
    "abilities": [
      {
        "name": "EntryAbility",
        "srcEntry": "./ets/entryability/EntryAbility.ts",
        "description": "$string:EntryAbility_desc",
        "icon": "$media:icon",
        "label": "$string:EntryAbility_label",
        "startWindowIcon": "$media:icon",
        "startWindowBackground": "$color:start_window_background",
        "exported": true,
      }
    ],
    // **注意** 以下信息为新增
    "extensionAbilities": [
      {
        "name": "DriverExtensionAbility",
        "srcEntry": "./ets/extensionAbility/DriverExtensionAbility.ts",
        "label": "$string:EntryAbility_label",
        "icon": "$media:icon",
        "description": "driver",
        "type": "driver",
        "exported": false,
        "metadata": [
          {
            "name": "desc",
            "value": "xxx printer driver"
          },
          {
            "name": "vendor",
            "value": "xx company"
          },
          {
            "name": "cupsFilter",
            "value": "/print_service/cups/serverbin/filter", // cups驱动配置路径,固定写法
            "resource": "/resources/rawfile/rastertopwg" // filter名称
          },
          {
            "name": "cupsPpd",
            "value": "/print_service/cups/datadir/model", // cups驱动配置路径,固定写法
            "resource": "/resources/rawfile/HUAWEI_PixLab_X1.ppd" // ppd名称
          }
        ]
      }
    ]
  }
}

(5)此时直接执行build/build hap/build hap会报错,需要修改SDK配置信息

(5.1)ctrl+鼠标左键点击extensionAbilities下的type属性,在SDK的module.json里面的preview类型下面新增driver(弹出是否编辑选是确定)

(5.2)ctrl+鼠标左键点击resource属性,将匹配规则pattern修改为:(注意w-前面的转移字符以及结尾处可能会有的\n字符)

(^[\$]profile:[0-9a-zA-Z_.]+|(?=.*[{])(?=.*[}])[0-9a-zA-Z_.{}]+)|(^(/[\w-]+)+(.[a-z]+)?)\$

(5.3)两处修改完毕,重启DevEco Studio,配置自动签名

四、编译驱动HAP包

(1)执行build-->build hap-->build hap

六、驱动HAP安装

  1. rk3568环境准备

下载OpenHarmony 4.0 Release刷机包,选择dayu200的镜像包,下载链接

图片.png

(2)在Terminal执行hdc install -r .\entry-default-signed.hap

结果显示安装成功

©著作权归作者所有,转载或内容合作请联系作者

您尚未登录,无法参与评论,登录后可以:
参与开源共建问题交流
认同或收藏高质量问答
获取积分成为开源共建先驱

Copyright   ©2023  OpenHarmony开发者论坛  京ICP备2020036654号-3 |技术支持 Discuz!

返回顶部