diff --git a/fygen.py b/fygen.py index c783f79..32eb154 100644 --- a/fygen.py +++ b/fygen.py @@ -288,6 +288,15 @@ def __init__( model = self.get_model() self.device_name = detect_device(model) + self.frequency_includes_decimal = False + if self.device_name == "fy6300": + # Model: FY6300-50M + # Version: V2.3.2 + # Frequency must be sent with decimal for WMF/WFF commands, + # And RMF command is received with decimal. + # (e.g. frequency is always represented in the form): 12345678.901234 Hz + self.frequency_includes_decimal = True + def close(self): """Closes serial port. Call this at program exit for a clean shutdown.""" self.port.close() @@ -444,8 +453,8 @@ def should_set(chan, parm_name, expected_value): make_command = { 'duty_cycle': functools.partial(_make_duty_cycle_command, channel), 'enable': functools.partial(_make_enable_command, channel), - 'freq_hz': functools.partial(_make_freq_hz_command, channel), - 'freq_uhz': functools.partial(_make_freq_uhz_command, channel), + 'freq_hz': functools.partial(_make_freq_hz_command, channel, include_decimal=self.frequency_includes_decimal), + 'freq_uhz': functools.partial(_make_freq_uhz_command, channel, include_decimal=self.frequency_includes_decimal), 'offset_volts': functools.partial( _make_offset_volts_command, channel, @@ -1218,7 +1227,7 @@ def _make_wave_command(channel, device_name, wave): return _make_command(channel, 'W%02u' % wave) -def _make_freq_uhz_command(channel, freq_uhz): +def _make_freq_uhz_command(channel, freq_uhz, include_decimal=False): """Create a frequency command string. freq_hz and freq_uhz are summed for the final result. @@ -1233,10 +1242,15 @@ def _make_freq_uhz_command(channel, freq_uhz): if freq_uhz < 0: raise InvalidFrequencyError('Invalid freq_uhz: %d' % freq_uhz) - return _make_command(channel, 'F%014u' % freq_uhz) + if include_decimal: + s = 'F%015.6f' % (freq_uhz/1e6) + return _make_command(channel, s) + else: + return _make_command(channel, 'F%014u' % freq_uhz) + -def _make_freq_hz_command(channel, freq_hz): - return _make_freq_uhz_command(channel, freq_hz * 1000000) +def _make_freq_hz_command(channel, freq_hz, include_decimal=False): + return _make_freq_uhz_command(channel, freq_hz * 1000000, include_decimal=include_decimal) def _make_volts_command(channel, max_volts, volts): diff --git a/fygen_test.py b/fygen_test.py index 9024ec1..07c1e77 100644 --- a/fygen_test.py +++ b/fygen_test.py @@ -1090,5 +1090,38 @@ def test_autodetect_no_conflict(self): for device in SUPPORTED_DEVICES: self.assertEqual(fygen.detect_device(device), device) +class TestFYGenFY6300(TestFYGen): + """Test harness for FY6300, which represents frequency differently in WMF/WFF command.""" + def setUp(self): + self.output = six.StringIO() + self.fy = fygen.FYGen( + port=self.output, + init_state=False, + device_name='fy6300', + ) + + def tearDown(self): + self.fy.close() + + def test_set_freq1(self): + """Sets a frequency using freq_hz.""" + self.fy.set(freq_hz=5000) + self.fy.set(channel=1, freq_hz=1e6) + self.assertEqual( + 'WMF00005000.000000\n' + 'WFF01000000.000000\n', + self.output.getvalue()) + + def test_set_freq2(self): + """Sets a frequency using freq_uhz.""" + self.fy.set(freq_uhz=5000) + self.fy.set(channel=1, freq_uhz=1e6) + self.assertEqual( + 'WMF00000000.005000\n' + 'WFF00000001.000000\n', + self.output.getvalue()) + + if __name__ == '__main__': unittest.main() + diff --git a/wavedef.py b/wavedef.py index 2423dca..b0f89e6 100644 --- a/wavedef.py +++ b/wavedef.py @@ -28,6 +28,7 @@ class UnsupportedDeviceError(Error): # mostly work anyway. SUPPORTED_DEVICES = set(( 'fy2300', + 'fy6300', 'fy6600', 'fy6800', 'fy6900',