sampleapp.c

来自「usbSampleApp,USB的工业标准是对PC机现有的体系结构的扩充。USB」· C语言 代码 · 共 99 行

C
99
字号
/*
**********************************************************************
*                          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 + =
减小字号Ctrl + -
显示快捷键?