# communication-usart **Repository Path**: HOMODELUNA/communication-usart ## Basic Information - **Project Name**: communication-usart - **Description**: 用来给OHOS做串口读写相关的系统功能 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-01-02 - **Last Updated**: 2022-06-26 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # /foundation/communication/usart_standard 用于串口读写的API,供C++端和ts端进行读写 # 系统盘烧写 https://shimo.im/docs/9030MrGppbuZorqw ## 2022-1-15 `//build/ohos/sa_profile/sa_profile.gni` 里面添加了 ```gn print("[Wang Debug] prepare to copy ${sources} to ${outputs}") ``` 显示出sa_profile被搬运到了 ``` [Wang Debug] prepare to copy ["9901.xml"] to ["//out/ohos-arm64-release/obj/foundation/multimedia/usart_standard/sa_profile/profiles/{{source_file_part}}"] ``` ## 2022-1-14测试 napitest用来测试napi的基本功能 1_entry..... 用来测试串口 aa命令如下 ```bash # 1_entry... aa start -a com.example.jstestusart.hmservice.ServiceAbility -b com.example.jstestusart.hmservice # napitest aa start -a napi.test.sa -b napi.test ``` 串口暂时只用一个:`/dev/ttyAMA0` ## 2022-1-11关于构建hap包 一开始写 ```javascript import usart from "@ohos.multimedia.usart"; ``` 的时候,DevEco(Intelij IDEA)会提醒你,没有这个文件,这是因为我自己写的`d.ts`不在华为官方的sdk中,你们找到 `interface\kits\js\usart\@ohos.multimedia.usart.d.ts`,把它复制到 `C:\Users\你的用户名\AppData\Local\OpenHarmony\Sdk\js\3.1.0.0\api\phone` 现在可以试着把测试包放进树莓派里面,用bm安装,然后打`JSTestUsart`,应该能出东西. 这个包这是串口的读功能,他干的只是两秒从串口读取一行,然后打出来. 用这个指令启动测试 ```bash aa start -a .MainAbility -b com.example.jstestusart.hmservice ``` 这个是造hap时用来生成证书用的 ```powershell # C:\Users\Kimi_no_Na_wa\AppData\Local\OpenHarmony\Sdk\toolchains\lib> keytool -gencert -alias "OpenHarmony Application CA" -infile C:\Users\homodeluna\Desktop\usart\JSTestUsart\self_gen.csr -outfile self_gen.cer -keystore OpenHarmony.p12 -sigalg SHA384withECDSA -storepass 123456 -ext KeyUsage:"critical=digitalSignature" -validity 3650 -rfc C:\Users\Kimi_no_Na_wa\AppData\Local\OpenHarmony\Sdk\toolchains\lib\keytool -gencert -alias "OpenHarmony Application CA" -infile C:\Users\homodeluna\Desktop\usart\JSTestUsart\self_gen.csr -outfile self_gen.cer -keystore OpenHarmony.p12 -sigalg SHA384withECDSA -storepass 123456 -ext KeyUsage:"critical=digitalSignature" -validity 3650 -rfc ``` #通过证书生成p7b,即应用profle ```powershell # C:\Users\homodeluna\AppData\Local\OpenHarmony\Sdk\toolchains\lib> java -jar provisionsigtool.jar sign --in UnsgnedReleasedProfileTemplate.json --out myApplication_ohos_Provision.p7b --keystore OpenHarmony.p12 --storepass 123456 --alias "OpenHarmony Application Profile Release" --sigAlg SHA256withECDSA --cert OpenHarmonyProfileRelease.pem --validity 365 --developer-id ohosdeveloper --bundle-name 包名 --permission 受限权限名(可选) --permission 受限权限名(可选) --distribution-certificate myApplication_ohos.cer #实际输入的是 java -jar provisionsigtool.jar sign --in UnsgnedReleasedProfileTemplate.json --out C:\Users\homodeluna\Desktop\usart\JSTestUsart\JSTestUsart_ohos_Provision.p7b --keystore OpenHarmony.p12 --storepass 123456 --alias "OpenHarmony Application Profile Release" --sigAlg SHA256withECDSA --cert OpenHarmonyProfileRelease.pem --validity 365 --developer-id ohosdeveloper --bundle-name com.example.jstestusart.hmservice --distribution-certificate C:\Users\homodeluna\Desktop\usart\JSTestUsart\self_gen.cer java -jar provisionsigtool.jar sign --in UnsgnedReleasedProfileTemplate.json --out C:\Users\homodeluna\Desktop\usart\JSTestUsart\JSTestUsart_ohos_Provision.p7b --keystore OpenHarmony.p12 --storepass 123456 --alias "OpenHarmony Application Profile Release" --sigAlg SHA256withECDSA --cert OpenHarmonyProfileRelease.pem --validity 365 --developer-id ohosdeveloper --bundle-name test.usart.loop --distribution-certificate C:\Users\homodeluna\Desktop\usart\JSTestUsartLoop\self_gen.cer java -jar provisionsigtool.jar sign --in UnsgnedReleasedProfileTemplate.json --out C:\Users\homodeluna\Desktop\usart\JSTestUsartSend\JSTestUsart_ohos_Provision.p7b --keystore OpenHarmony.p12 --storepass 123456 --alias "OpenHarmony Application Profile Release" --sigAlg SHA256withECDSA --cert OpenHarmonyProfileRelease.pem --validity 365 --developer-id ohosdeveloper --bundle-name test.usart.send --distribution-certificate C:\Users\homodeluna\Desktop\usart\JSTestUsartSend\self_gen.cer ``` ## 2022-01-06 制作了napi后面的函数,正在debug,希望有正确的输出 ### 2022-01-05 制作了gn,部分的napi 和 剩下的 SystemAbility。待调试。 思路已经明确,明天接着做 ### 遗留工作 src/usart_napi.cpp 还差两个函数没写 ## napi 系统服务和napi还是两个概念。 `napi`,全称`node api`,是node-js调用c和c++的接口,除了写串口的systemAbility之外,我还要写这些api。他们会按照ohos制定的方式,包装成动态库,详见[这里](https://gitee.com/openharmony/ace_napi)