; TestController device configuration file for the Hameg HM8134 and HM8135 RF synthesizer
; Version 1.0
; Date 01-11-2025
; Written by Gertjan Miedema,  info at miedemageluid dot nl,  Username "Gertjan" at EEVblog.

; For use with TestController, software to control and log data.
; Tested with HM8135 with firmware V1.22, over HO820 USB and RS-232 interface.

; TestController must be restarted before any changes in this file will be used.
; TestController Manual is here: https://lygte-info.dk/project/TestControllerConfigDevice%20UK.html


; Some tips:
;
; - The HM8135 can sweep from 1Hz to 3GHz!  (HM8134: 1Hz to 1024MHz)
;   Amplitude range is from -135dBm to +13dBm, or from 40nV to 1V!

; - The USB interface (HO820) needs a driver. See HM8135 manual.
; - Be sure to check the VCP (Virtual Com port) checkbox in the Windows driver.
;
; - Set TestController and HM813x generator to the same baud rate.
;   Default RS-232: 9600 baud, No parity, 8 data bits, 1 stop bit, Xon-Xoff.
;   Default USB: 9600 baud.
;
; - The Dual Interface USB/RS-232 HO820 is electrically isolated from the measuring circuit.
;
; - To use the RS-232 port on the isolated HO820 interface, SET THE MENU TO "USB".
;   This "USB" setting is for BOTH USB and RS-232 on the HO820 interface!
;   (The RS-232 setting in the menu is for the other, non-isolated RS-232 connector)
;

; Known issues:
;
; - FM and AM modulation are supported. PM, FSK and PSK are not, but are easy to add if needed.
;
; - This Generator was also sold as HM8135-X, and under the Rohde & Schwarz brand.
;   They are probably identical, but their *idn? answer is unknown to me....
;



#metadef
#idString HAMEG,HM8135
#name Hameg HM8135
#handle HM8135

#replaceText MaxFrequency 3000M



#metadef
#idString HAMEG,HM8134
#name Hameg HM8134
#handle HM8134

#replaceText MaxFrequency 1024M


#meta
#idString HAMEG,HM8135
#name Hameg HM8135
#handle HM8135
#port com

#driver SCPIx
 

; The author statement is used for the listing in the About window.
#author Gertjan Miedema


#notes  Device configuration file for the Hameg HM8135 RF synthesizer.

- Set TestController and HM813x generator to the same baud rate.
  Default is 9600 baud, No parity, 8 data bits, 1 stop bit, Xon-Xoff.

- The USB interface (HO820) needs a driver. See HM8135 manual.
- Be sure to check the VCP (Virtual Com port) checkbox in the Windows driver.

- To use the RS-232 port on the isolated HO820 interface, SET THE MENU TO "USB".
  This "USB" setting is for BOTH USB and RS-232 on the HO820 interface!
  (The RS-232 setting in the menu is for the other, non-isolated RS-232 connector)

- For more info, tips and known issues, see the notes in the header of the device configuration file (Hameg HM8135.txt)


Configuration file version: 1.0




; ---------- SCPIx commands ---------

; Command to send always integer frequency numbers to the HM8135.

#scpiCmd FREQi #pgm#
; var freqInt = int(floor(value))
var freqInt = int(round(value))
deviceWrite(handle,":FREQ "+freqInt);



; Command to convert input in Volts to milliVolts before sending to the HM8135.

#scpiCmd POWV tx :POW (value*1000);



; Depending on the output level, the HM8135 "Volt out?" answer is in V or mV or uV or nV, without specifying Unit.
; This #pgm# converts all V/mV/uV/nV answers to a correct answer in Volts.
; This is only done when the :POWer:UNIT is "V" , DBM is passed through unchanged.

#scpiCmd POWread? #pgm#
var powRead = 0.0
var pUnit = deviceRead(handle,":POWer:UNIT?");

deviceWrite(handle,":POWer:UNIT DBM");
var powDBM=deviceRead(handle,":POW?");

if (pUnit)=="DBM"
   powRead = powDBM;   
else
   deviceWrite(handle,":POWer:UNIT V");
   var powV=deviceRead(handle,":POW?");
   if (powDBM >= -7.0)
      powRead = powV;
   elseif (powDBM < -7.0) && (powDBM >= -67.0)
      powRead = powV/1000;
  elseif (powDBM < -67.0) && (powDBM >= -127.0)
      powRead = powV/1000000;
   else
      powRead = powV/1000000000;
   endif;
endif;
print(powRead);



; command to set the modulation mode (OFF/AM/FM)

#scpiCmd MOD #pgm#
if value=="OFF"
   deviceWrite(handle,":FM:STATe 0;:AM:STATe 0");
elseif value=="AM"
   deviceWrite(handle,":FM:STATe 0;:AM:STATe 1");
elseif value=="FM"
   deviceWrite(handle,":AM:STATe 0;:FM:STATe 1");
endif;



; command to read the modulation mode (OFF/AM/FM)

#scpiCmd MOD? #pgm#
var modMode="OFF"
if (deviceRead(handle,":FM:STATe?"))==1
    modMode="FM";
endif;
if (deviceRead(handle,":AM:STATe?"))==1
    modMode="AM";
endif;
print(modMode);






; ---------- Read-Out commands ---------


#value Freq Hz SI
#value Ampli_v V SI3 V
#value Ampli_dB dBm D3 DBM



; How to poll for data, this is used for table and #values?
; :FREQuency[:CW|:FIXed]? returns the current (carrier) frequency
; :POWread?               returns the current level. Processed value converted to V or dBm
; :POW:UNIT?;             returns the current level unit (mode, V or DBM)

#askValues :FREQ?;POWread?;:POW:UNIT?;
#askValuesReadFormat ffx



; :POWer:UNIT?  returns the current unit.  V for Volt (mV / μV included) or DBM for dBm
#askMode :POW:UNIT?

#modeFromValue getElement(value,2)


; Switch meter to this mode during start, leave empty to avoid any switching
#initialMode 



#outputOff :OUTP 0




; ---------- Initial & Final commands ---------

; Initial commands to meter when establishing connection

; Set unit to default settings, wait 1000ms, Set output power to -10dBm
; *RST : Set unit to default settings
#initCmd *RST;[1000];:POWer -10;


; Final commands to meter before breaking connection

; Set output OFF, Reset to default settings, wait 1000ms, Go to Local
; RM0 : Go To Local
#finalCmd :OUTP 0;[100];*RST;[1000];:POWer -10;RM0;




; ==========  Setup Menu  ==========

#cmdSetup indicator Output_state
:read: :OUTP?
:updatealloff:
Off (value)=="0" (204,255,204)
On (value)=="1" (0,153,0)

#cmdSetup buttons Output_state
:write: :OUTP #
Off 0
On 1


#cmdSetup number Frequency
:read: FREQ?
:write: FREQi #
:tip: Set RF Frequency. Input is truncated to 1Hz resolution.
Hz 1 MaxFrequency


#cmdSetup separator _ 
2 100 Raised

#cmdSetup number Amplitude_V
:read: POWread?
:write: POWV #
:update: Amplitude
:tip: Set RF Amplitude in Volts rms (for AM max 500mV)
V 40n 0,999


#cmdSetup number Amplitude_dBm
:read: POWread?
:write: :POW #
:update: Amplitude
:tip: Set RF Amplitude in dBm (for AM max +7dBm)
dBm -135 13


#cmdSetup radio Amplitude_unit
:read: :POWer:UNIT?
:string:
:write: :POWer:UNIT # 
:update: Amplitude
:tip: Choose Power Level Unit.
V V
dBm DBM


#cmdSetup selector Amplitude
:read: :POWer:UNIT?
:string:
V Amplitude_V
DBM Amplitude_dBm


#cmdSetup separator Amplitude
2 100 Raised


;----- start modulation -----

#cmdSetup radio Modulation
:read: MOD?
:string:
:write: MOD #
:update: Modulation_Settings
:updatedelayed: 0.25
:tip: Select modulation mode. (for AM max level is +7dBm)
Off OFF
AM AM
FM FM


#cmdSetup selector Modulation_Settings
:read: MOD?
:string:
OFF Modulation_info
AM AM_mod_depth AM_mod_source AM_int_mod_shape AM_int_mod_freq
FM FM_mod_deviation FM_mod_source FM_int_mod_shape FM_int_mod_freq


#cmdSetup separator Modulation_info
2 100 empty
left Mod settings:


#cmdSetup radio FM_mod_source
:read: :FM:SOURce?
:string:
:write: :FM:SOURce # 
:tip: <html>Choose INTernal or AC coupled EXTernal modulation source<br>For EXT modulation: 2Vpp input = 100% modulation
Int INT
Ext EXT


#cmdSetup number FM_mod_deviation
:read: :FM:DEViation?
:write: :FM:DEViation #
:enable: FM_mod_source=="INT"
:tip: Set FM deviation. Max freq depends on carrier frequency.
Hz 200 400k


#cmdSetup radio FM_int_mod_shape
:read: :FM:INT:SHAPe?
:string:
:write: :FM:INT:SHAPe # 
:enable: FM_mod_source=="INT": 
:tip: Set the waveform of the internal modulation generator
Sine SIN
Square SQU


#cmdSetup number FM_int_mod_freq
:read: :FM:INT:FREQ?
:write: :FM:INT:FREQ #
:enable: FM_mod_source=="INT"
:tip: Set the frequency of the internal modulation generator
Hz 10 200k


#cmdSetup radio AM_mod_source
:read: :AM:SOURce?
:string:
:write: :AM:SOURce # 
:tip: <html>Choose INTernal or AC coupled EXTernal modulation source<br>For EXT modulation: 2Vpp input = 100% modulation
Int INT
Ext EXT


#cmdSetup number AM_mod_depth
:read: :AM:DEPTh?
:write: :AM:DEPTh #
:enable: AM_mod_source=="INT"
:tip: Set AM modulation depth
% 0 100


#cmdSetup radio AM_int_mod_shape
:read: :AM:INT:SHAPe?
:string:
:write: :AM:INT:SHAPe # 
:enable: AM_mod_source=="INT"
:tip: Set the waveform of the internal modulation generator
Sine SIN
Square SQU
Triangle TRI


#cmdSetup number AM_int_mod_freq
:read: :AM:INT:FREQ?
:write: :AM:INT:FREQ #
:enable: AM_mod_source=="INT"
:tip: Set the frequency of the internal modulation generator
Hz 10 200k


;----- end modulation -----


#cmdSetup separator Reference
2 100 Raised

#cmdSetup radio 10MHz_Reference
:read: :PHASe:SOURce?
:string:
:write: :PHASe:SOURce #;[1500];
:tip: Select INTernal or EXTernal 10MHz Reference.
Int. INT
Ext. EXT


; Optional HM8135 error read out

; #cmdSetup infoAsk Last_Error
; :read: :SYSTem:ERRor?
; _

