annotate EventGhost.py @ 26:ca8993488ac5 default tip

Use Python 2.7.
author Daniel O'Connor <darius@dons.net.au>
date Tue, 16 Apr 2013 10:23:29 +0930
parents 2a1cea865cc0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
1 import eg
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
2 import zb
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
3
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
4 class PluginInfo(eg.PluginInfo):
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
5 name = "ZigBee"
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
6 author = "Darius"
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
7 version = "1.0.0"
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
8 description = "Listen for data from a Max Stream ZigBee module"
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
9
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
10
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
11
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
12 class Text:
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
13 port = "Port:"
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
14 baudrate = "Baudrate:"
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
15 bytesize = "Number of bits:"
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
16 parity = "Parity:"
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
17 parities = ['No parity', 'Odd', 'Even'] #, 'Mark', 'Space']
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
18 stopbits = "Stopbits:"
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
19 flowcontrol = "Flow control:"
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
20 handshakes = ['None', 'Xon / Xoff', 'Hardware']
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
21 generateEvents = "Generate events on incoming data"
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
22 eventPrefix = "Event prefix:"
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
23
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
24
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
25 import wx
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
26 import threading
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
27 import win32event
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
28 import win32file
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
29
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
30 class Serial(eg.RawReceiverPlugin):
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
31 canMultiLoad = True
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
32 text = Text
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
33
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
34 def __init__(self):
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
35 eg.RawReceiverPlugin.__init__(self)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
36 self.serial = None
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
37 self.up = zb.Packets()
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
38
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
39 def __start__(
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
40 self,
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
41 port,
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
42 baudrate,
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
43 bytesize=8,
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
44 parity=0,
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
45 stopbits=0,
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
46 handshake=0,
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
47 generateEvents=False,
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
48 prefix="Serial",
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
49 ):
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
50 xonxoff = 0
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
51 rtscts = 0
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
52 if handshake == 1:
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
53 xonxoff = 1
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
54 elif handshake == 2:
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
55 rtscts = 1
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
56
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
57 try:
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
58 self.serial = eg.SerialPort(
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
59 port,
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
60 baudrate=baudrate,
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
61 bytesize=(5, 6, 7, 8)[bytesize],
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
62 stopbits=(1, 2)[stopbits],
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
63 parity=('N', 'O', 'E')[parity],
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
64 xonxoff=xonxoff,
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
65 rtscts=rtscts,
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
66 )
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
67 except:
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
68 self.serial = None
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
69 raise eg.Exception("Can't open COM port.")
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
70 self.serial.timeout = 1.0
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
71 self.serial.setRTS()
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
72 self.info.eventPrefix = prefix
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
73 self.stopEvent = win32event.CreateEvent(None, 1, 0, None)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
74 self.receiveThread = threading.Thread(target=self.ReceiveThread)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
75 self.receiveThread.start()
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
76
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
77 def __stop__(self):
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
78 if self.serial is not None:
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
79 if self.receiveThread:
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
80 win32event.SetEvent(self.stopEvent)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
81 self.receiveThread.join(1.0)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
82 self.serial.close()
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
83 self.serial = None
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
84
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
85
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
86 def HandleChar(self, ch):
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
87 self.up.process(ch)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
88 while (len(self.up.pktq) > 0):
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
89 p = self.up.pktq.pop(0)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
90 if (p.PKT_TYPE == zb.RXIO_16_Bit.PKT_TYPE):
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
91 dios = (p._data[self.ADDR_SIZE + 5] << 8 |
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
92 self._data[self.ADDR_SIZE + 6]) & p.mask
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
93 self.TriggerEvent("0x%02x -> 0x%03x" % (p.sender, dios))
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
94 self.PrintError(str(p))
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
95 else:
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
96 self.PrintError("Got unknown packet: " + str(self.buffer))
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
97
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
98 def ReceiveThread(self):
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
99 from win32event import (
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
100 ResetEvent,
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
101 MsgWaitForMultipleObjects,
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
102 QS_ALLINPUT,
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
103 WAIT_OBJECT_0,
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
104 WAIT_TIMEOUT,
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
105 )
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
106 from win32file import ReadFile, AllocateReadBuffer, GetOverlappedResult
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
107 from win32api import GetLastError
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
108
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
109 continueLoop = True
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
110 overlapped = self.serial._overlappedRead
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
111 hComPort = self.serial.hComPort
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
112 hEvent = overlapped.hEvent
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
113 stopEvent = self.stopEvent
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
114 n = 1
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
115 waitingOnRead = False
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
116 buf = AllocateReadBuffer(n)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
117 while continueLoop:
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
118 if not waitingOnRead:
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
119 ResetEvent(hEvent)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
120 hr, _ = ReadFile(hComPort, buf, overlapped)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
121 if hr == 997:
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
122 waitingOnRead = True
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
123 elif hr == 0:
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
124 pass
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
125 #n = GetOverlappedResult(hComPort, overlapped, 1)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
126 #self.HandleChar(str(buf))
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
127 else:
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
128 self.PrintError("error")
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
129 raise
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
130
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
131 rc = MsgWaitForMultipleObjects(
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
132 (hEvent, stopEvent),
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
133 0,
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
134 1000,
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
135 QS_ALLINPUT
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
136 )
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
137 if rc == WAIT_OBJECT_0:
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
138 n = GetOverlappedResult(hComPort, overlapped, 1)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
139 if n:
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
140 self.HandleChar(str(buf))
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
141 #else:
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
142 # print "WAIT_OBJECT_0", n, str(buf[:n])
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
143 waitingOnRead = False
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
144 elif rc == WAIT_OBJECT_0+1:
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
145 continueLoop = False
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
146 elif rc == WAIT_TIMEOUT:
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
147 pass
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
148 else:
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
149 self.PrintError("unknown message")
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
150
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
151
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
152 def Configure(
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
153 self,
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
154 port=0,
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
155 baudrate=9600,
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
156 bytesize=8,
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
157 parity=0,
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
158 stopbits=0,
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
159 handshake=0,
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
160 generateEvents=False,
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
161 prefix="ZB",
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
162 ):
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
163 text = self.text
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
164 dialog = eg.ConfigurationDialog(self)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
165 portCtrl = eg.SerialPortChoice(dialog, value=port)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
166
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
167 baudrateCtrl = wx.ComboBox(
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
168 dialog,
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
169 value=str(baudrate),
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
170 choices=[
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
171 '110', '300', '600', '1200', '2400', '4800', '9600',
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
172 '14400', '19200', '38400', '57600', '115200',
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
173 '128000', '256000'
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
174 ],
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
175 style=wx.CB_DROPDOWN,
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
176 validator=eg.DigitOnlyValidator()
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
177 )
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
178
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
179 bytesizeCtrl = wx.Choice(dialog, choices=['5', '6', '7', '8'])
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
180 bytesizeCtrl.SetSelection(8 - 5)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
181
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
182 parityCtrl = wx.Choice(dialog, choices=text.parities)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
183 parityCtrl.SetSelection(parity)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
184
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
185 stopbitsCtrl = wx.Choice(dialog, choices=['1', '2'])
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
186 stopbitsCtrl.SetSelection(stopbits)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
187
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
188 handshakeCtrl = wx.Choice(dialog, choices=text.handshakes)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
189 handshakeCtrl.SetSelection(handshake)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
190
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
191 generateEventsCtrl = wx.CheckBox(dialog, label=text.generateEvents)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
192 generateEventsCtrl.SetValue(generateEvents)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
193
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
194 prefixCtrl = wx.TextCtrl(dialog)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
195 prefixCtrl.SetValue(prefix)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
196 prefixCtrl.Enable(generateEvents)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
197
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
198 def OnCheckBox(event):
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
199 flag = generateEventsCtrl.GetValue()
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
200 prefixCtrl.Enable(flag)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
201 generateEventsCtrl.Bind(wx.EVT_CHECKBOX, OnCheckBox)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
202
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
203 flags = wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
204 mySizer = wx.GridBagSizer(5, 5)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
205 Add = mySizer.Add
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
206 Add(wx.StaticText(dialog, -1, text.port), (0, 0), flag=flags)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
207 Add(portCtrl, (0, 1), flag=wx.EXPAND)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
208 Add(wx.StaticText(dialog, -1, text.baudrate), (1, 0), flag=flags)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
209 Add(baudrateCtrl, (1, 1), flag=wx.EXPAND)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
210 Add(wx.StaticText(dialog, -1, text.bytesize), (2, 0), flag=flags)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
211 Add(bytesizeCtrl, (2, 1), flag=wx.EXPAND)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
212 Add(wx.StaticText(dialog, -1, text.parity), (3, 0), flag=flags)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
213 Add(parityCtrl, (3, 1), flag=wx.EXPAND)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
214 Add(wx.StaticText(dialog, -1, text.stopbits), (4, 0), flag=flags)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
215 Add(stopbitsCtrl, (4, 1), flag=wx.EXPAND)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
216 Add(wx.StaticText(dialog, -1, text.flowcontrol), (5, 0), flag=flags)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
217 Add(handshakeCtrl, (5, 1), flag=wx.EXPAND)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
218
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
219 Add((5, 5), (6, 0), (1, 2), flag=flags)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
220 Add(generateEventsCtrl, (7, 0), (1, 2), flag=flags)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
221 Add(wx.StaticText(dialog, -1, text.eventPrefix), (9, 0), flag=flags)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
222 Add(prefixCtrl, (9, 1), flag=wx.EXPAND)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
223 dialog.sizer.Add(mySizer)
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
224
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
225 if dialog.AffirmedShowModal():
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
226 return (
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
227 portCtrl.GetValue(),
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
228 int(baudrateCtrl.GetValue()),
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
229 bytesizeCtrl.GetSelection(),
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
230 parityCtrl.GetSelection(),
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
231 stopbitsCtrl.GetSelection(),
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
232 handshakeCtrl.GetSelection(),
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
233 generateEventsCtrl.GetValue(),
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
234 prefixCtrl.GetValue(),
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
235 )
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
236
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
237
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
238
2a1cea865cc0 Add EventGhost module.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
239