aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugeniy E. Mikhailov <evgmik@gmail.com>2021-06-03 13:55:24 -0400
committerEugeniy E. Mikhailov <evgmik@gmail.com>2021-06-03 13:55:24 -0400
commit92f9093220dc089158b091ca3a2f05c4d44c6319 (patch)
tree3a818783b0eb4a701ebd4324e82964e2bc2a50a6
parentbb92df37075aa1d1fbcc421ae4d4dcf215da406b (diff)
downloadpyExpControl-92f9093220dc089158b091ca3a2f05c4d44c6319.tar.gz
pyExpControl-92f9093220dc089158b091ca3a2f05c4d44c6319.zip
tested rfGen with LMX2487 control
-rw-r--r--rfGen.py41
-rw-r--r--test_rfGenLMX2487.py20
2 files changed, 61 insertions, 0 deletions
diff --git a/rfGen.py b/rfGen.py
new file mode 100644
index 0000000..3be3182
--- /dev/null
+++ b/rfGen.py
@@ -0,0 +1,41 @@
+import serial
+import io
+
+import time # For sleep, clock, time and perf_counter
+from datetime import datetime, timedelta
+
+# ser = serial.Serial('COM4', 115200, timeout=1)
+ser = serial.Serial('/dev/ttyUSB0', 115200, timeout=1)
+# ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=1)
+
+class rfGenLMX2487:
+ def __init__(self, port='/dev/ttyUSB0', speed=115200, timeout=1):
+ self.port = port
+ self.speed = speed
+ self.timeout = timeout
+ self.connection = serial.Serial( self.port, self.speed, timeout=self.timeout)
+ self.log = []
+ self.logCapacity = 10
+
+ def add2log(self, text):
+ self.log.append(text)
+ while len(self.log) > self.logCapacity:
+ self.log.pop(0)
+
+ def log2str(self, interval=None):
+ strOut = ""
+ for e in self.log:
+ strOut += e
+ return strOut
+
+ def sendSerialCmd(self, cmd):
+ self.connection.write(bytes(cmd+'\r','ascii'))
+ resp = self.connection.read_until(terminator=b'> ')
+ resp = resp.decode('utf-8')
+ self.add2log(resp)
+ return resp
+
+ def setFreq(self,freq):
+ cmd_str=f'setFreq({freq:.2f})'
+ self.sendSerialCmd(cmd_str)
+
diff --git a/test_rfGenLMX2487.py b/test_rfGenLMX2487.py
new file mode 100644
index 0000000..e87ad79
--- /dev/null
+++ b/test_rfGenLMX2487.py
@@ -0,0 +1,20 @@
+from rfGen import rfGenLMX2487
+import numpy as np
+import platform
+
+if platform.system() == 'Linux':
+ rf=rfGenLMX2487(port='/dev/ttyUSB0', speed=115200, timeout=1)
+else:
+ rf=rfGenLMX2487(port='COM5', speed=115200, timeout=1)
+
+freqStart = 6.830e9
+freqStop = 6.840e9
+Np = 21
+print(f'We will sweep frequency from {freqStart} to {freqStop} in {Np} points')
+for freq in np.linspace(freqStart,freqStop, num=Np, endpoint=True):
+ print(f'Frequency set to {freq:.2f}')
+ rf.setFreq(freq)
+
+print("Printing log")
+print(rf.log2str())
+