//HelloWorld.cpp:Defines the entry point for the console application.///*************************************************************************** * VC + + 6.0 c8051f340 USB Communication Demo * Statement: * 1. In addition, this procedure needs c8051f340 single-chip microcomputer program to cooperate; * 2. This procedure is in the possession of SiUSBXp.h, SiUSBXp.lib, SiUSBXp.dll on the basis of doing, * I do not know where this is from, colleagues left. * 2015-7-11 Sunny Shenzhen Nanshan Ping Shan village increased Janus ********************************************************* *****************/#include"stdafx.h"#include<windows.h>#include<time.h>#include"SiUSBXp.h"#include<string.h>intMainintargcChar*argv[]) {printf ("Hello world!\n"); HANDLE M_husbdevice=Invalid_handle_value; DWORD dwnumdevices=0; //get how many devices are currently available on the systemSi_getnumdevices (&dwnumdevices); printf ("ZENGJF debug:dwnumdevices =%d.\n", dwnumdevices); //if the number of devices is zero, it is not necessary to continue running if(Dwnumdevices = =0) return-1; //Open the No. 0 available device if(Si_open (0, &m_husbdevice) = =si_success) printf ("zengjf debug:si_open usbdevice success.\n"); Else{printf ("zengjf debug:si_open usbdevice fails.\n"); return-1; } //Initialize some of the data to be transferred and some data that will be needed Chartestdata[ -] ="ZENGJF"; DWORD Haswritten=0; DWORD Hasread=0; //write data to c8051f340 microcontroller if(Si_write (M_husbdevice, TestData, strlen (testData), &haswritten) = =si_success) printf ("ZENGJF debug:si_write usbdevice success, Haswritten length =%d.\n", Haswritten); Else{printf ("zengjf debug:si_write usbdevice fails.\n"); return-1; } //sleep 1s, waiting for data to return, this is because it has been set inside the c8051f340 microcontroller, will return a string of charactersSleep ( +); //re-clean up the data in testdata to prepare for receiving datamemset (TestData,0,sizeof(TestData)); //read SCM Internal c8051f340 SCM sent back data, microcontroller only sent 16 characters, hasread to keep the number of real things read characters if(Si_read (M_husbdevice, TestData, -, &hasread) = =si_success) {printf ("ZENGJF debug:si_read usbdevice success, hasread length =%d.\n", Hasread); printf ("ZENGJF debug:get data from c8051f340--testdata[%s].\n", TestData); } Else{printf ("zengjf debug:si_read usbdevice fails.\n"); return-1; } //Turn off communication connections if(Si_close (m_husbdevice) = =si_success) printf ("zengjf debug:si_close usbdevice success.\n"); Else{printf ("zengjf debug:si_close usbdevice fails.\n"); return-1; } return 0;}
VC + + 6.0 c8051f340 USB pc side Communication Demo