public ScpiIOResult Open(string visaAddress, bool exclusiveLock) { if (instrument != Visa.VI_NULL) { throw new Exception("IO is already open"); } var res2 = Visa.viOpenDefaultRM(out rm); if (res2 < 0) { return(MakeError(res2)); } var res = Visa.viOpen(ScpiInstrument.GetResourceManager(), visaAddress, exclusiveLock ? Visa.VI_EXCLUSIVE_LOCK : Visa.VI_NO_LOCK, IOTimeoutMS, out instrument); // Use sensible defaults sendEnd = true; useTermChar = false; if (res >= 0) { SyncSettings(); } else { instrument = Visa.VI_NULL; } return(MakeError(res)); }
[System.Runtime.ExceptionServices.HandleProcessCorruptedStateExceptions] // Required by .NET to catch AccessViolationException. internal static int GetResourceManager() { try { if (visa_resource == Visa.VI_NULL && !visa_tried_load) { RaiseError2(Visa.viOpenDefaultRM(out visa_resource)); } } catch (Exception) { visa_tried_load = true; } return(visa_resource); }