Code Search for Developers
 
 
  

UsbSerial.h from Make Controller at Krugle


Show UsbSerial.h syntax highlighted

/*********************************************************************************

 Copyright 2006 MakingThings

 Licensed under the Apache License, 
 Version 2.0 (the "License"); you may not use this file except in compliance 
 with the License. You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0 
 
 Unless required by applicable law or agreed to in writing, software distributed
 under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 CONDITIONS OF ANY KIND, either express or implied. See the License for
 the specific language governing permissions and limitations under the License.

*********************************************************************************/


#ifndef USBSERIAL_H
#define USBSERIAL_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <QtGlobal>
#include "MessageInterface.h"
#include <QMutex>
#include <QMainWindow>

//Windows-only
#ifdef Q_WS_WIN

#define _UNICODE
#if (WINVER != 0x0501) // Hacky business for MinGW...this needs to be set BEFORE including windows.h
#define WINVER 0x0501
#endif

#include <windows.h>
#include <tchar.h>

#define OVERLAPPED_HANDLES 2

#endif  //Windows defines/includes 

//Mac only
#ifdef Q_WS_MAC

#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <paths.h>
#include <sysexits.h>
#include <sys/param.h>
#include <sys/select.h>
#include <sys/time.h>
#include <time.h>
#include <AvailabilityMacros.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/serial/IOSerialKeys.h>
#include <CoreFoundation/CFNumber.h>
#include <IOKit/usb/IOUSBLib.h>
#include <IOKit/IOBSD.h>
#include <IOKit/IOMessage.h>

typedef const char cchar;
#endif

class UsbSerial
{									
	public:
	  enum UsbStatus { OK, ALREADY_OPEN=-1, NOT_OPEN=-2, NOTHING_AVAILABLE=-3, IO_ERROR=-4, UNKNOWN_ERROR=-5, 
											GOT_CHAR=-6, ALLOC_ERROR=-7, ERROR_CLOSE=-8 };
		UsbSerial( );
		
		UsbStatus usbOpen( );
		void usbClose( );
		int usbRead( char* buffer, int length );
		UsbStatus usbWrite( char* buffer, int length );
		UsbStatus usbWriteChar( char c );
		int numberOfAvailableBytes( );
		#ifdef Q_WS_WIN
		HANDLE deviceHandle;
		#endif
		UsbStatus setportName( char* filePath );
		
	protected:
		bool deviceOpen;
		bool readInProgress;
		QMutex usbOpenMutex;
	  char portName[1024];
		
	  MessageInterface* messageInterface;
	  QMainWindow* mainWindow;		
		
	private:
		//Windows only
		#ifdef Q_WS_WIN
		UsbStatus openDevice( TCHAR* deviceName );
		bool DoRegisterForNotification( );
		
		OVERLAPPED overlappedRead;
		char readBuffer[512];
		OVERLAPPED overlappedWrite;
		OVERLAPPED overlappedStatus;
		DWORD dwStoredFlags;
		HDEVNOTIFY notificationHandle;
		#endif
		
		//Mac only
		#ifdef Q_WS_MAC
		int deviceHandle;
		mach_port_t masterPort;
		bool foundMakeController;
		io_object_t usbDeviceReference;
		
		
		void createMatchingDictionary( );
		#endif	
};

#endif // USBSERIAL_H






See more files for this project here

Make Controller

The Make Controller is an open microcontroller platform for Makers of all kinds, by MakingThings. This project maintains the official firmware for the board and source for the software tools used with the board.

Project homepage: http://sourceforge.net/projects/makingthings
Programming language(s): C,C#,C++
License: other

  layouts/
    mchelper.ui
    mchelperPrefs.ui
  linux_driver/
    Makefile
    at91.c
    at91.mod.c
  Board.cpp
  Board.h
  BoardArrivalEvent.h
  IconPackageOSX.icns
  McHelperWindow.cpp
  McHelperWindow.h
  MessageEvent.cpp
  MessageEvent.h
  MessageInterface.h
  MonitorInterface.h
  NetworkMonitor.cpp
  NetworkMonitor.h
  Osc.cpp
  Osc.h
  OscXmlServer.cpp
  OscXmlServer.h
  OutputWindow.cpp
  OutputWindow.h
  PacketInterface.h
  PacketReadyInterface.h
  PacketUdp.cpp
  PacketUdp.h
  PacketUsbCdc.cpp
  PacketUsbCdc.h
  ReadMe.rtf
  Samba.cpp
  Samba.h
  SambaMonitor.cpp
  SambaMonitor.h
  UploaderThread.cpp
  UploaderThread.h
  UsbMonitor.cpp
  UsbMonitor.h
  UsbSerial.cpp
  UsbSerial.h
  guid829.h
  loader256_data.h
  main.cpp
  mchelper.pro
  mchelper.qrc
  mchelper.rc
  mchelper_icon.ico
  mticon128.png