APP编写


为什么要写APP

驱动编写完成后必须进行测试,测试驱动必须编写APP。APP完成对设备的打开(open)、读(read)、写(write)、关闭(close)。因为linux系统中一切皆为文件,所以相关的文件操作即可完成相关的设备操作。


一、字符设备测试APP

1.引入库

以下代码来源于ALENTEK IMX6ULL 开发板,因为左先生已经完成程序的编写,我们就乐享其成了。
代码如下(示例):

#include "unistd.h"
#include "sys/types.h"
#include "sys/stat.h"
#include "fcntl.h"
#include "stdlib.h"
#include "string.h"


static char usrdata[] = {"usr data!luoxinli"};

/*
 * @description		: main主程序
 * @param - argc 	: argv数组元素个数
 * @param - argv 	: 具体参数
 * @return 			: 0 成功;其他 失败
 */
int main(int argc, char *argv[])
{
	int fd, retvalue;
	char *filename;
	char readbuf[100], writebuf[100];

	if(argc != 3){
		printf("Error Usage!\r\n");
		return -1;
	}

	filename = argv[1];

	/* 打开驱动文件 */
	fd  = open(filename, O_RDWR);
	if(fd < 0){
		printf("Can't open file %s\r\n", filename);
		return -1;
	}

	if(atoi(argv[2]) == 1){ /* 从驱动文件读取数据 */
		retvalue = read(fd, readbuf, 50);
		if(retvalue < 0){
			printf("read file %s failed!\r\n", filename);
		}else{
			/*  读取成功,打印出读取成功的数据 */
			printf("read data:%s\r\n",readbuf);
		}
	}

	if(atoi(argv[2]) == 2){
 	/* 向设备驱动写数据 */
		memcpy(writebuf, usrdata, sizeof(usrdata));
		retvalue = write(fd, writebuf, 50);
		if(retvalue < 0){
			printf("write file %s failed!\r\n", filename);
		}
	}

	/* 关闭设备 */
	retvalue = close(fd);
	if(retvalue < 0){
		printf("Can't close file %s\r\n", filename);
		return -1;
	}

	return 0;
}





2.APP程序解读

程序非常简单,打开一个设备,从设备中读、或者写入数据。
程序运行是需要两个参数,第一是设备的绝对路径,第二个参数是1或者2,
1是读取数据,2是写入文件。
在学习的过程中,如果没有可靠的方法,可以使用静态分析的方法,分析结束后然后测试运行,可以使用printf( )、printk( )输出调试信息来分析前人的设计思路。

在这里插入图片描述

总结

第一 测试驱动的APP编写必须了解C语言程序设计;
第二 必须熟悉linux下文件操作;
第三 熟练使用printk( )和printf( )函数。
熟悉三点已经达到编写APP的基本需求。

  • 5
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Uni-app是一款跨平台的开发框架,可以使用Vue.js语法来开发微信小程序、H5、Android、iOS等多个平台的应用程序。下面是编写登录页面的步骤: 1. 创建一个新的uni-app项目,可以使用HBuilderX等工具进行创建。 2. 在项目的`pages`目录下创建一个新的页面,例如`login.vue`。 3. 在`login.vue`中编写页面布局和样式,例如: ```html <template> <div class="login"> <form> <input type="text" placeholder="请输入用户名" v-model="username"> <input type="password" placeholder="请输入密码" v-model="password"> <button type="submit" @click.prevent="login">登录</button> </form> </div> </template> <style> .login { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; } form { display: flex; flex-direction: column; align-items: center; justify-content: center; } input { width: 300px; height: 40px; margin-bottom: 10px; padding: 10px; border: 1px solid #ccc; border-radius: 5px; font-size: 16px; } button { width: 300px; height: 40px; background-color: #007aff; color: #fff; border: none; border-radius: 5px; font-size: 16px; cursor: pointer; } </style> ``` 4. 在`login.vue`中编写登录逻辑,例如: ```javascript <script> export default { data() { return { username: '', password: '' } }, methods: { login() { // 进行登录操作 console.log('username:', this.username) console.log('password:', this.password) } } } </script> ``` 在`login`方法中可以编写向服务器发送登录请求的代码,例如使用`uni.request`方法发送POST请求。 5. 在`pages.json`文件中添加`login`页面的配置,例如: ```json { "pages": [ { "path": "pages/login/login", "style": { "navigationBarTitleText": "登录" } } ] } ``` 6. 运行uni-app项目,即可在应用程序中查看到登录页面。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值