Arm USB communication

Source: Internet
Author: User

Part of oscilloscope Development

The dynamic link library of zlg is used for dynamic loading.

Arm is Context-M3-1343.

PC communication software developed in C ++ Builder 6.

The USB communication code is as follows:

// ----------------------------------------------------------------------------- </P> <p> # include <VCL. h> <br/> # pragma hdrstop </P> <p> # include "unit1.h" <br/> // # include "zyusbdev. H "</P> <p> // usage <br/> # pragma package (smart_init) <br/> # pragma resource "*. DFM "<br/> tform1 * form1; <br/> //--------------------------------------------------- ------------------------ <Br/>__ fastcall tform1: tform1 (tcomponent * owner) <br/>: tform (owner) <br/>{< br/>}< br/> // signature </P> <p> void _ fastcall tform1: button1click (tobject * sender) <br/>{< br/> unsigned char sendbuf [1024], recbuf [1024]; <br/> int I; </P> <p> unsigned char inbyte; <br/> for (I = 0; I <sizeof (sendbuf); I ++) <br/> {<Br/> sendbuf [I] = inbyte; // 4096 bytes in the sending buffer in hexadecimal notation <br/> recbuf [I] = 0; // clear the receiving buffer <br/>}</P> <p> /*********************. dynamic library ***********************/<br/> int ret; <br/> ansistring m_disp = "China"; <br/> unsigned char cmd [2], ack; <br/> cmd [0] = sizeof (sendbuf)/256; // The length of the number of bytes to be sent is 8 bits <br/> cmd [1] = sizeof (sendbuf) % 256; // 8-bit lower </P> <p> hinstance handle; <br/> farproc lpfarproc; <br/> in T _ stdcall (* pfun) (INT, unsigned char *, Int, INT); // change </P> <p> handle = loadlibrary ("zyusbdev. DLL "); <br/> lpfarproc = getprocaddress (handle," zyusb_readdata "); <br/> pfun = (INT (_ stdcall *) (INT, unsigned char *, int, INT) lpfarproc; // _ cdecl </P> <p> // Step 5: Use logical endpoint 2, receives a large amount of data from a USB device <br/> ret = pfun (2, recbuf, sizeof (sendbuf), 1000); <br/> If (Ret! = Sizeof (sendbuf) <br/>{< br/> If (Ret <= 0) <br/>{< br/> m_disp = "logical endpoint 2 receive data error: no valid data is received. "; <Br/>}< br/> else if (Ret> 0) <br/>{< br/> m_disp =" error in receiving data from logical endpoint 2: some data is received. "; <Br/>}</P> <p> // MessageBox (" logical endpoint 2 receives data error "); <br/> return; <br/>}</P> <p> // display received bytes <br/> m_disp = ""; <br/> int temp = 0; <br/> temp = recbuf [0] + recbuf [1] * 256; <br/> m_disp = inttostr (temp) + ""; <br/> for (I = 0; I <sizeof (sendbuf); I ++) <br/> m_disp = m_disp + recbuf [I] + ""; </P> <p> memo1-> text = m_disp; <br/> freelibrary (handle); <br/>}< br/> // handle <br/>

For details, see www.jxust3jia1.com, which describes the oscilloscope project.

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.