mini2440_x35 ubuntu下使用dnw进行传送文件
来源:互联网 发布:linux git生成ssh key 编辑:程序博客网 时间:2024/04/30 03:11
关键点
需要libusb的支持,使用apt-get install libusb进行安装
注意QQ2440_SECBULK_IDVENDOR 以及 QQ2440_SECBULK_IDPRODUCT的值,我使用的是方口进行数据传输,对应的值是0x5345以及0x1234。下面介绍如何查询这两个值
- 将开发版拨到NOR,并开机
- 输入lisusb,可以看到
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching HubBus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hubBus 001 Device 003: ID 13d3:5165 IMC Networks Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching HubBus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hubBus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hubBus 003 Device 005: ID 5345:1234 Owon PDS6062T OscilloscopeBus 003 Device 002: ID 0461:4de2 Primax Electronics, Ltd Bus 003 Device 004: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) ICBus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Owon PDS6062T就是我们的方口啦,它的ID就是5345:1234
dnw源代码
#include <stdio.h> #include <usb.h> #include <errno.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #define QQ2440_SECBULK_IDVENDOR 0x5345 #define QQ2440_SECBULK_IDPRODUCT 0x1234 struct usb_dev_handle * open_port() { struct usb_bus *busses, *bus; usb_init(); usb_find_busses(); usb_find_devices(); busses = usb_get_busses(); for(bus=busses;bus;bus=bus->next) { struct usb_device *dev; for(dev=bus->devices;dev;dev=dev->next) { printf("idVendor:0x%x\t,ipProduct:0x%x\n",dev->descriptor.idVendor,dev->descriptor.idProduct); if( QQ2440_SECBULK_IDVENDOR==dev->descriptor.idVendor && QQ2440_SECBULK_IDPRODUCT==dev->descriptor.idProduct) { printf("Target usb device found!\n"); struct usb_dev_handle *hdev = usb_open(dev); if(!hdev) { perror("Cannot open device"); } else { if(0!=usb_claim_interface(hdev, 0)) { perror("Cannot claim interface"); usb_close(hdev); hdev = NULL; } } return hdev; } } } printf("Target usb device not found!\n"); return NULL; } void usage() { printf("Usage: dnw2 <file>\n\n"); } unsigned char* prepare_write_buf(char *filename, unsigned int *len) { unsigned char *write_buf = NULL; struct stat fs; int fd = open(filename, O_RDONLY); if(-1==fd) { perror("Cannot open file"); return NULL; } if(-1==fstat(fd, &fs)) { perror("Cannot get file size"); goto error; } write_buf = (unsigned char*)malloc(fs.st_size+10); if(NULL==write_buf) { perror("malloc failed"); goto error; } if(fs.st_size != read(fd, write_buf+8, fs.st_size)) { perror("Reading file failed"); goto error; } printf("Filename : %s\n", filename); printf("Filesize : %d bytes\n", fs.st_size); *((u_int32_t*)write_buf) = 0x30000000; //download address *((u_int32_t*)write_buf+1) = fs.st_size + 10; //download size; *len = fs.st_size + 10; return write_buf; error: if(fd!=-1) close(fd); if(NULL!=write_buf) free(write_buf); fs.st_size = 0; return NULL; } int main(int argc, char *argv[]) { if(2!=argc) { usage(); return 1; } struct usb_dev_handle *hdev = open_port(); if(!hdev) { return 1; } unsigned int len = 0; unsigned char* write_buf = prepare_write_buf(argv[1], &len); if(NULL==write_buf) return 1; unsigned int remain = len; unsigned int towrite; printf("Writing data ...\n"); while(remain) { towrite = remain>512 ? 512 : remain; if(towrite != usb_bulk_write(hdev, 0x03, write_buf+(len-remain), towrite, 3000)) { perror("usb_bulk_write failed"); break; } remain-=towrite; printf("\r%d%\t %d bytes ", (len-remain)*100/len, len-remain); fflush(stdout); } if(0==remain) printf("Done!\n"); return 0; }
gcc -o dnw2 dnw.c 进行编译
./dnw2 filename 进行传输。
网络上很多代码都是需要加载驱动之类的,我试过了好多,都失败了。这个方法是可行的
0 0
- mini2440_x35 ubuntu下使用dnw进行传送文件
- mini2440_x35 使用minicom进行连接,传送文件
- linux 下DNW 传送文件
- ubuntu下如何使用minicom传送文件
- ubuntu下使用dnw遇到的问题
- tiny4412使用---ubuntu下的dnw
- 使用CSockets进行文件传送
- 使用CSockets进行文件传送
- ubuntu下使用kermit协议,通过串口传送文件
- 在Linux环境下安装并使用DNW进行文件下载
- Ubuntu 12.10 使用DNW传数据 进行ARM开发板烧写
- ubuntu 下使用usb2ram替代windows下的DNW软件
- ubuntu 下使用usb2ram替代windows下的DNW软件
- linux(ubuntu)下利用dnw烧写文件
- linux下使用DNW传数据 进行ARM开发板烧写
- fedora下使用dnw
- VC 使用CSockets进行小文件传送
- 使用Ip/tcp协议进行文件传送
- Android文字测量与绘制的两个注意点
- css3媒体查询实现网站响应式布局
- How to run 32-bit app in Ubuntu 64-bit?
- CSS控制文本自动换行
- opnet 遇到的语法错误
- mini2440_x35 ubuntu下使用dnw进行传送文件
- linux下使用gdb调试程序
- Nim语言字符串切片
- java入门练习题三
- 查找数据库对象的关联对象列表
- CSAPP——实验三 内存攻击(一)
- Python定时任务
- JAVA正则表达式语法大全
- SD卡读写文件