1

我正在尝试实现 IDtech Unimag 读卡器。我已经获得了 UniMag 本机代码的 c# 绑定库。为了创建我在给定代码下面编写的 unimag 对象。

_uniMagReader = new uniMag ();
//_uniMagReader.ReaderType = BrushfireUniMagBinding.UmReader.Shuttle;
_uniMagReader.SetAutoAdjustVolume(true);
_uniMagReader.SetSwipeTimeoutDuration (0);
_uniMagReader.SetAutoAdjustVolume (true);
_uniMagReader.StartUniMag (true);

在第三行,_uniMagReader.SetAutoAdjustVolume(true)我得到了这个例外:

Foundation.You_Should_Not_Call_base_In_This_Method:“Foundation.You_Should_Not_Call_base_In_This_Method”类型的异常。

我不知道为什么会收到此异常。我搜索了相同的异常,但我没有得到答案的实际含义。

我的 Unimag 转换文件如下所示:

using Foundation;
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace BrushfireUniMagBinding
{
    [Model, Register ("uniMag", false)]
    public class uniMag : NSObject
    {
        //
        // Properties
        //
        [CompilerGenerated]
        public virtual UmReader ReaderType {
            [Export ("readerType")]
            get;
            [Export ("setReaderType:")]
            set;
        }

        //
        // Constructors
        //
        [Export ("init"), EditorBrowsable (EditorBrowsableState.Advanced), CompilerGenerated]
        public uniMag ();

        [EditorBrowsable (EditorBrowsableState.Advanced), CompilerGenerated]
        protected uniMag (NSObjectFlag t);

        //
        // Static Methods
        //
        [Export ("enableLogging:"), CompilerGenerated]
        public static void EnableLogging (bool enable);

        [Export ("SDK_version"), CompilerGenerated]
        public static string SDK_version ();

        //
        // Methods
        //
        [Export ("autoDetect:"), CompilerGenerated]
        public virtual void AutoDetect (bool autoDetect);

        [Export ("cancelSwipe"), CompilerGenerated]
        public virtual void CancelSwipe ();

        [Export ("cancelTask"), CompilerGenerated]
        public virtual void CancelTask ();

        [Export ("closeConnection"), CompilerGenerated]
        public virtual void CloseConnection ();

        [Export ("getAuthentication"), CompilerGenerated]
        public virtual UmRet GetAuthentication ();

        [Export ("getConnectionStatus"), CompilerGenerated]
        public virtual bool GetConnectionStatus ();

        [Export ("getFlagByte"), CompilerGenerated]
        public virtual NSData GetFlagByte ();

        [Export ("getRunningTask"), CompilerGenerated]
        public virtual UmTask GetRunningTask ();

        [Export ("getVolumeLevel"), CompilerGenerated]
        public virtual float GetVolumeLevel ();

        [Export ("getWave"), CompilerGenerated]
        public virtual NSData GetWave ();

        [Export ("isReaderAttached"), CompilerGenerated]
        public virtual bool IsReaderAttached ();

        [Export ("proceedPoweringUp:"), CompilerGenerated]
        public virtual UmRet ProceedPoweringUp (bool proceedPowerUp);

        [Export ("promptForConnection:"), CompilerGenerated]
        public virtual void PromptForConnection (bool prompt);

        [Export ("requestSwipe"), CompilerGenerated]
        public virtual UmRet RequestSwipe ();

        [Export ("sendCommandClearBuffer"), CompilerGenerated]
        public virtual UmRet SendCommandClearBuffer ();

        [Export ("sendCommandCustom:"), CompilerGenerated]
        public virtual UmRet SendCommandCustom (NSData cmd);

        [Export ("sendCommandDefaultGeneralSettings"), CompilerGenerated]
        public virtual UmRet SendCommandDefaultGeneralSettings ();

        [Export ("sendCommandDisableErrNotification"), CompilerGenerated]
        public virtual UmRet SendCommandDisableErrNotification ();

        [Export ("sendCommandDisableExpDate"), CompilerGenerated]
        public virtual UmRet SendCommandDisableExpDate ();

        [Export ("sendCommandDisableForceEncryption"), CompilerGenerated]
        public virtual UmRet SendCommandDisableForceEncryption ();

        [Export ("sendCommandEnableAES"), CompilerGenerated]
        public virtual UmRet SendCommandEnableAES ();

        [Export ("sendCommandEnableErrNotification"), CompilerGenerated]
        public virtual UmRet SendCommandEnableErrNotification ();

        [Export ("sendCommandEnableExpDate"), CompilerGenerated]
        public virtual UmRet SendCommandEnableExpDate ();

        [Export ("sendCommandEnableForceEncryption"), CompilerGenerated]
        public virtual UmRet SendCommandEnableForceEncryption ();

        [Export ("sendCommandEnableTDES"), CompilerGenerated]
        public virtual UmRet SendCommandEnableTDES ();

        [Export ("sendCommandGetNextKSN"), CompilerGenerated]
        public virtual UmRet SendCommandGetNextKSN ();

        [Export ("sendCommandGetSerialNumber"), CompilerGenerated]
        public virtual UmRet SendCommandGetSerialNumber ();

        [Export ("sendCommandGetSettings"), CompilerGenerated]
        public virtual UmRet SendCommandGetSettings ();

        [Export ("sendCommandGetVersion"), CompilerGenerated]
        public virtual UmRet SendCommandGetVersion ();

        [Export ("sendCommandResetBaudRate"), CompilerGenerated]
        public virtual UmRet SendCommandResetBaudRate ();

        [Export ("sendCommandSetPrePAN:"), CompilerGenerated]
        public virtual UmRet SendCommandSetPrePAN (int prePAN);

        [Export ("setAutoAdjustVolume:"), CompilerGenerated]
        public virtual void SetAutoAdjustVolume (bool b);

        [Export ("setAutoConnect:"), CompilerGenerated]
        public virtual void SetAutoConnect (bool autoConnect);

        [Export ("setCmdTimeoutDuration:"), CompilerGenerated]
        public virtual bool SetCmdTimeoutDuration (int seconds);

        [Export ("setDeferredActivateAudioSession:"), CompilerGenerated]
        public virtual void SetDeferredActivateAudioSession (bool b);

        [Export ("setFirmwareFile:"), CompilerGenerated]
        public virtual bool SetFirmwareFile (string location);

        [Export ("setSwipeTimeoutDuration:"), CompilerGenerated]
        public virtual bool SetSwipeTimeoutDuration (int seconds);

        [Export ("setWavePath:"), CompilerGenerated]
        public virtual bool SetWavePath (string path);

        [Export ("startUniMag:"), CompilerGenerated]
        public virtual UmRet StartUniMag (bool start);

        [Export ("updateFirmware:"), CompilerGenerated]
        public virtual UmRet UpdateFirmware (string encrytedBytes);

        [Export ("updateFirmware2:stringWithFile:"), CompilerGenerated]
        public virtual UmRet UpdateFirmware2 (string stringWithFile, string path);
    }
}

任何人都可以在这种情况下指导我吗?

提前致谢。

4

1 回答 1

0

所以异常You_Should_Not_Call_base_In_This_Method意味着该方法正在调用绑定库中它的父方法中的SetAutoAdjustVolume(bool)东西。Base.SetAutoAdjustVolume(bool)

您可能需要重写该SetAutoAdjustVolume(bool)方法以确保它没有调用Base.

[Export ("setAutoAdjustVolume:"), CompilerGenerated]
public virtual void SetAutoAdjustVolume (bool b);

本质上,编译器生成的绑定到此方法需要被覆盖,然后才能在代码中使用它。

例如,您可以创建一个派生自uniMag并覆盖该SetAutoAdjustVolume方法的新类,以确保base不调用该方法。

于 2018-05-04T09:38:08.080 回答