📄 speed_i2c.c
字号:
//****************************************
//** Copyright (C) USBIO 1999-2004 **
//** Web: http://www.usb-i2c-spi.com **
//****************************************
//** C, VC6.0 **
//****************************************
//
// USB2I2C 测试I2C传输速度
//
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <winioctl.h>
#include "USBIOX.H" // USB2I2C的动态链接库
//程序入口
void main ( )
{
unsigned char mBuffer[4100];
unsigned long i, mLength, mTestCount, mErrCnt, mStep, mTotal;
double speed;
printf( "\nUSB2I2C Bulk Data Test Program V0.2 , Copyright (C) USBIO TECH. 2003.12\n" );
// 需要使用DLL则需要先加载
printf( "Load DLL: USBIOX.DLL ......\n" );
if ( LoadLibrary( "USBIOX.DLL" ) == NULL ) return; // 加载DLL失败,可能未安装到系统中
printf( "USBIO_OpenDevice: 0# \n" );
if ( USBIO_OpenDevice( 0 ) == INVALID_HANDLE_VALUE ) return; /* 使用之前必须打开设备 */
mErrCnt = 0;
printf( "*** Step-1: test speed of download data: 2048KB data \n" );
for ( i=0; i<4096; i+=4 ) *(unsigned long *)(&mBuffer[i])=rand(); // 产生随机数以发送
mTotal=0;
mStep=GetTickCount();
for ( mTestCount=0; mTestCount<500; ++mTestCount ) // 循环测试
{
*(unsigned long *)(&mBuffer[4])=mTestCount;
mLength = 4096;
if ( USBIO_EppWriteData( 0, &mBuffer, &mLength ) ) // 发送成功
{
if ( mLength != 4096 ) printf( "S2-C%ld USBIO_WriteData actual length short %ld (4096)\n", mLength );
mTotal +=mLength; // 累计长度
}
else { // 写操作失败
mErrCnt++;
printf( "S2-C%ld USBIO_WriteData return error\n", mTestCount );
}
}
mLength=GetTickCount();
mLength=mLength-mStep;
speed=1000;
if ( mLength !=0 ) speed=speed*mTotal/mLength;
else speed=9999999;
printf( "*** download speed = %7.1f Bytes/Sec, total=%ld bytes, time=%ld mS\n", speed, mTotal, mLength);
Sleep(100);
printf( "*** Step-2: test speed of upload data: 2048KB data\n" );
mTotal=0;
mStep=GetTickCount();
for ( mTestCount=0; mTestCount<500; ++mTestCount ) // 循环测试
{
mLength = 4096;
if ( USBIO_EppReadData( 0, &mBuffer, &mLength ) ) // 接收成功
{
if ( mLength != 4096 ) printf( "S3-C%ld USBIO_ReadData actual length short %ld (4096)\n", mLength );
mTotal +=mLength; // 累计长度
}
else { // 读操作失败
mErrCnt++;
printf( "S3-C%ld USBIO_ReadData return error\n", mTestCount );
}
}
mLength=GetTickCount();
mLength=mLength-mStep;
speed=1000;
if ( mLength !=0 ) speed=speed*mTotal/mLength;
else speed=9999999;
printf( "*** upload speed = %7.1f Bytes/Sec, total=%ld bytes, time=%ld mS\n", speed, mTotal, mLength);
Sleep(100);
// 关闭USB2I2C设备,如果不继续使用则必须关闭设备,就象读写完硬盘中的数据文件后要关闭一样
printf( "*** Total error = %ld \n", mErrCnt );
printf( "*** USBIO_CloseDevice: 0 \n" );
USBIO_CloseDevice( 0 );
printf( "\nExit.\n" );
getch();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -