private void onMessage(iMonNativeApi.iMonDisplayNotifyCode code, IntPtr data)
        {
            this.OnLog("Message received: " + code + "(" + data + ")");

            switch (code)
            {
                case iMonNativeApi.iMonDisplayNotifyCode.PluginSuccess:
                case iMonNativeApi.iMonDisplayNotifyCode.HardwareConnected:
                case iMonNativeApi.iMonDisplayNotifyCode.iMonRestarted:
                    this.displayType = (iMonDisplayType)data;
                    this.onStateChanged(true);
                    break;

                case iMonNativeApi.iMonDisplayNotifyCode.PluginFailed:
                    this.onError(this.getErrorType((iMonNativeApi.iMonDisplayInitResult)data));
                    break;

                case iMonNativeApi.iMonDisplayNotifyCode.HardwareDisconnected:
                case iMonNativeApi.iMonDisplayNotifyCode.iMonClosed:
                    this.onError(this.getErrorType(code));
                    break;

                case iMonNativeApi.iMonDisplayNotifyCode.LCDTextScrollDone:
                    this.lcd.OnScrollFinished();
                    break;
            }
        }
        private iMonErrorType getErrorType(iMonNativeApi.iMonDisplayNotifyCode notifyCode)
        {
            this.OnLogError("Interpreting notify error type: " + notifyCode);

            switch (notifyCode)
            {
                case iMonNativeApi.iMonDisplayNotifyCode.PluginFailed:
                    return iMonErrorType.Unknown;

                case iMonNativeApi.iMonDisplayNotifyCode.iMonClosed:
                    return iMonErrorType.iMonClosed;

                case iMonNativeApi.iMonDisplayNotifyCode.HardwareDisconnected:
                    return iMonErrorType.HardwareDisconnected;
            }

            return iMonErrorType.Unknown;
        }
        private iMonErrorType getErrorType(iMonNativeApi.iMonDisplayInitResult code)
        {
            this.OnLogError("Interpreting init result error type: " + code);

            switch (code)
            {
                case iMonNativeApi.iMonDisplayInitResult.HardwareNotConnected:
                    return iMonErrorType.HardwareNotConnected;

                case iMonNativeApi.iMonDisplayInitResult.HardwareNotSupported:
                    return iMonErrorType.HardwareNotSupported;

                case iMonNativeApi.iMonDisplayInitResult.iMonNotResponding:
                    return iMonErrorType.iMonNotResponding;

                case iMonNativeApi.iMonDisplayInitResult.PluginModeAlreadyInUse:
                    return iMonErrorType.PluginModeAlreadyInUse;

                case iMonNativeApi.iMonDisplayInitResult.PluginModeDisabled:
                    return iMonErrorType.PluginModeDisabled;
            }

            return iMonErrorType.Unknown;
        }
        private iMonErrorType getErrorType(iMonNativeApi.iMonDisplayResult result)
        {
            this.OnLogError("Interpreting result error type: " + result);

            switch (result)
            {
                case iMonNativeApi.iMonDisplayResult.ApiNotInitialized:
                    return iMonErrorType.ApiNotInitialized;

                case iMonNativeApi.iMonDisplayResult.Failed:
                    return iMonErrorType.Unknown;

                case iMonNativeApi.iMonDisplayResult.InvalidArguments:
                    return iMonErrorType.InvalidArguments;

                case iMonNativeApi.iMonDisplayResult.InvalidPointer:
                    return iMonErrorType.InvalidPointer;

                case iMonNativeApi.iMonDisplayResult.NotInitialized:
                    return iMonErrorType.NotInitialized;

                case iMonNativeApi.iMonDisplayResult.NotInPluginMode:
                    return iMonErrorType.NotInPluginMode;

                case iMonNativeApi.iMonDisplayResult.OutOfMemory:
                    return iMonErrorType.OutOfMemory;
            }

            return iMonErrorType.Unknown;
        }