473,378 Members | 1,577 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

telit script run number

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
6 4727
bvdet
2,851 Expert Mod 2GB
Tim,

Can you describe the purpose of the code snippet? What determines the value of i?
Jan 9 '09 #2
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
2,851 Expert Mod 2GB
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
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
2,851 Expert Mod 2GB
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
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

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

Similar topics

8
by: michael830724 | last post by:
Hello everyone : I am doing some work about telit GM862-GPS , i want to have some exemple python code about how to capture ADC .
0
by: eltonyeo | last post by:
hi everyone.. i am new here.. can everyone in the forum guide me along.. thanks.. i am currently doing a project on telit gm862-gps.. i have to use PYTHON to write a software program. kindly...
0
by: lrajselj | last post by:
Hi. I have a problem with presentation of numbers in Python 1.5.2 that is integrated in Telit module GE863-GPS. The problem is, that Python does not recognize decimal numbers (For example: I...
1
by: AAAlansari | last post by:
Hi everyone. I am a new customer here :) ... I hope you can help me.. I am trying to program Telit GM862-GSM GPS modem in order to send SMS. However, I am not sure which software do I have to...
2
by: Anitaa | last post by:
Hello! I'm new here, both in this forum and with Python, so you'll have to excuse me if my questions are a bit.... well, you know. I'm trying to write a script for Telit module with witch i'll be...
2
by: EdKing | last post by:
Hi everyone, I'm currently trying to get the simplest "Hello World!" Python script working on a Telit GM862-GPS. I have succeeded in writing to the Telit via the Hyper Terminal and can confirm...
1
by: yueying53 | last post by:
Hi all, I have a telit EVK2 evaluation kit and a gm862 module. Setup was fine in my school computers and I was even able to write a small program to send and receive sms. However when I...
1
by: wangchengxinyi | last post by:
hello everyone: Is anyone know how to program with telit GM862 GPS in python? i want to program with the telit module, but i have never used it, i even dont know how to download a script, how...
1
by: nbrdja | last post by:
Hi everyone :) (telit 862-GPS) pyton script Is there anyone have solution how to use GPIO line on 862-GPS to act as "interupt"? for example: i'd like to send sms or turn on LED (immiditly)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.