VC + + 6.0 c8051f340 USB communication CAN Data analysis

Source: Internet
Author: User

//HelloWorld.cpp:Defines the entry point for the console application.///***************************************************************************** * VC + + 6.0 C8051F340 USB Communication CAN Data Resolution * Declaration: * 1. This is the "VC + + 6.0 c8051f340 USB pc-side communication Demo" based on the code; * 2. As you can see, this article will only comment on the relative importance of the content. * 3. This paper mainly obtains the data of can through USB, and resolves the data in it.
* 4. Frame format can be consulted: http://wenku.baidu.com/view/f508511d6bd97f192279e902.html * * 2015-7-11 Sunny Shenzhen Nanshan Ping Shan village Zengjianfeng ****************************************************************************/#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; Si_getnumdevices (&dwnumdevices); printf ("ZENGJF debug:dwnumdevices =%d.\n", dwnumdevices); if(Dwnumdevices = =0 ) returnFALSE; if(Si_open (1, &m_husbdevice) = =si_success) printf ("zengjf debug:si_open usbdevice success.\n"); Elseprintf ("zengjf debug:si_open usbdevice fails.\n"); Chartestdata[ -] ="ZENGJF"; DWORD Haswritten=0; DWORD Hasread=0; DWORD Timecount=0; while(true) {Sleep ( -); //Take 6 frames of data to exit the program, as a test program, this amount is almost if(timecount++ >6 ) Break; memset (TestData,0,sizeof(TestData)); if(Si_read (M_husbdevice, TestData, +, &hasread) = =si_success) {printf ("ZENGJF debug:si_read usbdevice success, hasread length =%d.\n", Hasread); //prints a received frame of data in 16-binary formprintf"printf All data:\n\t"); for(DWORD i =0; i < Hasread; i++) printf ("%02x", Testdata[i] &0xFF); printf ("\ n"); //determine whether the received data is a remote frame or a data frame if(testdata[0] & (1<<6)) printf ("Frame format:remote frame.\n"); Elseprintf ("Frame format:data frame.\n"); //Output Data Lengthprintf"Frame Data length:%d.\n", testdata[0] &0xf); //Whether the output is an extended frame or a standard frame if(testdata[0] & (1<<7) {printf ("Frame type:extend frame.\n"); //parse the ID of an extended frameprintf"ID:%x.\n", (((testdata[1] &0x0ff) << +) |((testdata[2] &0x0ff) << -) |((testdata[3] &0x0ff) <<5) |((testdata[4] >>3) &0x1f))); //converts a binary value to a character number for(DWORD i =5; i < Hasread; i++) Testdata[i]+='0'; //Show all the received dataprintf"ZENGJF debug:show data from c8051f340--testdata[%s].\n", testdata+5); } Else{printf ("Frame Type:standard frame.\n"); //Resolving the ID of a standard frameprintf"ID:%x.\n", (((testdata[1] &0x0ff) <<3) | ((testdata[2] >>5) &0x7))); //converts a binary value to a character number for(DWORD i =3; i < Hasread; i++) Testdata[i]+='0'; //Show all the received dataprintf"ZENGJF debug:show data from c8051f340--testdata[%s].\n", testdata+3); } } Else{printf ("zengjf debug:si_read usbdevice fails.\n"); Break; } } if(Si_close (m_husbdevice) = =si_success) printf ("zengjf debug:si_close usbdevice success.\n"); Elseprintf ("zengjf debug:si_close usbdevice fails.\n"); return 0;}

VC + + 6.0 c8051f340 USB communication CAN Data analysis

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.