This repository has been archived by the owner on May 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommands.py
83 lines (63 loc) · 2.79 KB
/
commands.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
79
80
81
82
83
#!/usr/bin/env python
from communication import Communication
from enum import Enum
class GeneralCommand(Enum):
GetDeviceInformation = 1
SetVoltage = 2
GetVoltage = 3
SetCurrent = 4
GetCurrent = 5
SelectChannel = 6
SetOutput = 7
class Command():
def __init__(self, command, length):
self.command = command
self.length = length
def __mod__(self, value):
return self.command % value
def __str__(self):
return self.command
class Device:
def __init__(self, device):
self._GeneralCommands = {
GeneralCommand.GetDeviceInformation : None,
GeneralCommand.SetVoltage : None,
GeneralCommand.GetVoltage : None,
GeneralCommand.SetCurrent : None,
GeneralCommand.GetCurrent : None,
GeneralCommand.SelectChannel : None,
GeneralCommand.SetOutput : None,
}
self.__device = Communication(device)
def __SelectChannel(self,channel):
self.__device.Write(self._GeneralCommands[GeneralCommand.SelectChannel] % channel)
def SetVoltage(self, channel, voltage):
self.__SelectChannel(channel)
self.__device.Write(self._GeneralCommands[GeneralCommand.SetVoltage] % voltage)
def GetVoltage(self, channel):
self.__SelectChannel(channel)
self.__device.Write(self._GeneralCommands[GeneralCommand.GetVoltage])
val = self.__device.Read(self._GeneralCommands[GeneralCommand.GetVoltage].length)
print "val=" + str(val)
def SetCurrent(self, channel, current):
pass
def GetCurrent(self, channel):
pass
def SetOutput(self, channel, state):
self.__SelectChannel(channel)
self.__device.Write(self._GeneralCommands[GeneralCommand.SetOutput] % state)
class HMC804xDevice(Device):
def __init__(self, device):
Device.__init__(self,device)
self.__linefeed = "\n"
self._GeneralCommands[GeneralCommand.SelectChannel] = Command("INST:NSEL %i" + self.__linefeed, None)
self._GeneralCommands[GeneralCommand.SetVoltage] = Command("VOLT %f" + self.__linefeed, None)
self._GeneralCommands[GeneralCommand.GetVoltage] = Command("VOLT?" + self.__linefeed, 10)
self._GeneralCommands[GeneralCommand.SetOutput] = Command("OUTP %f" + self.__linefeed, None)
class DummyCommands(Device):
def __init__(self):
Device.__init__(self)
if __name__ == "__main__":
# mycommand = HMC804xDevice()
# mycommand.GetVoltage()
print dir(Device)