舞之韵艺术培训中心:教你如何在开发驱动时在图形界面下的终端打印字符!!
来源:百度文库 编辑:九乡新闻网 时间:2024/04/29 05:52:11
我们平时在图形界面下开一个终端(xterm),然后在程序里面开发程序时,用printk()打印一些我们需要打印的信息,但是这些信息不能在当前终端下面显示出来,只能通过dmesg才能查看,很麻烦,这两天从书上学了一个方法,拿出来和大家分享一下,简单的几句代码就可以解决这个问题,代码如下:
#include
#include
#include
#include
#include
#include
MODULE_LICENSE("GPL");
MODULE_AUTHOR("ZHANG FEI LONG");//这些信息可以通过modinfo XXX.o查看
static void print_string(char * str)
{
struct tty_struct * my_tty; //将要显示字符的终端
#if(LINUX_VERSION_CODE<=KERNEL_VERSION(2,6,5))//条件编译判断kernel版本
my_tty = current->tty;
#else
my_tty = current->signal->tty;
#endif
if(my_tty!=NULL)
{
((my_tty->driver)->ops->write)(my_tty,
#if(LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,9))
0,
#endif
str,
strlen(str));
#if(LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,9))
((my_tty->driver)->ops->write)(my_tty,0,"\015\012",2);
#else
((my_tty->driver)->ops->write)(my_tty,"\015\012",2);
#endif
}
}
static int __init print_string_init(void)
{
print_string("The module has been inserted,Hello World");
return 0;
}
static void __exit print_string_exit(void)
{
print_string("The module has been removed,Farewell world");
}
module_init(print_string_init);
module_exit(print_string_exit);
代码里面的关键部分就是print_string(char *)这个函数了,以后我们就可以调用这个信息随便的在自己xterm里面打印信息了。
#include
#include
#include
#include
#include
#include
MODULE_LICENSE("GPL");
MODULE_AUTHOR("ZHANG FEI LONG");//这些信息可以通过modinfo XXX.o查看
static void print_string(char * str)
{
struct tty_struct * my_tty; //将要显示字符的终端
#if(LINUX_VERSION_CODE<=KERNEL_VERSION(2,6,5))//条件编译判断kernel版本
my_tty = current->tty;
#else
my_tty = current->signal->tty;
#endif
if(my_tty!=NULL)
{
((my_tty->driver)->ops->write)(my_tty,
#if(LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,9))
0,
#endif
str,
strlen(str));
#if(LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,9))
((my_tty->driver)->ops->write)(my_tty,0,"\015\012",2);
#else
((my_tty->driver)->ops->write)(my_tty,"\015\012",2);
#endif
}
}
static int __init print_string_init(void)
{
print_string("The module has been inserted,Hello World");
return 0;
}
static void __exit print_string_exit(void)
{
print_string("The module has been removed,Farewell world");
}
module_init(print_string_init);
module_exit(print_string_exit);
代码里面的关键部分就是print_string(char *)这个函数了,以后我们就可以调用这个信息随便的在自己xterm里面打印信息了。
教你如何在开发驱动时在图形界面下的终端打印字符!!
linux下的触摸屏驱动开发
摄影师教你如何在正午的阳光下拍摄
如何在Windows下搭建Android开发环境
教你在Excel 中禁止打印
linux下的触摸屏驱动开发 - Qzone日志
Linux下利用sed在文档的每行首或行尾增加减少字符
如何在Word下实现方格稿纸打印-办公软件,WORD-办公用品行业-hc360慧聪网
全州seo教你在一无所有情况下如何创业
如何在 Qt 中正确显示宽字符
在 Windows XP 下,打印出的文本页面最后一行出现残缺打不全,怎么办?
教你如何打印请柬
在AIX下通过光纤连接LTO 3582磁带库,驱动的安装方法 - 无法无天耗的日志 - 网...
编写uboot下Nor Flash驱动的注意事项 - 嵌入式开发 - Linux论坛
uclinux添加字符设备驱动过程--shinep的笔记
如何在Excel中正确打印不连续区域的数据
如何把excel不相邻的区域打印在同一页
在你的夜阑下,一帘幽梦谁与共
Excel中如何实现一个表头打印在多页上
如何把打印图纸摹印在布上
在IE下使用Firebug的简单功能 – WEB前端开发
教你在Windows下对硬盘分区 .
教你如何在Win7系统下对硬盘进行分区.
教你如何在Win7系统下对硬盘进行分区