-
Notifications
You must be signed in to change notification settings - Fork 0
/
T344.py
78 lines (65 loc) · 2.04 KB
/
T344.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import time
import serial
#!/usr/bin/env python
import string, os, sys, time
class T344:
def __init__(self, name):
self.ser = serial.Serial(
port='COM1',
baudrate=38400,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1
)
ser = self.ser
ser.isOpen()
# send the character to the device
# (note that I happend a \r\n carriage return and line feed to the characters - this is requested by my device)
self.write(' ')
out = ''
# let's wait one second before reading output (let's give device time to answer)
time.sleep(1)
while ser.inWaiting() > 0:
out += ser.read(1)
if out != '':
print ">>" + out
def get_status(self):
self.write('ST')
return self.readline()
def sync(self):
self.write('SYNC')
return self.readline()
def set_freq(self, chan, val):
self.write(str(chan) + 'FREQ ' + str(val))
return self.readline()
def set_freq_raw(self, chan, val):
self.write(str(chan) + 'RAW ' + str(val))
return self.readline()
def set_amp(self, chan, val):
self.write(str(chan) + 'AMP ' + str(val))
return self.readline()
def set_phase(self, chan, val):
self.write(str(chan) + 'PHASE ' + str(val))
return self.readline()
def set_DC(self, chan, val):
self.write(str(chan) + 'DC ' + str(val))
return self.readline()
def write(self, stri):
ser = self.ser
ser.write(stri + '\r\n')
def readline(self):
ser = self.ser
return ser.readline()
def read2(self):
ser = self.ser
time.sleep(0.1)
out=''
while ser.inWaiting() > 0:
out += ser.read(1)
return (out)
#initialization should open it already
def reopen(self):
self.ser.open()
def close(self):
self.ser.close()