[经验分享] [Experience Sharing] OpenHarmony Print Driver Development Guide

itDyh12 显示全部楼层 发表于 2024-4-15 19:36:19

1. DevEco Studio download and installation

(1) Download DevEco Studio (version 3.1.0.501)

Download link:

(2) When installing, you can customize the check installation selection

*

2. Create a demo project

(1) After successful installation, open the DevEco option to download the node.js and ohpm options, execute Next, and then install the SDK according to the prompts

(2) Create a project after the SDK is successfully downloaded, select Empty Ability, and select the basic information of the project (the SDK uses the latest 9, and the Model uses the default Stage)

(3)The following error may occur when successfully initializing project resources. If it appears open C:\Users\xxx.ohpm,Editor.ohpm file,add strict_ssl=false,Then restart DecEco Studio

(4)download OpenHarmony SDK,The default download is HarmonyOS SDK,write demo can use OpenHarmony SDK,This facilitates automatic signature configuration

三、write OpenHarmony Print the driver configuration information

(1)create DirverExtensionAbility:In the project root directory entry/src/main/ets Create by right-clicking the directory extensionAbility file,in extensionAbility Right click Create folder DirverExtensionAbility.ts file

// @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)Will compile the driver file(filter/backend/ppd)File into entry/src/main/resources/rawfile , ppd filter The name needs to be concatenated with the package name of the current application and entry name(Ensure the uniqueness of the drive)

(3)edit entry/src/build-profile.json5 runtimeOS as OpenHarmony

(4)in entry/src/main/module.json5 Configuring driver Information

{
  "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)Direct execution at this time build/build hap/build hap will error,The SDK configuration information needs to be modified

(5.1)ctrl+ Left mouse click extensionAbilities type Stats,Add driver under preview type in SDK module.json (pop up whether to edit is OK)

(5.2)ctrl+ left mouse click on the resource property to change the pattern of the matching rule to: (Note the transition character before w- and the \n character that may be at the end)

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

(5.3)After the two changes are complete, restart DevEco Studio and configure automatic signature

  1. Compile the driver HAP package

(1)Run build-->build hap-->build hap

6. Drive HAP installation

  1. RK3568 Environment Preparation

Download the OpenHarmony 4.0 Release flash package, select the dayu200 image package, and download the link

Picture .png

(2)In Terminal, run hdc install -r.\ entry-default-sign.hap

The results show that the installation was successful

无用

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

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

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

返回顶部