ExternalAccessory iOS上的Xamarin [英] ExternalAccessory on iOS at Xamarin

查看:730
本文介绍了ExternalAccessory iOS上的Xamarin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人对如何使用API​​ ExternalAccessory上Xamarin.iOS线索?

我Xamarin Studio版本是4.0.12(建3),Xamarin.Android版本4.8.1,版本Xamarin.iOS和6.4.5.0 X code是5.0版(5A1413),我试图目标既和6.1 7.0的iPad / iPhone。

我已经走了互联网,并没有太多的文档。即使MonoTouch的文档已经打破链接。

我要的是,列出连接的蓝牙设备,获得再一个名称,然后连接到它,所以我可以打开一个套接字,并开始发送数据给它什么。它是采用串行通信和设备,是的,它拥有苹果外部附件协议ID。

我试过这样:

  VAR AM = EAAccessoryManager.SharedAccessoryManager;

这只是我抛出一个异常的InvaidCastException。

任何线索?

谢谢!我真的AP preciate的帮助。

PS:Xamarin详情

  Xamarin工作室
版本4.0.12(建设3)
安装UUID:7348d641-ed6d-4c8a-b59a-116674e06dfd
运行:
    单3.2.0((无/ 7c7fcc7)
    GTK 20年2月24日
    GTK#(2.12.0.0)
    包版本:3.02亿[...]苹果开发工具
X $ C $Ç5.0(3332.25)
构建5A1413[...]Xamarin.iOS
版本:6.4.5.0(试行版)
哈希:1336a36
科:
建立时间:2013年10月9日11:14:45-0400构建信息
发行编号:400120003
Git的版本:593d7acb1cb78ceeeb482d5133cf1fe514467e39
建立时间:2013年8月7日20:30:53 + 0000
Xamarin加载项:25a0858b281923e666b09259ad4746b774e0a873操作系统
的Mac OS X 10.8.5
达尔文Gutembergs-的MacBook-Pro.local 12.5.0 Darwin内核版本12.5.0
    周一07月29日16时33分49秒PDT 2013
    根:XNU-2050.48.11〜1 / RELEASE_X86_64 x86_64的


解决方案

虽然好像你已经工作了这一点,我想我会表现出一定的code段,介绍基本知识(在这种情况下连接到一个SPHERO并把它绿色):

  EAAccessoryManager经理= EAAccessoryManager.SharedAccessoryManager;
VAR配件= mgr.ConnectedAccessories;
的foreach(在附件VAR附件)
{
    myLabel.Text =它让我的附件;
    Console.WriteLine(accessory.ToString());
    Console.WriteLine(accessory.Name);
    VAR协议=com.orbotix.robotprotocol;    如果(accessory.ProtocolStrings.Where(S =&GT氏==协议)。任何())
    {
        myLabel.Text =找了份SPHERO        VAR会话=新EASession(附件,协议);
        VAR的OutputStream = session.OutputStream;
        outputStream.Delegate =新MyOutputStreamDelegate(myLabel);
        outputStream.Schedule(NSRunLoop.CurrentkCFRunLoopDefaultMode);
        outputStream.Open();
    }
}

 公共类MyOutputStreamDelegate:NSStreamDelegate
{
    标签的UILabel;
    布尔hasWritten = FALSE;    公共MyOutputStreamDelegate(标签的UILabel)
    {
        this.label =标签;
    }
    公共覆盖无效的handleEvent(NSStream theStream,NSStreamEvent streamEvent)
    {
        如果(streamEvent == NSStreamEvent.HasSpaceAvailable&放大器;&安培;!hasWritten)
        {
            //设置SPHERO的颜色
            VAR书面=((NSOutputStream)theStream).WRITE(新的byte [] {为0xFF,0xFF的,0X02,为0x20,0x0E的为0x05,0x1F的,为0xFF,0x1B,为0x00,0x91的信息},11);
            如果(书面== 11)
            {
                label.Text =SPHERO应该是绿色的;
            }
            hasWritten = TRUE;
        }
    }
}

Anybody has a clue on how to use the ExternalAccessory API on Xamarin.iOS?

My Xamarin Studio version is 4.0.12(build 3), Xamarin.Android version 4.8.1, Xamarin.iOS version 6.4.5.0 and Xcode is Version 5.0 (5A1413) and I tried target both 6.1 and 7.0 iPad/iPhone.

I've walked the internet and there is not much documentation. Even the MonoTouch docs have broken links.

What I want is, list the connected bluetooth devices, get one of then by name and then connect to it so I can open a socket and start sending data to it. It is a device that uses Serial communication and yes, it has the Apple external accessory protocol ID.

I've tried this:

var am = EAAccessoryManager.SharedAccessoryManager;

It just throws me an exception an InvaidCastException.

Any clues?

Thanks! I really appreciate the help.

PS: Xamarin Details

Xamarin Studio
Version 4.0.12 (build 3)
Installation UUID: 7348d641-ed6d-4c8a-b59a-116674e06dfd
Runtime:
    Mono 3.2.0 ((no/7c7fcc7)
    GTK 2.24.20
    GTK# (2.12.0.0)
    Package version: 302000000

[...]

Apple Developer Tools
Xcode 5.0 (3332.25)
Build 5A1413

[...]

Xamarin.iOS
Version: 6.4.5.0 (Trial Edition)
Hash: 1336a36
Branch: 
Build date: 2013-10-09 11:14:45-0400

Build Information
Release ID: 400120003
Git revision: 593d7acb1cb78ceeeb482d5133cf1fe514467e39
Build date: 2013-08-07 20:30:53+0000
Xamarin addins: 25a0858b281923e666b09259ad4746b774e0a873

Operating System
Mac OS X 10.8.5
Darwin Gutembergs-MacBook-Pro.local 12.5.0 Darwin Kernel Version 12.5.0
    Mon Jul 29 16:33:49 PDT 2013
    root:xnu-2050.48.11~1/RELEASE_X86_64 x86_64

解决方案

Although it seems like you've worked this out, I thought I'd show some code snippets that show the basics (in this case connecting to a Sphero and turning it green):

EAAccessoryManager mgr = EAAccessoryManager.SharedAccessoryManager;
var accessories = mgr.ConnectedAccessories;
foreach(var accessory in accessories)
{
    myLabel.Text = "Got me an accessory";
    Console.WriteLine(accessory.ToString());
    Console.WriteLine(accessory.Name);
    var protocol = "com.orbotix.robotprotocol";

    if(accessory.ProtocolStrings.Where(s => s == protocol).Any())
    {
        myLabel.Text = "Got me a Sphero";

        var session = new EASession(accessory, protocol);
        var outputStream = session.OutputStream;
        outputStream.Delegate = new MyOutputStreamDelegate(myLabel);
        outputStream.Schedule(NSRunLoop.Current, "kCFRunLoopDefaultMode");
        outputStream.Open();
    }
}

and

public class MyOutputStreamDelegate : NSStreamDelegate
{
    UILabel label;
    bool hasWritten = false;

    public MyOutputStreamDelegate(UILabel label)
    {
        this.label = label;
    }
    public override void HandleEvent(NSStream theStream, NSStreamEvent streamEvent)
    {
        if(streamEvent == NSStreamEvent.HasSpaceAvailable && ! hasWritten)
        {
            //Set the color of the Sphero
            var written = ((NSOutputStream)theStream).Write(new byte[] {0xFF, 0xFF, 0x02, 0x20, 0x0e, 0x05, 0x1F, 0xFF, 0x1B, 0x00, 0x91}, 11);
            if(written == 11)
            {
                label.Text = "Sphero should be green";
            }
            hasWritten = true;
        }
    }
}

这篇关于ExternalAccessory iOS上的Xamarin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆