USB数据的读写

rooky123 2008-11-28 12:02:27
function USBdevRead(var usb: TLIBUSB; cmd, para1, para2, len: integer): boolean;
begin
if usb.handle = nil then
begin
Result := False;
Exit;
end;
if usb_control_msg(usb.handle, USB_TYPE_VENDOR or USB_RECIP_DEVICE or
USB_ENDPOINT_IN, cmd, para1, para2, usb.dat, len, USB_TIMEOUT) < 0 then
Result := False
else
Result := True;
end;

function USBdevWrite(var usb: TLIBUSB; cmd, para1, para2, len: integer): boolean;
begin
if usb.handle = nil then
begin
Result := False;
Exit;
end;
if usb_control_msg(usb.handle, USB_TYPE_VENDOR or USB_RECIP_DEVICE or
USB_ENDPOINT_OUT, cmd, para1, para2, usb.dat, len, USB_TIMEOUT) < 0 then
Result := False
else
Result := True;
end;



这个是两个读和写的函数,现在写可以了,但是读我读不到数据,就是对里面的参数不大懂,到底应该怎么传才是对的
比如我写是用USBdevWrite(USBasp, 1, 0, 0, 8);可以到数据发送出去
但是我用USBdevRead(USBasp, 0, 0, 0, 4)读取4个字节的数据就不成功,但是把4改成0就可以读成功了,但是没有数据,是不是读成功后我的数据就发在usb.dat,参数应该怎么传才对呢?
...全文
477 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
big_chen 2011-04-11
  • 打赏
  • 举报
回复
你们遇到的问题都还不是很严重,我用usb_control_msg时,usb_device指针本身代表的地址值前后都不一样了,结果应该可想而知,到现在问题还没有解决,严重郁闷中...
rilon1988 2009-03-28
  • 打赏
  • 举报
回复
关注
winli3278 2009-03-27
  • 打赏
  • 举报
回复
我也遇到了相同的问题,read 时 usb_control_msg函数总是返回 -32错误。楼主解决这个问题了吗??
ko_navy 2009-02-03
  • 打赏
  • 举报
回复
mark
sharp99827 2009-02-02
  • 打赏
  • 举报
回复
/**
* usb_control_msg - Builds a control urb, sends it off and waits for completion
* @dev: pointer to the usb device to send the message to
* @pipe: endpoint "pipe" to send the message to
* @request: USB message request value
* @requesttype: USB message request type value
* @value: USB message value
* @index: USB message index value
* @data: pointer to the data to send
* @size: length in bytes of the data to send
* @timeout: time in msecs to wait for the message to complete before
* timing out (if 0 the wait is forever)
* Context: !in_interrupt ()
*
* This function sends a simple control message to a specified endpoint
* and waits for the message to complete, or timeout.
*
* If successful, it returns the number of bytes transferred, otherwise a negative error number.
*
* Don't use this function from within an interrupt context, like a
* bottom half handler. If you need an asynchronous message, or need to send
* a message from within interrupt context, use usb_submit_urb()
* If a thread in your driver uses this call, make sure your disconnect()
* method can wait for it to complete. Since you don't have a handle on
* the URB used, you can't cancel the request.
*/
int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request, __u8 requesttype,
__u16 value, __u16 index, void *data, __u16 size, int timeout)
heeten 2009-01-19
  • 打赏
  • 举报
回复
up
rooky123 2008-12-01
  • 打赏
  • 举报
回复
USB 芯片是使用的D12,硬件是没有问题的,使用周立功的那个USBDEBUG都没有问题,发过去了,能看到收到的数据

我的意思不是发送和接收有问题了,而是usb_control_msg这个函数的各个参数的使用方法
bdc995 2008-12-01
  • 打赏
  • 举报
回复
usb的固件是不是有问题呢?
xxgamexx 2008-11-28
  • 打赏
  • 举报
回复
关注!

4,436

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 内核源代码研究区
社区管理员
  • 内核源代码研究区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧