Skip to content

Commit

Permalink
progress with serial device monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
Arti3DPlayer committed Mar 9, 2018
1 parent 33f2f23 commit d3a0d50
Show file tree
Hide file tree
Showing 15 changed files with 1,400 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,7 @@

- Updated all projects to Switf 4
- Created Wiki documentation [here](https://github.com/Arti3DPlayer/USBDeviceSwift/wiki)
- Added Serial device support

## 1.0.2
- Explicitly set Swift version project-wide
Expand Down
5 changes: 4 additions & 1 deletion README.md
@@ -1,6 +1,6 @@
# USBDeviceSwift

**USBDeviceSwift** - is a wrapper for `IOKit.usb` and `IOKit.hid` written on pure Swift that allows you convenient work with USB devices.
**USBDeviceSwift** - is a wrapper for `IOKit.usb` and `IOKit.hid` and `IOKit.serial` written on pure Swift that allows you convenient work with USB devices.

<table>
<tr>
Expand All @@ -13,6 +13,9 @@
</tr>
</table>

Working with `IOKit.usb` and `IOKit.hid` and `IOKit.serial` on Swift is a pain. A lot of not converted C code, pointers make your life harder.
This library provides basic connect/disconnect events, converted functions to send and receive requests and examples.

## Getting Started

### Requirements
Expand Down
335 changes: 335 additions & 0 deletions SerialDeviceSwift/SerialDeviceSwift.xcodeproj/project.pbxproj
@@ -0,0 +1,335 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 48;
objects = {

/* Begin PBXBuildFile section */
3F8A57A1205287F500E5BD99 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F8A57A0205287F500E5BD99 /* AppDelegate.swift */; };
3F8A57A3205287F500E5BD99 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F8A57A2205287F500E5BD99 /* ViewController.swift */; };
3F8A57A5205287F500E5BD99 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3F8A57A4205287F500E5BD99 /* Assets.xcassets */; };
3F8A57A8205287F500E5BD99 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3F8A57A6205287F500E5BD99 /* Main.storyboard */; };
3F8A57B120528AF300E5BD99 /* USBDeviceSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3F8A57B220528AF300E5BD99 /* USBDeviceSwift.framework */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
3F8A579D205287F500E5BD99 /* SerialDeviceSwift.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SerialDeviceSwift.app; sourceTree = BUILT_PRODUCTS_DIR; };
3F8A57A0205287F500E5BD99 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
3F8A57A2205287F500E5BD99 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
3F8A57A4205287F500E5BD99 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
3F8A57A7205287F500E5BD99 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
3F8A57A9205287F500E5BD99 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3F8A57AA205287F500E5BD99 /* SerialDeviceSwift.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = SerialDeviceSwift.entitlements; sourceTree = "<group>"; };
3F8A57B220528AF300E5BD99 /* USBDeviceSwift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = USBDeviceSwift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
3F8A579A205287F500E5BD99 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
3F8A57B120528AF300E5BD99 /* USBDeviceSwift.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
3F8A5794205287F500E5BD99 = {
isa = PBXGroup;
children = (
3F8A579F205287F500E5BD99 /* SerialDeviceSwift */,
3F8A579E205287F500E5BD99 /* Products */,
3F8A57B020528AF300E5BD99 /* Frameworks */,
);
sourceTree = "<group>";
};
3F8A579E205287F500E5BD99 /* Products */ = {
isa = PBXGroup;
children = (
3F8A579D205287F500E5BD99 /* SerialDeviceSwift.app */,
);
name = Products;
sourceTree = "<group>";
};
3F8A579F205287F500E5BD99 /* SerialDeviceSwift */ = {
isa = PBXGroup;
children = (
3F8A57A0205287F500E5BD99 /* AppDelegate.swift */,
3F8A57A2205287F500E5BD99 /* ViewController.swift */,
3F8A57A4205287F500E5BD99 /* Assets.xcassets */,
3F8A57A6205287F500E5BD99 /* Main.storyboard */,
3F8A57A9205287F500E5BD99 /* Info.plist */,
3F8A57AA205287F500E5BD99 /* SerialDeviceSwift.entitlements */,
);
path = SerialDeviceSwift;
sourceTree = "<group>";
};
3F8A57B020528AF300E5BD99 /* Frameworks */ = {
isa = PBXGroup;
children = (
3F8A57B220528AF300E5BD99 /* USBDeviceSwift.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
3F8A579C205287F500E5BD99 /* SerialDeviceSwift */ = {
isa = PBXNativeTarget;
buildConfigurationList = 3F8A57AD205287F500E5BD99 /* Build configuration list for PBXNativeTarget "SerialDeviceSwift" */;
buildPhases = (
3F8A5799205287F500E5BD99 /* Sources */,
3F8A579A205287F500E5BD99 /* Frameworks */,
3F8A579B205287F500E5BD99 /* Resources */,
);
buildRules = (
);
dependencies = (
);
name = SerialDeviceSwift;
productName = SerialDeviceSwift;
productReference = 3F8A579D205287F500E5BD99 /* SerialDeviceSwift.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */

/* Begin PBXProject section */
3F8A5795205287F500E5BD99 /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 0920;
ORGANIZATIONNAME = "Artem Hruzd";
TargetAttributes = {
3F8A579C205287F500E5BD99 = {
CreatedOnToolsVersion = 9.2;
ProvisioningStyle = Automatic;
SystemCapabilities = {
com.apple.Sandbox = {
enabled = 1;
};
};
};
};
};
buildConfigurationList = 3F8A5798205287F500E5BD99 /* Build configuration list for PBXProject "SerialDeviceSwift" */;
compatibilityVersion = "Xcode 8.0";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = 3F8A5794205287F500E5BD99;
productRefGroup = 3F8A579E205287F500E5BD99 /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
3F8A579C205287F500E5BD99 /* SerialDeviceSwift */,
);
};
/* End PBXProject section */

/* Begin PBXResourcesBuildPhase section */
3F8A579B205287F500E5BD99 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
3F8A57A5205287F500E5BD99 /* Assets.xcassets in Resources */,
3F8A57A8205287F500E5BD99 /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
3F8A5799205287F500E5BD99 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
3F8A57A3205287F500E5BD99 /* ViewController.swift in Sources */,
3F8A57A1205287F500E5BD99 /* AppDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */

/* Begin PBXVariantGroup section */
3F8A57A6205287F500E5BD99 /* Main.storyboard */ = {
isa = PBXVariantGroup;
children = (
3F8A57A7205287F500E5BD99 /* Base */,
);
name = Main.storyboard;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */

/* Begin XCBuildConfiguration section */
3F8A57AB205287F500E5BD99 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "Mac Developer";
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Debug;
};
3F8A57AC205287F500E5BD99 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "Mac Developer";
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
};
name = Release;
};
3F8A57AE205287F500E5BD99 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = SerialDeviceSwift/SerialDeviceSwift.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = LGTF372X5G;
INFOPLIST_FILE = SerialDeviceSwift/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = ah.com.SerialDeviceSwift;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
};
name = Debug;
};
3F8A57AF205287F500E5BD99 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = SerialDeviceSwift/SerialDeviceSwift.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = LGTF372X5G;
INFOPLIST_FILE = SerialDeviceSwift/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = ah.com.SerialDeviceSwift;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
};
name = Release;
};
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
3F8A5798205287F500E5BD99 /* Build configuration list for PBXProject "SerialDeviceSwift" */ = {
isa = XCConfigurationList;
buildConfigurations = (
3F8A57AB205287F500E5BD99 /* Debug */,
3F8A57AC205287F500E5BD99 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
3F8A57AD205287F500E5BD99 /* Build configuration list for PBXNativeTarget "SerialDeviceSwift" */ = {
isa = XCConfigurationList;
buildConfigurations = (
3F8A57AE205287F500E5BD99 /* Debug */,
3F8A57AF205287F500E5BD99 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 3F8A5795205287F500E5BD99 /* Project object */;
}
30 changes: 30 additions & 0 deletions SerialDeviceSwift/SerialDeviceSwift/AppDelegate.swift
@@ -0,0 +1,30 @@
//
// AppDelegate.swift
// SerialDeviceSwift
//
// Created by Artem Hruzd on 3/9/18.
// Copyright © 2018 Artem Hruzd. All rights reserved.
//

import Cocoa
import USBDeviceSwift

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
//make sure that cfDeviceMonitor always exist
let cfDeviceMonitor = SerialDeviceMonitor()

func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application

let cfDeviceDaemon = Thread(target: self.cfDeviceMonitor, selector:#selector(self.cfDeviceMonitor.start), object: nil)
cfDeviceDaemon.start()
}

func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
}


}

0 comments on commit d3a0d50

Please sign in to comment.