Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for FY6300. #8

Merged
merged 1 commit into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions fygen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -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):
Expand Down
33 changes: 33 additions & 0 deletions fygen_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

1 change: 1 addition & 0 deletions wavedef.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class UnsupportedDeviceError(Error):
# mostly work anyway.
SUPPORTED_DEVICES = set((
'fy2300',
'fy6300',
'fy6600',
'fy6800',
'fy6900',
Expand Down