更多信息请访问:与华为官方共建的鸿蒙技术社区https://ost.51cto.com在工农业生产中,变频器具有广泛而深远的应用。除了就地操作面板、按钮和旋钮控制外,变频器更多的是通过上位机进行远程操作和监控。2022年3月30日,发布OpenHarmony3.1Release和配套的南向开发工具DevEcoDeviceTool3.0Release。3月31日,OpenHarmony首款北向应用开发工具DevEcoStudio3.0Beta3forOpenHarmony发布,支持API8和API9,具有以下能力和特点:支持一站式信息采集平台。支持可视化界面UI开发。双向、极快的UI预览。新的编译工具Hvigor实现了OpenHarmony应用/服务的一键自动构建。支持全自动应用签名机制,一键生成签名信息,签名后的HAP可以安装到真机上运行。高效的代码编辑,提供代码高亮、代码折叠、代码格式化等多种常用技能,同时支持关联补全、代码跳转、代码校验等,实现高效的代码编辑。预览器支持双向极速UI预览,实现应用开发过程的可视化。丰富的代码调试和调优能力。下面我们使用DevEcoStudio3.0Beta3forOpenHarmony开发一个逆变器控制接口,实现常用的启停、正反转、加减速功能,模拟器效果如下。准备好Hi3516开发板,烧写OpenHarmony3.1Release标准系统,参考1,参考2。2.安装OpenHarmony专用开发工具DevEcoStudio3.0Beta3forOpenHarmony官网文档创建项目并打开应用,点击新建项目,在弹出的窗口中选择“EmptyAbility”,点击“Next”弹出所有默认项目配置,点击“finish”完成eTS项目的创建。默认API为8,也可以选择API9。测试在3516开发板上运行正常。如果单击“启用超级可视化”,将创建一个低代码可视化项目。项目结构如下index.ets:用于描述UI布局、风格、事件交互和页面逻辑。app.ets:用于全局应用程序逻辑和应用程序生命周期管理。pages:用于存放所有组件页面。resources:用于存放资源配置文件。首次使用会显示“信息中心”,以后可以在帮助菜单下选择“信息中心”。图片、代码、自动签名、在线调试将项目中用到的图片添加到资源->基础->媒体目录下。编辑代码,打开预览器的双T,就可以实时预览了。完整代码是在codelabs的SliderApplicationEts基础上修改的。@Entry@ComponentstructIndex{@Stateprivatespeed:number=0@Stateprivatelastspeed:number=1@StateprivateimageSize:number=1.5@Stateprivatefwd_rev:number=1@Stateprivateangle:number=0@Stateprivateinterval}:number=0build(){Column(){Text("变频调速控制").fontSize(45).fontColor("blue").fontWeight(FontWeight.Bold).margin({top:50,bottom:20})Row(){Image($r('app.media.fengye')).objectFit(ImageFit.Contain).height(150).width(150).position({x:120,y:100}).rotate({x:0,y:0,z:this.fwd_rev,angle:this.angle}).scale({x:this.imageSize,y:this.imageSize})}.width(375)。height(375)Row(){Button(){Text('启动').fontSize(30).fontWeight(FontWeight.Bold)}.type(ButtonType.Capsule).margin({left:20,right:20}).width('40%').height('5%').backgroundColor('green').onClick(()=>{this.speed=this.lastspeed})Button(){Text('停止').fontSize(30).fontWeight(FontWeight.Bold)}.type(ButtonType.Capsule).margin({left:20,right:20}).width('40%').height('5%').backgroundColor('red').onClick(()=>{this.speed=0})}Row(){Button(){Text('正转').fontSize(30).fontWeight(FontWeight.Bold)}.type(ButtonType.Capsule).margin({top:40,left:20,right:20}).width('40%').height('5%').backgroundColor('#ffc916dd').onClick(()=>{this.fwd_rev=1})Button(){Text('反转').fontSize(30).fontWeight(FontWeight.Bold)}.type(ButtonType.Capsule).margin({top:40,left:20,right:20}).width('40%').height('5%').backgroundColor('#ffc916dd').onClick(()=>{this.fwd_rev=-1})}this.DescribeText('速度:',this.speed*5)Slider({value:this.speed,min:0,max:10,步骤:0.2,样式:SliderStyle.OutSet}).showTips(true).blockColor(Color.Red).onChange((value:number,mode:SliderChangeMode)=>{this.speed=valuethis.lastspeed=this.speedclearInterval(this.interval)this.speedChange()})Row(){Button(){Text('加速').fontSize(30).fontWeight(FontWeight.Bold)}.type(ButtonType.Capsule).margin({top:20,left:20,right:20}).width('40%').height('5%').backgroundColor('#ff00ffd9').onClick(()=>{this.speed+=0.2if(this.speed>=10){this.speed=10}this.lastspeed=this.speed})Button(){Text('减速').fontSize(30).fontWeight(FontWeight.Bold)}.type(ButtonType.Capsule).margin({top:20,left:20,right:20}).width('40%').height('5%').backgroundColor('#ff00ffd9').onClick(()=>{this.speed-=0.2if(this.speed<=0){this.speed=0}this.lastspeed=this.speed})}}.margin({left:30,right:30})}speedChange(){varthat=this;那。角度=0;this.interval=setInterval(function(){that.angle+=that.speed},15)}onPageShow(){clearInterval(this.interval)this.speedChange()}@BuilderDescribeText(text:string,speed:number){堆(){Text(text+speed.toFixed(1)+'Hz').margin({top:70}).fontSize(40).fontWeight(FontWeight.Bold)}}}在连接到真实设备之前,IDE提供了一个自动签名功能依次点击“文件-项目结构-项目-签名配置”,在弹出的窗口中勾选“自动生成签名”,等待签名完成,点击“确定”。用usb线连接电脑和3516开发板。开发板启动后,会自动连接DevEcoStudio3.0Beta3forOpenHarmony。同时,在Windows系统的设备管理器中,会显示通用串行总线设备-HDC。点击设备的“运行”按钮,完成工程编译,同时下载到开发板。效果如下:OpenHarmony建立了完整的开发工具链,其生态会越来越强大。更多信息请访问:与华为官方共建的鸿蒙技术社区https://ost.51cto.com
