Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在MonoTouch中使用Redpark SDK_C#_Xamarin.ios_External Accessory - Fatal编程技术网

C# 在MonoTouch中使用Redpark SDK

C# 在MonoTouch中使用Redpark SDK,c#,xamarin.ios,external-accessory,C#,Xamarin.ios,External Accessory,我正在尝试将MonoTouch与Redpark SDK结合使用,并在C#中复制一个用Objective-C编写的Redpark串行电缆示例程序(我能够在Xcode中完美运行): 我使用了此处找到的现有绑定: 并创建了一个用于我的项目的.dll。在我的项目中,在尝试编写之前,一切都进展顺利(我能够让cableConnected和cableDisconnected代理回调正常工作)。当我尝试使用Write功能时,程序会因SIGSEGV而崩溃: Stacktrace: at MonoTouch

我正在尝试将MonoTouch与Redpark SDK结合使用,并在C#中复制一个用Objective-C编写的Redpark串行电缆示例程序(我能够在Xcode中完美运行):

我使用了此处找到的现有绑定:

并创建了一个用于我的项目的.dll。在我的项目中,在尝试编写之前,一切都进展顺利(我能够让cableConnected和cableDisconnected代理回调正常工作)。当我尝试使用Write功能时,程序会因SIGSEGV而崩溃:

Stacktrace:

 at MonoTouch.RedPark.RscMgr.Write (int16,uint) <IL 0x00010, 0x00113>
  at tester2.tester2ViewController.toggleLED (MonoTouch.Foundation.NSObject) [0x00069] in /Users/salgarcia/Projects/tester2/tester2/tester2ViewController.cs:57
  at (wrapper runtime-invoke) object.runtime_invoke_dynamic (intptr,intptr,intptr,intptr) <0xffffffff>
  at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
  at tester2.Application.Main (string[]) [0x00000] in /Users/salgarcia/Projects/tester2/tester2/Main.cs:17
  at (wrapper runtime-invoke) object.runtime_invoke_dynamic (intptr,intptr,intptr,intptr) <0xffffffff>

Native stacktrace:

0   tester2                             0x001c2a25 mono_handle_native_sigsegv + 244
1   tester2                             0x001af065 mono_sigsegv_signal_handler + 172
2   libsystem_c.dylib                   0x329f17ed _sigtramp + 48
3   tester2                             0x00003a63 __inline_memcpy_chk + 30
4   tester2                             0x00003a63 __inline_memcpy_chk + 30
5   tester2                             0x00004011 -[RscMgr writeRscMessage:Length:MsgData:] + 220
6   tester2                             0x00004131 -[RscMgr write:Length:] + 100
7   tester2                             0x000438d8 wrapper_managed_to_native_ApiDefinition_Messaging_int_objc_msgSend_short_UInt32_intptr_intptr_int16_uint + 256
8   tester2                             0x001aa024 tester2_tester2ViewController_toggleLED_MonoTouch_Foundation_NSObject + 680
9   tester2                             0x000f76c0 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 200
10  tester2                             0x001b0843 mono_jit_runtime_invoke + 1054
11  tester2                             0x0022c40f mono_runtime_invoke + 90
12  tester2                             0x001ad14d native_to_managed_trampoline_tester2_tester2ViewController_toggleLED + 220
13  CoreFoundation                      0x3553f3fd -[NSObject performSelector:withObject:withObject:] + 52
14  UIKit                               0x33034e07 -[UIApplication sendAction:to:from:forEvent:] + 62
15  UIKit                               0x33034dc3 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 30
16  UIKit                               0x33034da1 -[UIControl sendAction:to:forEvent:] + 44
17  UIKit                               0x33034b11 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 492
18  Foundation                          0x350ff933 __NSFireDelayedPerform + 414
19  CoreFoundation                      0x355b9a33 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 14
20  CoreFoundation                      0x355b9699 __CFRunLoopDoTimer + 364
21  CoreFoundation                      0x355b826f __CFRunLoopRun + 1206
22  CoreFoundation                      0x3553b4a5 CFRunLoopRunSpecific + 300
23  CoreFoundation                      0x3553b36d CFRunLoopRunInMode + 104
24  GraphicsServices                    0x371d7439 GSEventRunModal + 136
25  UIKit                               0x33047cd5 UIApplicationMain + 1080
26  tester2                             0x0001fcc4 wrapper_managed_to_native_MonoTouch_UIKit_UIApplication_UIApplicationMain_int_string___intptr_intptr + 240
27  tester2                             0x001a9744 tester2_Application_Main_string__ + 152
28  tester2                             0x000f76c0 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 200
29  tester2                             0x001b0843 mono_jit_runtime_invoke + 1054
30  tester2                             0x0022c40f mono_runtime_invoke + 90
31  tester2                             0x0022f123 mono_runtime_exec_main + 306
32  tester2                             0x00232a4f mono_runtime_run_main + 482
33  tester2                             0x001b529f mono_jit_exec + 94
34  tester2                             0x00271c70 main + 2216
35  tester2                             0x00004860 start + 40

=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================
我的C#/MonoTouch实现

using System;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.RedPark;

namespace tester2
{
    public partial class tester2ViewController : UIViewController
    {
        static RscMgr rscMgr;
        MyRedparkDelegate delegate1;

        short[] rxbuffer = new short[1024];
        short[] txbuffer = new short[1024];

        public tester2ViewController () : base ("tester2ViewController", null)
        {
        }

        public override void DidReceiveMemoryWarning ()
        {
            base.DidReceiveMemoryWarning ();
        }

        public override void ViewDidLoad ()
        {
            base.ViewDidLoad ();
            rscMgr = new RscMgr();
            delegate1 = new MyRedparkDelegate ();
            rscMgr.SetDelegate(delegate1);
        }

        public override void ViewDidUnload ()
        {
            base.ViewDidUnload ();
            ReleaseDesignerOutlets ();
        }

        public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
        {
            return (toInterfaceOrientation != UIInterfaceOrientation.PortraitUpsideDown);
        }

        partial void toggleLED (NSObject sender)
        {
            if(toggleSwitch.On) {
                txbuffer[0] = (int) '1';
            } else {
                txbuffer[0] = (int) '0';
            }
            rscMgr.Write (txbuffer[0], 1);
        }

        public class MyRedparkDelegate : RscMgrDelegate
        {
            public MyRedparkDelegate ()
            {
            }
            public override void CableConnected (string protocol)
            {
                rscMgr.SetBaud (9600);
                rscMgr.Open ();
            }
            public override void CableDisconnected ()
            {
            }
            public override void PortStatusChanged ()
            {
            }
            public override void ReadBytesAvailable (uint length)
            {
            }
        }
    }
}

这个问题在我的MonoTouch实现代码中得到了解决,我发现我需要通过引用来传递正在编写的数据,所以我将上面代码中的写入更改为

     rscMgr.Write(ref txbuffer[0],1);

这一切都如期而至。它有助于彻底阅读SDK下载附带的Redpark串行电缆SDK用户指南。

问题在我的MonoTouch实现代码中得到了解决,我发现我需要通过引用传递正在编写的数据,因此我将上面代码中的写入改为

     rscMgr.Write(ref txbuffer[0],1);

这一切都如期而至。它有助于彻底阅读SDK下载附带的Redpark串行电缆SDK用户指南。

您需要发布
RscMgr
的Obj-C头文件,以便有人帮助您完成此操作。我认为这需要特殊的硬件来测试?@miguel.de.icaza好的,这就是Redpark串行电缆的具体问题,但最终,只有一个配备串行通信的设备(我只是在这个示例项目中使用了一个基本的arduino),您需要为
RscMgr
发布Obj-C头文件,以便有人来帮助您。我认为这需要特殊的硬件来测试?@miguel.de.icaza这个特定问题只需要redpark串行电缆,但最终只是一个配备串行通信的设备(我只是在这个示例项目中使用一个基本的arduino)
using System;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.RedPark;

namespace tester2
{
    public partial class tester2ViewController : UIViewController
    {
        static RscMgr rscMgr;
        MyRedparkDelegate delegate1;

        short[] rxbuffer = new short[1024];
        short[] txbuffer = new short[1024];

        public tester2ViewController () : base ("tester2ViewController", null)
        {
        }

        public override void DidReceiveMemoryWarning ()
        {
            base.DidReceiveMemoryWarning ();
        }

        public override void ViewDidLoad ()
        {
            base.ViewDidLoad ();
            rscMgr = new RscMgr();
            delegate1 = new MyRedparkDelegate ();
            rscMgr.SetDelegate(delegate1);
        }

        public override void ViewDidUnload ()
        {
            base.ViewDidUnload ();
            ReleaseDesignerOutlets ();
        }

        public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
        {
            return (toInterfaceOrientation != UIInterfaceOrientation.PortraitUpsideDown);
        }

        partial void toggleLED (NSObject sender)
        {
            if(toggleSwitch.On) {
                txbuffer[0] = (int) '1';
            } else {
                txbuffer[0] = (int) '0';
            }
            rscMgr.Write (txbuffer[0], 1);
        }

        public class MyRedparkDelegate : RscMgrDelegate
        {
            public MyRedparkDelegate ()
            {
            }
            public override void CableConnected (string protocol)
            {
                rscMgr.SetBaud (9600);
                rscMgr.Open ();
            }
            public override void CableDisconnected ()
            {
            }
            public override void PortStatusChanged ()
            {
            }
            public override void ReadBytesAvailable (uint length)
            {
            }
        }
    }
}
     rscMgr.Write(ref txbuffer[0],1);