VC + + 6.0 c8051f340 USB pc side Communication Demo

Source: Internet
Author: User

//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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.