• Save
RoboCV Module 6: Hardware Interfacing using Visual C++
Upcoming SlideShare
Loading in...5
×
 

RoboCV Module 6: Hardware Interfacing using Visual C++

on

  • 1,672 views

These are the slides of the RoboCV Workshop organized by roboVITics on August 11th-12th, 2012 in TT311 Smart Classroom, VIT University, Vellore. ...

These are the slides of the RoboCV Workshop organized by roboVITics on August 11th-12th, 2012 in TT311 Smart Classroom, VIT University, Vellore.

The workshop was delivered by the following people:
1. Mayank Prasad, President of roboVITics
2. Akash Kashyap, President of TEC - The Electronics Club of VIT
3. Akshat Wahi, Asst. Project Manager of roboVITics

Statistics

Views

Total Views
1,672
Views on SlideShare
807
Embed Views
865

Actions

Likes
1
Downloads
1
Comments
0

2 Embeds 865

http://robovitics.wordpress.com 861
https://robovitics.wordpress.com 4

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

CC Attribution-NonCommercial-NoDerivs LicenseCC Attribution-NonCommercial-NoDerivs LicenseCC Attribution-NonCommercial-NoDerivs License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

RoboCV Module 6: Hardware Interfacing using Visual C++ RoboCV Module 6: Hardware Interfacing using Visual C++ Presentation Transcript

  • Using Visual C++Module 6 © Akshat Wahi | roboVITics, 2012 1
  • • The overall goal is to give a basic overview of how Serial Communications programming works using Windows API © Akshat Wahi | roboVITics, 2012 2
  • • Make sure to include “windows.h” header file. HANDLE hSerial; hSerial = CreateFile(TEXT("COM1“), GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); © Akshat Wahi | roboVITics, 2012 3
  • • Now we have a HANDLE to the serial port, we need to set certain parameters for communication (baud rate, stopbits etc.)• Windows does this through a struct called DCB . DCB dcbSerial = {0}; dcbSerial.DCBlength=sizeof(dcbSerial); if (!GetCommState(hSerial, &dcbSerial)) { //error getting state } dcbSerial.BaudRate=CBR_19200; dcbSerial.ByteSize=8; dcbSerial.StopBits=ONESTOPBIT; dcbSerial.Parity=NOPARITY; if(!SetCommState(hSerial, &dcbSerial)){ //error setting serial port state } © Akshat Wahi | roboVITics, 2012 4
  • • Now we have an open serial port with correct parameters, so we can begin writing data . char data =‘f’; DWORD byteswritten=0; if(!WriteFile(hSerial,&data,1,&byteswritten,NULL)){ //error occurred ,data not written } © Akshat Wahi | roboVITics, 2012 5
  • • Reading is similar to writing we use ReadFile() char data; DWORD bytesread=0; if(!ReadFile(hSerial,&data,1,&bytesread,NULL)){ //error occurred ,data not written } © Akshat Wahi | roboVITics, 2012 6
  • • Once you’re done using the serial port, make sure to close the HANDLE.• If you don’t weird things can happen. CloseHandle(hSerial); © Akshat Wahi | roboVITics, 2012 7
  • • http://msdn.microsoft.com/en-us/library/ms123401.aspx © Akshat Wahi | roboVITics, 2012 8
  • • Mayank Prasad President, roboVITics mayank@robovitics.in• Akshat Wahi Asst. Project Manager, roboVITics +91 909 250 3053 akshat@core.robovitics.in• Akash Kashyap President, TEC – The Electronics Club of VIT akash130791@gmail.com © Akshat Wahi | roboVITics, 2012 9