i'm making a GUI on BOA 0.3.1 and wxPython 2.4.2.4
this is what the program do:
1. the user browses for a text file containing the
amount of delay needed to be sent serially:
def OnBrowseTextFileButton(self, event):
dlg = wxFileDialog(self, "Choose a file",
".",
"", "*.txt", wxOPEN)
try:
if dlg.ShowModal() == wxID_OK:
filename = dlg.GetPath()
# Your code
self.BrowseFile.SetValue(filename)
finally:
dlg.Destroy()
2. the text file is read and the delays are put into
a list:
def OnOKButton(self, event):
if self.UserMode.GetValue() == True:
data_file = open(os.path.normpath
(self.BrowseFile.GetValue()), 'r')
data = data_file.readlines()
self.irradianceStrings = map(str, data)
self.irradianceIntegers = map(int, data)
self.Irradiance_Execute.SetValue
(''.join(self.irradianceStrings))
else:
self.irradianceIntegers = [10000 for x in
range(96)] #'10000', 96 times
self.Irradiance_Execute.SetValue
('10000')
3. the irradianceIntegers is then sent to
the external hardware through a serial port.
then after transmitting data, the GUI should then
retrieve data coming from the hardware, and it will do
this perpetually until the user stops the process or
the GUI has finished transmitting the contents of the
irradianceInteger[] list:
def OnStartButton(self, event):
self.ser.open()
tx_command = 67
tx_no_databyte = 2
tx_message_no = 1
tx_len = len (self.irradianceIntegers)
for j in range (tx_len) :
temp1 = []
temp2 = []
pyra1 = []
pyra2 = []
voltage = []
current = []
data_hi, data_lo =
divmod(self.irradianceIntegers[j], 0x100)
tx_checksum = -(data_hi + data_lo +
tx_command + tx_message_no + tx_no_databyte) & 0xff
self.ser.write(pack('6B', tx_command,
tx_message_no, tx_no_databyte, data_lo, data_hi,
tx_checksum))
rx_data = self.ser.read(19)
rx_len = len(rx_data)
byte = [ord(x) for x in rx_data]
if rx_len < 10:
sys.exit(1)
for k in range (rx_len-9):
if byte[k] == 70 and byte [k+2] == 6
and sum(byte[k:k+10]) & 0xff == 0:
temp11 = float(byte[k+3])* 5/255
temp22 = float(byte[k+4])* 5/255
pyra11 = float(byte[k+5])* 5/255
pyra22 = float(byte[k+6])* 5/255
voltage11 = float(byte[k+7])*
5/255
current11 = float(byte[k+8])*
5/255
temp1.append(temp11)
temp2.append(temp22)
pyra1.append(pyra11)
pyra2.append(pyra22)
voltage.append(voltage11)
current.append(current11)
filename = "%s%s.txt"
%(self.Save_Session.GetValue(),
time.strftime("%Y%m%d%H%M"))
table_file = open(filename,"a")
lendata = len(temp1)
for ii in xrange(lendata):
table_file.write('%f\t'%temp1[ii])
table_file.write('%f\t'%temp2[ii])
table_file.write('%f\t'%pyra1[ii])
table_file.write('%f\t'%pyra2[ii])
table_file.write('%f\t'
%voltage[ii])
table_file.write('%f\t'
%current[ii])
table_file.write('\n')
table_file.close()
self.ser.close()
----the problem is how will i make the transmit part
do the event every five minutes while just keeping the
receive part perpetually running. The transmit and
receive part is running smoothly.
----will doing this solve the problem:
self.timer1 = wxTimer(evtHandler=self,
id=wxID_WXMDIPARENTFRAME1TIMER1)
EVT_TIMER(self, wxID_WXMDIPARENTFRAME1TIMER1,
self.OnTimer1Timer)
def OnTimer1Timer(self, event):
#put serial transmit part of the code here #
def OnStartButton(self, event):
self.timer1.Start(30000) #5 minutes
#put serial receive part of the code here #
----thanks for the help you'll extend to me!
···
__________________________________
Do you Yahoo!?
Yahoo! Mail - Find what you need with new enhanced search.
http://info.mail.yahoo.com/mail_250