⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sampleapp.c

📁 usbSampleApp,USB的工业标准是对PC机现有的体系结构的扩充。USB的设计主要遵循以下几个准则: &#8226 易于扩充多个外围设备; &#8226 价格低廉
💻 C
字号:
/*
**********************************************************************
*                          Micrium, Inc.
*                      949 Crestview Circle
*                     Weston,  FL 33327-1848
*
*                           uC/USB-Bulk
*
*             (c) Copyright 2003 - 2004, Micrium, Inc.
*                      All rights reserved.
*
***********************************************************************

----------------------------------------------------------------------
File    : SampleApp.c
Purpose : USB BULK Sample Application
---------------------------END-OF-HEADER------------------------------
*/

#include <stdio.h>
#include <windows.h>
#include "USBBULK.h"



/*********************************************************************
*
*       _MessageBox
*
*/
static void _MessageBox(const char * s) {
  MessageBox(NULL, s, "USB Bulk sample application", MB_OK);
}


/*********************************************************************
*
*       _SendReceive1
*
*/
static int _SendReceive1(unsigned char DataTx) {
  unsigned char DataRx;
  int r;

  printf("Writing one byte\n");
  r = USBBULK_Write(&DataTx, 1);
  if (r == 0) {
    _MessageBox("Could not write to device");
  }

  printf("Reading one byte\n");
  r = USBBULK_Read (&DataRx, 1);
  if (r == 0) {
    _MessageBox("Could not read from device (time out)");
  }
  if (DataRx != (DataTx + 1)) {
    _MessageBox("Wrong data read");
    return 1;
  }
  printf("Operation succesful!\n\n");
  return 0;
}


/*********************************************************************
*
*       _Test
*
*/
int Test(void) {
  int r;
  r = _SendReceive1(0x12);
  if (r) {
    return r;
  }
  r = _SendReceive1(0x13);
  return r;
}

/*********************************************************************
*
*       main
*
* Function description
*/
int main(int argc, char* argv[]) {
  int r;
  if (USBBULK_Open() == NULL) {
    _MessageBox("Unable to connect to USB BULK device");
    return 1;
  }
  r = Test();
  USBBULK_Close();
  if (r == 0) {
    _MessageBox("Communication with USB BULK device succesful!");
  }
  return r;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -