aboutsummaryrefslogtreecommitdiff
path: root/rfGen.py
blob: 0fbca7b4bc2b17189fdd79cc6d0bc87ebec8c8b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import serial
import io

import time  # For sleep, clock, time and perf_counter
from datetime import datetime, timedelta

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)