網(wǎng)上有很多關(guān)于pos機(jī)的驅(qū)動(dòng),一個(gè)簡(jiǎn)單的Linux內(nèi)核字符驅(qū)動(dòng)程序編寫的知識(shí),也有很多人為大家解答關(guān)于pos機(jī)的驅(qū)動(dòng)的問題,今天pos機(jī)之家(www.tjfsxbj.com)為大家整理了關(guān)于這方面的知識(shí),讓我們一起來看下吧!
本文目錄一覽:
2、收銀機(jī)不出小票對(duì)機(jī)器有沒有影響
3、pos 8015c熱敏打印機(jī)驅(qū)動(dòng)怎樣安裝?
pos機(jī)的驅(qū)動(dòng)
一、背景為了了解設(shè)備驅(qū)動(dòng)程序的框架,在此編寫一個(gè)簡(jiǎn)單的字符驅(qū)動(dòng)程序,以此來對(duì)驅(qū)動(dòng)程序的框架進(jìn)行一個(gè)簡(jiǎn)單的了解。
嵌入式進(jìn)階教程分門別類整理好了,看的時(shí)候十分方便,由于內(nèi)容較多,這里就截取一部分圖吧。
需要的朋友私信【內(nèi)核】即可領(lǐng)取。
內(nèi)核學(xué)習(xí)地址:Linux內(nèi)核源碼/內(nèi)存調(diào)優(yōu)/文件系統(tǒng)/進(jìn)程管理/設(shè)備驅(qū)動(dòng)/網(wǎng)絡(luò)協(xié)議棧-學(xué)習(xí)視頻教程-騰訊課堂
所謂設(shè)備驅(qū)動(dòng)程序,其實(shí)就是計(jì)算機(jī)硬件與外部設(shè)備進(jìn)行通信的接口。由于硬件設(shè)備各式各樣,有了設(shè)備驅(qū)動(dòng)程序,應(yīng)用程序就可以不用在意設(shè)備的具體細(xì)節(jié),而方便地與外部設(shè)備進(jìn)行通信。從外部設(shè)備讀取數(shù)據(jù),或是將數(shù)據(jù)寫入外部設(shè)備,即對(duì)設(shè)備進(jìn)行控制。
三、設(shè)備驅(qū)動(dòng)程序框架設(shè)備的種類繁多是可想而知的,所以設(shè)備的驅(qū)動(dòng)程序也是各式各樣的。由此需要建立一個(gè)統(tǒng)一的規(guī)范:SVR4(UNIX System V Rlease 4)提出了DDI/DKI(Driver-Device Interface/Driver-Kernel Interface)規(guī)范。這個(gè)SVR4是UNIX操作系統(tǒng)的一種內(nèi)核標(biāo)準(zhǔn)。
規(guī)范分為以下三個(gè)部分:
1、驅(qū)動(dòng)程序與內(nèi)核的接口2、驅(qū)動(dòng)程序與設(shè)備的接口3、驅(qū)動(dòng)程序與系統(tǒng)引導(dǎo)的接口其中,驅(qū)動(dòng)程序與內(nèi)核的接口是通過數(shù)據(jù)結(jié)構(gòu)file_opration完成的。驅(qū)動(dòng)程序與設(shè)備的接口描述了驅(qū)動(dòng)程序如何與設(shè)備交互,這與具體的設(shè)備是密切相關(guān)的。驅(qū)動(dòng)程序與系統(tǒng)引導(dǎo)的接口其實(shí)就是驅(qū)動(dòng)程序?qū)υO(shè)備進(jìn)行初始化。
四、簡(jiǎn)單的字符驅(qū)動(dòng)程序我在這里直接將我編寫的字符驅(qū)動(dòng)程序展示出來,然后對(duì)其進(jìn)行分析:
#include<linux/init.h>#include<linux/module.h>#include<linux/types.h>#include<linux/fs.h>#include<linux/mm.h>#include<linux/sched.h>#include<linux/cdev.h>#include<asm/io.h>#include<asm/switch_to.h>#include<asm/uaccess.h>#include<linux/kernel.h>MODULE_LICENSE("GPL");#define MYCDEV_MAJOR 231#define MYCDEV_SIZE 1024static int mycdev_open(struct inode *inode,struct file *fp){ return 0;}static int mycdev_release(struct inode *inode,struct file *fp){ return 0;}static ssize_t mycdev_read(struct file *fp,char __user *buf,size_t size,loff_t *pos){ unsigned long p = *pos; unsigned int count = size; char kernel_buf[MYCDEV_SIZE] = "This is mycdev!"; int i; if(p >= MYCDEV_SIZE) return -1; if(count > MYCDEV_SIZE) count = MYCDEV_SIZE - p; if(copy_to_user(buf,kernel_buf,count) != 0){ printk("read error!\"); return -1; } printk("reader:%d bytes was read...\",count); return count;}static ssize_t mycdev_write(struct file *fp,const char __user *buf,size_t size,loff_t *pos){ return size;}static const struct file_operations mycdev_fops ={ .owner = THIS_MODULE, .read = mycdev_read, .write = mycdev_write, .open = mycdev_open, .release = mycdev_release,};static int __init mycdev_init(void){ int ret; printk("mycdev module is starting..\"); ret = register_chrdev(MYCDEV_MAJOR,"my_cdev",&mycdev_fops); if(ret < 0) { printk("register failed..\"); return 0; } else { printk("register success..\"); } return 0;}static void __exit mycdev_exit(void){ printk("mycdev module is leaving..\"); unregister_chrdev(MYCDEV_MAJOR,"my_cdev");}module_init(mycdev_init);module_exit(mycdev_exit);
首先看一下file_operation結(jié)構(gòu)體,此結(jié)構(gòu)體是該驅(qū)動(dòng)程序的核心。它給出了對(duì)文件操作函數(shù)的定義。當(dāng)然,具體的實(shí)現(xiàn)函數(shù)是留給驅(qū)動(dòng)程序編寫的:
struct file_operations { struct module *owner; loff_t (*llseek) (struct file *, loff_t, int); ssize_t (*read) (struct file *, char __user *, size_t, loff_t *); ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *); ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t); ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t); int (*readdir) (struct file *, void *, filldir_t); unsigned int (*poll) (struct file *, struct poll_table_struct *); long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long); long (*compat_ioctl) (struct file *, unsigned int, unsigned long); int (*mmap) (struct file *, struct vm_area_struct *); int (*open) (struct inode *, struct file *); int (*flush) (struct file *, fl_owner_t id); int (*release) (struct inode *, struct file *); int (*fsync) (struct file *, loff_t, loff_t, int datasync); int (*aio_fsync) (struct kiocb *, int datasync); int (*fasync) (int, struct file *, int); int (*lock) (struct file *, int, struct file_lock *); ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int); unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long); int (*check_flags)(int); int (*flock) (struct file *, int, struct file_lock *); ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int); ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int); int (*setlease)(struct file *, long, struct file_lock **); long (*fallocate)(struct file *file, int mode, loff_t offset, loff_t len); int (*show_fdinfo)(struct seq_file *m, struct file *f);};
此結(jié)構(gòu)對(duì)文件操作的函數(shù)給出了定義。種類繁多。
我們這里的file_operation結(jié)構(gòu)體進(jìn)行初始化時(shí)僅初始化了4個(gè)函數(shù)。這些使用的函數(shù)在程序的前半部分已經(jīng)給出了定義。
五、調(diào)試程序由于編寫的是內(nèi)核模塊,所以需要用make進(jìn)行編譯。這個(gè)我在之前的博客已經(jīng)寫過如何編寫Makefile文件。編譯完畢后將模塊插入。
然后,通過cat /proc/devices來看系統(tǒng)中未使用的字符設(shè)備主設(shè)備號(hào),我這里看到的是my_cdev,對(duì)應(yīng)的是231號(hào)。
接下來使用mknod命令創(chuàng)建設(shè)備文件結(jié)點(diǎn),然后用chmod命令修改權(quán)限為777。此時(shí)設(shè)備就可以使用了。
這里我們需要注意一下/proc/devices與/dev下的顯示的設(shè)備的不同之處。
在/proc/devices下,顯示的是驅(qū)動(dòng)程序生成的設(shè)備及其主設(shè)備號(hào)。其中主設(shè)備號(hào)可用來讓mknod作為參數(shù)。
在/dev下的設(shè)備是mknod生成的設(shè)備,其中,用戶通過使用/dev下的設(shè)備名來使用設(shè)備。
六、編寫用戶態(tài)測(cè)試程序#include<stdio.h>#include<sys/types.h>#include<sys/stat.h>#include<fcntl.h>#include<stdlib.h>#include<unistd.h>int main(){ int testdev; int i,ret; char buf[10]; testdev = open("/dev/mycdev",O_RDWR); if(testdev == -1){ printf("connot open file..\"); exit(1); } if((ret = read(testdev,buf,10)) <10){ printf("read error!\"); exit(1); } for(i=0;i<10;i++) printf("%d\",buf[i]); close(testdev); return 0;}
這個(gè)程序沒什么好說的。
七、運(yùn)行結(jié)果插入模塊后查看日志信息:
運(yùn)行測(cè)試程序:
這里我們看到,它輸出了數(shù)組的前十個(gè)字節(jié),對(duì)應(yīng)著:This is my
查看日志信息:
這個(gè)我們看到,驅(qū)動(dòng)也打印出了一段文字,十個(gè)字節(jié)被讀取。
卸載模塊:
八、總結(jié)這里只是簡(jiǎn)單地介紹了一下設(shè)備驅(qū)動(dòng)程序的框架,作為一個(gè)對(duì)驅(qū)動(dòng)程序的簡(jiǎn)單了解。
原文鏈接:https://blog.csdn.net/hty46565/article/details/53053345
收銀機(jī)不出小票對(duì)機(jī)器有沒有影響
不出小票可能是POS機(jī)有什么問題,不影響機(jī)器使用橋虧拿。
1、檢查電源鍵是否接通。
2、查看一下POS機(jī)是否卡紙。
3、查看一下POS機(jī)是否進(jìn)水或者短路。
4、查看一下收銀POS機(jī)與電腦數(shù)據(jù)鏈接線是否正敏搭確。
5、查看POS機(jī)的驅(qū)動(dòng)是否正常。
6、檢查空神POS機(jī)卷紙滾筒損壞。
7、查看收銀機(jī)軟件設(shè)置問題。
pos 8015c熱敏打印機(jī)驅(qū)動(dòng)怎樣安裝?
安裝打印機(jī)一般通過控制面板的添加打印機(jī)來操作,具體可以參考如下步驟:
1、首先確定打印機(jī)是否能正常使用。
2、將usb數(shù)據(jù)線聯(lián)接電腦和打印機(jī),開始——控制面板——硬件和聲音,點(diǎn)擊“設(shè)備和打印機(jī)”選項(xiàng)的“添加打印機(jī)”。
3、點(diǎn)擊添加本地打印機(jī)(第二個(gè)不用管他,他是裝無(wú)線打印機(jī)的一般用不上)選擇打印機(jī)的端口類型,一般說明書上有。
在選項(xiàng)列表內(nèi)選著打印機(jī)的品牌和型號(hào),如果你有光盤的話就用隨機(jī)附送的光盤直接安裝打印機(jī)的驅(qū)動(dòng)系統(tǒng),如果沒有的話,那就到該品牌的官方網(wǎng)站下載這個(gè)型號(hào)的打印機(jī)驅(qū)動(dòng)就行,按照它的提示一步一步安裝就行了。
以上就是關(guān)于pos機(jī)的驅(qū)動(dòng),一個(gè)簡(jiǎn)單的Linux內(nèi)核字符驅(qū)動(dòng)程序編寫的知識(shí),后面我們會(huì)繼續(xù)為大家整理關(guān)于pos機(jī)的驅(qū)動(dòng)的知識(shí),希望能夠幫助到大家!
