Click here to Skip to main content
15,867,568 members
Articles / Desktop Programming / MFC
Tip/Trick

Laptop<->USB<->μcontroller : ways

Rate me:
Please Sign up or sign in to vote.
4.50/5 (3 votes)
19 Apr 2015CPOL2 min read 9.7K   353   7  
Some ways in which laptops and microcontrollers communicate

Introduction

AsSC7 uses overlapped I/O with Arduino: Tx can be pushed while receiving and it seems full-duplex. AsProC9 uses overlapped I/O with asynchronous procedure calls with Arduino: an APC timer polls for Rx, but it is strictly half-duplex.

Using the Code

AsSC7

  • Connect Arduino to laptop via USB and check which COM port it is.
  • Load in Arduino WriteAndRead.
  • Launch AsSC7, choose the same COM port in combobox, push Start, then push Tx when enabled: messages will appear in editbox.
  • Push Pause to stop receiving from Arduino without closing serial port: 00000... will pop up.
  • Push Tx when enabled... Again and again Pause and Tx.
  • To close serial port, push Stop.
  • Push x system command to close app.
  • EXE app has almost no error checking and messages. It presumes all devices work correctly.

AsProC9

  • Connect Arduino to laptop via USB and check which COM port it is.
  • Load in Arduino WriteAndRead. Launch AsProC9, choose the same COM port in combobox: CRichEdit2 is white.
  • Push Communicate, CRichEdit2 is Azure and wait for response: white CRichEdit2. TimerAPC polls for Rx.
  • Timer has a weak algorithm to vary its period depending on frequency of received strings: check or uncheck checkbox and see StringLength, NumRead and ZeroLen in the CRichEdit2.
  • While communicating, wait for an arbitrary moment and push Stop: CRichEdit2 gets pink and some strings received from Arduino or locally written, will be shown.
  • Stop button uses an estimated interval not to stop before transmission from microcontroller is finished: if not, Rx buffer would get dirty.
  • Each app has its own WriteAndRead.

SyScUc8

While the previous two are asynchronous, this one is synchronous. Connect Arduino to laptop via USB and check which COM port it is. Load in Arduino WriteAndRead. Launch SyScUc8, choose the same COM port in combobox. Push Communicate: russian is displayed in Rx. Push again Communicate, till it lasts (5 sec). Then push Stop: with x syscommand can close app. Arduino will flash led 13 to signal it. If last row in WriteAndRead Serial.end(); is inserted, after pushing Stop, Arduino must be reset to redo communication.

Points of Interest

In WriteAndRead.ino, I used crt functions. They seem to work fine.

References

  • MSDN
  • Internet samples
  • Jeffrey Richter, Stanley B. Lippman & Josee Lajoie

History

  • 18th April, 2015: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --