From cdd5ee4e41f7f20253396025267792705d0b47ec Mon Sep 17 00:00:00 2001 From: Colm Ryan Date: Mon, 22 Jun 2015 09:23:56 -0400 Subject: [PATCH] :arrow_up: update Labbrick header to 64bit version Also change GetModelName to char* version as 64 bit supports both char* and wchar_t*. --- common/+deviceDrivers/@Labbrick/Labbrick.m | 74 +++++------ common/+deviceDrivers/@Labbrick/vnx_LMS_api.h | 112 ++++++++++++++++ common/+deviceDrivers/@Labbrick/vnx_fmsynth.h | 124 ------------------ 3 files changed, 149 insertions(+), 161 deletions(-) create mode 100644 common/+deviceDrivers/@Labbrick/vnx_LMS_api.h delete mode 100644 common/+deviceDrivers/@Labbrick/vnx_fmsynth.h diff --git a/common/+deviceDrivers/@Labbrick/Labbrick.m b/common/+deviceDrivers/@Labbrick/Labbrick.m index 15dc4394..383788a6 100644 --- a/common/+deviceDrivers/@Labbrick/Labbrick.m +++ b/common/+deviceDrivers/@Labbrick/Labbrick.m @@ -22,8 +22,8 @@ MAX_DEVICES = 64; MAX_RETRIES = 3; end % end constant properties - - + + % Class-specific private properties properties (Access = private) devID; @@ -35,7 +35,7 @@ max_freq = 10; % GHz min_freq = 5; % GHz pulseModeEnabled = 0; - + % status codes from vnx_fmssynth.h STATUS_INVALID_DEVID = hex2dec('80000000') % MSB is set if the device ID is invalid STATUS_DEV_CONNECTED = hex2dec('00000001') % LSB is set if a device is connected @@ -47,7 +47,7 @@ STATUS_PLL_LOCKED = hex2dec('00000040') % set if the PLL lock status is TRUE (both PLL's are locked) STATUS_FAST_PULSE_OPTION = hex2dec('00000080') % set if the fast pulse mode option is installed end % end private properties - + % Device properties correspond to instrument parameters properties (Access = public) output @@ -58,13 +58,13 @@ alc pulse pulseSource = 'ext'; - + pllLocked; - + % device specific refSource end % end device properties - + methods %Constructor function obj = Labbrick() @@ -72,7 +72,7 @@ % build library path path = [fileparts(mfilename('fullpath')) filesep]; if ~libisloaded('vnx_fmsynth') - loadlibrary([path 'vnx_fmsynth.dll'], [path 'vnx_fmsynth.h']); + loadlibrary([path 'vnx_fmsynth.dll'], [path 'vnx_LMS_api.h']); calllib('vnx_fmsynth', 'fnLMS_SetTestMode', false); end end @@ -83,14 +83,14 @@ function delete(obj) obj.disconnect(); end end - + % open the connection to the Labbrick with the given serial number function connect(obj, serial) if ~isnumeric(serial) serial = str2double(serial); end obj.serialNum = serial; - + % find the devID of the Labbrick with the given serial number [devIDs, serial_nums] = obj.enumerate(); obj.devID = devIDs(serial_nums == serial); @@ -101,7 +101,7 @@ function connect(obj, serial) if status ~= 0 error('Could not open device with id: %i, returned error %i', [obj.devID status]) end - + % populate some device properties obj.open = 1; obj.max_power = calllib('vnx_fmsynth', 'fnLMS_GetMaxPwr', obj.devID) / 4; @@ -109,7 +109,7 @@ function connect(obj, serial) obj.max_freq = calllib('vnx_fmsynth', 'fnLMS_GetMaxFreq', obj.devID) / 1e8; obj.min_freq = calllib('vnx_fmsynth', 'fnLMS_GetMinFreq', obj.devID) / 1e8; end - + function disconnect(obj) if obj.open status = calllib('vnx_fmsynth', 'fnLMS_CloseDevice', obj.devID); @@ -120,12 +120,12 @@ function disconnect(obj) obj.open = 0; end end - + function flag = get_dev_status(obj, status_code) val = calllib('vnx_fmsynth', 'fnLMS_GetDeviceStatus', obj.devID); flag = (bitand(val, status_code) == status_code); end - + % get a list of connected Labbricks % NB: There is a bug in the Labbrick DLL that causes % fnLMS_GetDevInfo to only return device IDs in order until it @@ -141,9 +141,9 @@ function disconnect(obj) if isempty(previous_num_devices) previous_num_devices = 0; end - + %num_devices = calllib('vnx_fmsynth','fnLMS_GetNumDevices'); - + %if (num_devices > previous_num_devices) || isempty(devIDs) if isempty(devIDs) num_devices = calllib('vnx_fmsynth','fnLMS_GetNumDevices'); @@ -160,13 +160,13 @@ function disconnect(obj) ids = devIDs; serials = serial_nums; end - + % get model name function name = model_name(obj) - [~, obj.model] = calllib('vnx_fmsynth', 'fnLMS_GetModelName', obj.devID, ' '); + [~, obj.model] = calllib('vnx_fmsynth', 'fnLMS_GetModelNameA', obj.devID, ' '); name = obj.model; end - + % Instrument parameter accessors % getters function val = get.frequency(obj) @@ -204,21 +204,21 @@ function disconnect(obj) %if val == true, val = 'ext'; end val = obj.pulseSource; end - + function val = get.refSource(obj) val = calllib('vnx_fmsynth', 'fnLMS_GetUseInternalRef', obj.devID); if val == true, val = 'int'; end if val == false, val = 'ext'; end end - + function val = get.pllLocked(obj) val = obj.get_dev_status(obj.STATUS_PLL_LOCKED); end - + % property setters function obj = set.frequency(obj, value) % value: frequency to set in GHz - + % error check that the frequency is within the bounds of % the device if value > obj.max_freq @@ -228,7 +228,7 @@ function disconnect(obj) value = obj.min_freq; warning('Frequency out of range'); end - + % write frequency in 10s of Hz calllib('vnx_fmsynth', 'fnLMS_SetFrequency', obj.devID, value*1e8); end @@ -241,7 +241,7 @@ function disconnect(obj) value = obj.min_power; warning('Power out of range'); end - + % write power as a multiple of 0.25dBm value = int32(value*4); %fprintf('Writing value %i\n', value); @@ -258,10 +258,10 @@ function disconnect(obj) function obj = set.mod(obj, ~) %not supported by hardware end - + function obj = set.pulse(obj, value) obj.pulseModeEnabled = obj.cast_boolean(value); - + switch obj.pulseSource case 'int' calllib('vnx_fmsynth', 'fnLMS_SetUseExternalPulseMod', obj.devID, false); @@ -273,7 +273,7 @@ function disconnect(obj) disp('Labbrick: Unknown pulse source'); end end - function obj = set.pulseSource(obj, value) + function obj = set.pulseSource(obj, value) % Validate input value = lower(value); checkMapObj = containers.Map({'int','internal','ext','external'},... @@ -286,12 +286,12 @@ function disconnect(obj) else obj.pulseSource = 'int'; end - + if obj.pulseModeEnabled obj.pulse = 1; % set the pulse parameter to update the device end end - + function obj = set.refSource(obj, value) % Validate input checkMapObj = containers.Map({'int','internal','ext','external'},... @@ -299,9 +299,9 @@ function disconnect(obj) if not (checkMapObj.isKey( lower(value) )) error('Invalid input'); end - + calllib('vnx_fmsynth', 'fnLMS_SetUseInternalRef', obj.devID, checkMapObj(lower(value))); - + if (strncmpi(value,'ext', 3) ) % test for PLL lock retries = 0; @@ -309,15 +309,15 @@ function disconnect(obj) retries = retries + 1; pause(0.5); end - if (~obj.pllLocked) + if (~obj.pllLocked) error('Labbrick PLL is not locked'); end end end end % end instrument parameter accessors - + methods (Static) - + %Helper function to cast boolean inputs to 'on'/'off' strings function out = cast_boolean(in) if isnumeric(in) @@ -333,7 +333,7 @@ function disconnect(obj) error('Unable to cast to boolean'); end end - + end - + end % end class definition diff --git a/common/+deviceDrivers/@Labbrick/vnx_LMS_api.h b/common/+deviceDrivers/@Labbrick/vnx_LMS_api.h new file mode 100644 index 00000000..9ee71e79 --- /dev/null +++ b/common/+deviceDrivers/@Labbrick/vnx_LMS_api.h @@ -0,0 +1,112 @@ +// Include file for 64 Bit Vaunix Lab Brick LMS Synthesizer DLL +// +// 10/2013 RD 64 Bit DLL version. +// + + +// The following ifdef block is the standard way of creating macros which make exporting +// from a DLL simpler. All files within this DLL are compiled with the VNX_FSYNSTH_EXPORTS +// symbol defined on the command line. this symbol should not be defined on any project +// that uses this DLL. This way any other project whose source files include this file see +// VNX_LMS_API functions as being imported from a DLL, wheras this DLL sees symbols +// defined with this macro as being exported. + +#ifdef VNX_FMSYNTH_EXPORTS +#define VNX_LMS_API __declspec(dllexport) +#else +#define VNX_LMS_API __declspec(dllimport) +#endif + +#ifdef __cplusplus +extern "C" { +#endif + + +// ----------- Global Equates ------------ +#define MAXDEVICES 64 +#define MAX_MODELNAME 32 + +// ----------- Data Types ---------------- +#define DEVID unsigned int + +// ----------- Mode Bit Masks ------------ +#define MODE_RFON 0x00000010 // bit is 1 for RF on, 0 if RF is off +#define MODE_INTREF 0x00000020 // bit is 1 for internal osc., 0 for external reference +#define MODE_SWEEP 0x0000000F // bottom 4 bits are used to keep the sweep control bits +#define MODE_PWMON 0x00000100 // we keep a copy of the PWM control bits here, 1 for int PWM on +#define MODE_EXTPWM 0x00000200 // 1 for ext. PWM input enabled +#define PWM_MASK 0x00000300 + +// ----------- Command Equates ----------- +// Status returns for commands +#define LVSTATUS int +#define STATUS_OK 0 +#define BAD_PARAMETER 0x80010000 // out of range input -- frequency outside min/max etc. +#define BAD_HID_IO 0x80020000 +#define DEVICE_NOT_READY 0x80030000 // device isn't open, no handle, etc. +#define F_INVALID_DEVID -1.0 // for functions that return a float +#define F_DEVICE_NOT_READY -3.0 + +// Status returns for DevStatus +#define INVALID_DEVID 0x80000000 // MSB is set if the device ID is invalid +#define DEV_CONNECTED 0x00000001 // LSB is set if a device is connected +#define DEV_OPENED 0x00000002 // set if the device is opened +#define SWP_ACTIVE 0x00000004 // set if the device is sweeping +#define SWP_UP 0x00000008 // set if the device is sweeping up in frequency +#define SWP_REPEAT 0x00000010 // set if the device is in continuous sweep mode +#define SWP_BIDIRECTIONAL 0x00000020 // set if the device is in bi-directional sweep mode +#define PLL_LOCKED 0x00000040 // set if the PLL lock status is TRUE (both PLL's are locked) +#define FAST_PULSE_OPTION 0x00000080 // set if the fast pulse mode option is installed + +// Flags to encode pulse mode time ranges +#define PM48Mhz 0x10000000 // used to select the 48Mhz pulse mod clock +#define PM1Mhz 0x00000000 // used to select the 1Mhz pulse mod clock or sw pulsing + +VNX_LMS_API void fnLMS_SetTestMode(bool testmode); +VNX_LMS_API int fnLMS_GetNumDevices(); +VNX_LMS_API int fnLMS_GetDevInfo(DEVID *ActiveDevices); +VNX_LMS_API int fnLMS_GetModelNameA(DEVID deviceID, char *ModelName); +VNX_LMS_API int fnLMS_GetModelNameW(DEVID deviceID, wchar_t *ModelName); +VNX_LMS_API int fnLMS_InitDevice(DEVID deviceID); +VNX_LMS_API int fnLMS_CloseDevice(DEVID deviceID); +VNX_LMS_API int fnLMS_GetSerialNumber(DEVID deviceID); +VNX_LMS_API int fnLMS_GetDLLVersion(); +VNX_LMS_API LVSTATUS fnLMS_SetFrequency(DEVID deviceID, int frequency); +VNX_LMS_API LVSTATUS fnLMS_SetStartFrequency(DEVID deviceID, int startfrequency); +VNX_LMS_API LVSTATUS fnLMS_SetEndFrequency(DEVID deviceID, int endfrequency); +VNX_LMS_API LVSTATUS fnLMS_SetSweepTime(DEVID deviceID, int sweeptime); +VNX_LMS_API LVSTATUS fnLMS_SetPowerLevel(DEVID deviceID, int powerlevel); +VNX_LMS_API LVSTATUS fnLMS_SetRFOn(DEVID deviceID, bool on); +VNX_LMS_API LVSTATUS fnLMS_SetPulseOnTime(DEVID deviceID, float pulseontime); +VNX_LMS_API LVSTATUS fnLMS_SetPulseOffTime(DEVID deviceID, float pulseofftime); +VNX_LMS_API LVSTATUS fnLMS_EnableInternalPulseMod(DEVID deviceID, bool on); +VNX_LMS_API LVSTATUS fnLMS_SetUseExternalPulseMod(DEVID deviceID, bool external); +VNX_LMS_API LVSTATUS fnLMS_SetFastPulsedOutput(DEVID deviceID, float pulseontime, float pulsereptime, bool on); +VNX_LMS_API LVSTATUS fnLMS_SetUseInternalRef(DEVID deviceID, bool internal); +VNX_LMS_API LVSTATUS fnLMS_SetSweepDirection(DEVID deviceID, bool up); +VNX_LMS_API LVSTATUS fnLMS_SetSweepMode(DEVID deviceID, bool mode); +VNX_LMS_API LVSTATUS fnLMS_SetSweepType(DEVID deviceID, bool swptype); +VNX_LMS_API LVSTATUS fnLMS_StartSweep(DEVID deviceID, bool go); +VNX_LMS_API LVSTATUS fnLMS_SaveSettings(DEVID deviceID); +VNX_LMS_API int fnLMS_GetFrequency(DEVID deviceID); +VNX_LMS_API int fnLMS_GetStartFrequency(DEVID deviceID); +VNX_LMS_API int fnLMS_GetEndFrequency(DEVID deviceID); +VNX_LMS_API int fnLMS_GetSweepTime(DEVID deviceID); +VNX_LMS_API int fnLMS_GetRF_On(DEVID deviceID); +VNX_LMS_API int fnLMS_GetUseInternalRef(DEVID deviceID); +VNX_LMS_API int fnLMS_GetPowerLevel(DEVID deviceID); +VNX_LMS_API int fnLMS_GetAbsPowerLevel(DEVID deviceID); +VNX_LMS_API int fnLMS_GetMaxPwr(DEVID deviceID); +VNX_LMS_API int fnLMS_GetMinPwr(DEVID deviceID); +VNX_LMS_API int fnLMS_GetMaxFreq(DEVID deviceID); +VNX_LMS_API int fnLMS_GetMinFreq(DEVID deviceID); +VNX_LMS_API float fnLMS_GetPulseOnTime(DEVID deviceID); +VNX_LMS_API float fnLMS_GetPulseOffTime(DEVID deviceID); +VNX_LMS_API int fnLMS_GetPulseMode(DEVID deviceID); +VNX_LMS_API int fnLMS_GetHasFastPulseMode(DEVID deviceID); +VNX_LMS_API int fnLMS_GetUseInternalPulseMod(DEVID deviceID); +VNX_LMS_API int fnLMS_GetDeviceStatus(DEVID deviceID); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/common/+deviceDrivers/@Labbrick/vnx_fmsynth.h b/common/+deviceDrivers/@Labbrick/vnx_fmsynth.h deleted file mode 100644 index e647b731..00000000 --- a/common/+deviceDrivers/@Labbrick/vnx_fmsynth.h +++ /dev/null @@ -1,124 +0,0 @@ -// Include file for Vaunix Lab Brick Microwave Frequency Synthesizers -// -// 9/2010 RD Updated version of DLL API definitions -// -// 3/2011 RD Updated with new pulse mode status functions, ANSI-C version - - - -// ------ C++ Calling Convention -------- -#define VNX_FSYNSTH_API __declspec(dllimport) - -#ifdef __cplusplus -extern "C" { -#endif - - -// ----------- Global Equates ------------ -#define MAXDEVICES 64 -#define MAX_MODELNAME 32 - -// ----------- Data Types ---------------- - -#define DEVID unsigned int - - -// ----------- Mode Bit Masks ------------ - -#define MODE_RFON 0x00000010 // bit is 1 for RF on, 0 if RF is off -#define MODE_INTREF 0x00000020 // bit is 1 for internal osc., 0 for external reference -#define MODE_SWEEP 0x0000000F // bottom 4 bits are used to keep the sweep control bits - -#define MODE_PWMON 0x00000100 // we keep a copy of the PWM control bits here, 1 for int PWM on -#define MODE_EXTPWM 0x00000200 // 1 for ext. PWM input enabled -#define PWM_MASK 0x00000300 - -// ----------- Command Equates ----------- - - -// Status returns for commands -#define LVSTATUS int - -#define STATUS_OK 0 -#define BAD_PARAMETER 0x80010000 // out of range input -- frequency outside min/max etc. -#define BAD_HID_IO 0x80020000 -#define DEVICE_NOT_READY 0x80030000 // device isn't open, no handle, etc. - -#define F_INVALID_DEVID -1.0 // for functions that return a float -#define F_DEVICE_NOT_READY -3.0 - -// Status returns for DevStatus - -#define INVALID_DEVID 0x80000000 // MSB is set if the device ID is invalid -#define DEV_CONNECTED 0x00000001 // LSB is set if a device is connected -#define DEV_OPENED 0x00000002 // set if the device is opened -#define SWP_ACTIVE 0x00000004 // set if the device is sweeping -#define SWP_UP 0x00000008 // set if the device is sweeping up in frequency -#define SWP_REPEAT 0x00000010 // set if the device is in continuous sweep mode -#define SWP_BIDIRECTIONAL 0x00000020 // set if the device is in bidirectional sweep mode -#define PLL_LOCKED 0x00000040 // set if the PLL lock status is TRUE (both PLL's are locked) -#define FAST_PULSE_OPTION 0x00000080 // set if the fast pulse mode option is installed - -// Internal values in DevStatus -#define DEV_LOCKED 0x00002000 // used internally by the DLL -#define DEV_RDTHREAD 0x00004000 // used internally by the DLL - - -VNX_FSYNSTH_API void fnLMS_SetTestMode(bool testmode); -VNX_FSYNSTH_API int fnLMS_GetNumDevices(); -VNX_FSYNSTH_API int fnLMS_GetDevInfo(DEVID *ActiveDevices); -VNX_FSYNSTH_API int fnLMS_GetModelName(DEVID deviceID, char *ModelName); -VNX_FSYNSTH_API int fnLMS_InitDevice(DEVID deviceID); -VNX_FSYNSTH_API int fnLMS_CloseDevice(DEVID deviceID); -VNX_FSYNSTH_API int fnLMS_GetSerialNumber(DEVID deviceID); - - -VNX_FSYNSTH_API LVSTATUS fnLMS_SetFrequency(DEVID deviceID, int frequency); - -VNX_FSYNSTH_API LVSTATUS fnLMS_SetStartFrequency(DEVID deviceID, int startfrequency); -VNX_FSYNSTH_API LVSTATUS fnLMS_SetEndFrequency(DEVID deviceID, int endfrequency); -VNX_FSYNSTH_API LVSTATUS fnLMS_SetSweepTime(DEVID deviceID, int sweeptime); - -VNX_FSYNSTH_API LVSTATUS fnLMS_SetPowerLevel(DEVID deviceID, int powerlevel); -VNX_FSYNSTH_API LVSTATUS fnLMS_SetRFOn(DEVID deviceID, bool on); - -VNX_FSYNSTH_API LVSTATUS fnLMS_SetPulseOnTime(DEVID deviceID, float pulseontime); -VNX_FSYNSTH_API LVSTATUS fnLMS_SetPulseOffTime(DEVID deviceID, float pulseofftime); -VNX_FSYNSTH_API LVSTATUS fnLMS_EnableInternalPulseMod(DEVID deviceID, bool on); -VNX_FSYNSTH_API LVSTATUS fnLMS_SetUseExternalPulseMod(DEVID deviceID, bool external); -VNX_FSYNSTH_API LVSTATUS fnLMS_SetFastPulsedOutput(DEVID deviceID, float pulseontime, float pulsereptime, bool on); - -VNX_FSYNSTH_API LVSTATUS fnLMS_SetUseInternalRef(DEVID deviceID, bool internal); -VNX_FSYNSTH_API LVSTATUS fnLMS_SetSweepDirection(DEVID deviceID, bool up); -VNX_FSYNSTH_API LVSTATUS fnLMS_SetSweepMode(DEVID deviceID, bool mode); -VNX_FSYNSTH_API LVSTATUS fnLMS_SetSweepType(DEVID deviceID, bool swptype); -VNX_FSYNSTH_API LVSTATUS fnLMS_StartSweep(DEVID deviceID, bool go); -VNX_FSYNSTH_API LVSTATUS fnLMS_SaveSettings(DEVID deviceID); - -VNX_FSYNSTH_API int fnLMS_GetFrequency(DEVID deviceID); -VNX_FSYNSTH_API int fnLMS_GetStartFrequency(DEVID deviceID); -VNX_FSYNSTH_API int fnLMS_GetEndFrequency(DEVID deviceID); -VNX_FSYNSTH_API int fnLMS_GetSweepTime(DEVID deviceID); - -VNX_FSYNSTH_API int fnLMS_GetRF_On(DEVID deviceID); -VNX_FSYNSTH_API int fnLMS_GetUseInternalRef(DEVID deviceID); -VNX_FSYNSTH_API int fnLMS_GetPowerLevel(DEVID deviceID); -VNX_FSYNSTH_API int fnLMS_GetMaxPwr(DEVID deviceID); -VNX_FSYNSTH_API int fnLMS_GetMinPwr(DEVID deviceID); -VNX_FSYNSTH_API int fnLMS_GetMaxFreq(DEVID deviceID); -VNX_FSYNSTH_API int fnLMS_GetMinFreq(DEVID deviceID); - - -VNX_FSYNSTH_API float fnLMS_GetPulseOnTime(DEVID deviceID); -VNX_FSYNSTH_API float fnLMS_GetPulseOffTime(DEVID deviceID); - -VNX_FSYNSTH_API int fnLMS_GetPulseMode(DEVID deviceID); - -VNX_FSYNSTH_API int fnLMS_GetHasFastPulseMode(DEVID deviceID); -VNX_FSYNSTH_API int fnLMS_GetUseInternalPulseMod(DEVID deviceID); - -VNX_FSYNSTH_API int fnLMS_GetDeviceStatus(DEVID deviceID); - -#ifdef __cplusplus - } -#endif