By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,772 Members | 937 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,772 IT Pros & Developers. It's quick & easy.

telit script run number

P: 6
hello,
I need to make a compiled script that I know how to do, done more then once, and work, *.pyo.
Then I send it to the gsm module and put it run.
The rest of the code is ok, I have test it more than once but to organize a group of aquired temperatures does not work, next is an example of the code that I need to run:
Expand|Select|Wrap|Line Numbers
  1. import MOD #Use build in module
  2. import MDM #Use AT command interface
  3. #i=5
  4. # wake module
  5. #Set time
  6. #Set next alarm
  7. print i
  8. if i == 1:
  9.         i=i+1
  10.         print'Temperature=',temp,'C'
  11. elif i == 2:
  12.         i=i+1
  13.         print 'voltage=',volt,'V'
  14. elif i == 3:
  15.         i=1
  16.         print 'send sms',volt,temp
  17. else:
  18.         i = 1
  19.         print 'reset'
  20. #Turn off module
  21.  
If I dont declare the variable i I get the error:
Traceback (innermost last):
File "C:\Programas\Python\Pythonwin\pywin\framework\scr iptutils.py", line 301, in RunScript
exec codeObject in __main__.__dict__
File "D:\Python\Script1.py", line 18, in ?
print i
NameError: i
but if I declare i=5 like in the exemple it allway give me an output:
i=5
reset
So what i need is to give a value to i in the beginig and after that first cycle disable it...
Did i make myself clear?
Thanks in advance
Tim
Jan 9 '09 #1
Share this Question
Share on Google+
6 Replies


bvdet
Expert Mod 2.5K+
P: 2,851
Tim,

Can you describe the purpose of the code snippet? What determines the value of i?
Jan 9 '09 #2

P: 6
bvdet,

The i is like in the example, in the first run it collect the voltage in the second run it colect temperature and in the 3 run it put all the information toghether and send it by sms.
Thanks
Tim
Jan 9 '09 #3

bvdet
Expert Mod 2.5K+
P: 2,851
You can save the run number (variable i) to a file. It could work something like this:
Expand|Select|Wrap|Line Numbers
  1. import os
  2.  
  3. def read_data(fn, i):
  4.     # read data file if existing
  5.     if os.path.exists(fn):
  6.         return int(open(fn).read().strip())
  7.     else:
  8.         return i
  9.  
  10. def save_data(fn, n):
  11.     f = open(fn, 'w')
  12.     f.write(str(n))
  13.     f.close()
  14.  
  15. def main(temp=None, volt=None):
  16.     data_fn = 'data_i.txt'
  17.     i = 1
  18.  
  19.     i = read_data(data_fn, i)
  20.  
  21.     if i == 1:
  22.         i += 1
  23.         print'Temperature =',temp,'C'
  24.     elif i == 2:
  25.         i += 1
  26.         print 'Voltage =',volt,'V'
  27.     elif i == 3:
  28.         i = 1
  29.         print 'send sms',volt,temp
  30.     else:
  31.         i = 1
  32.         print 'reset'
  33.  
  34.     save_data(data_fn, i)
  35.     return i
  36.  
  37. if __name__ == '__main__':
  38.     print main(temp=23)
  39.     print main(volt=220)
  40.     print main(23,220)
Jan 9 '09 #4

P: 6
hello bvdet,

Thanks for the fast answer!
Do you know if in telit modules is possible to save a txt file?
Because i am using a telit ge863 gps and don't know if it is as the os module.
thanks once again

Tim
Jan 9 '09 #5

bvdet
Expert Mod 2.5K+
P: 2,851
I am not familiar with telit. You don't need the os module if you do it like this:
Expand|Select|Wrap|Line Numbers
  1. def read_data(fn, i):
  2.      # read data file if existing
  3.      try:
  4.          return int(open(fn).read().strip())
  5.      except:
  6.          return i
Jan 9 '09 #6

P: 6
hello bvdet,

It took me some time to understand how to make that file and manipulate it but now is resolved the problem.
Thanks for your help.
If you want you can close the thread.

Regards,
Tim
Jan 11 '09 #7

Post your reply

Sign in to post your reply or Sign up for a free account.