code:

 import serial,time,itertools

 try:
ser=serial.Serial(2,115200,timeout=0)
except:
print 'Open COM2 Failed!!' #transno=(1,100,500,1380,1381)
#transno=(1,20)
indexsets=[[0],[1],[2],[3],[0,1],[0,2],[0,3],[1,2],[1,3],[2,3],[0,1,2],[0,1,3],[0,2,3],[1,2,3],[0,1,2,3]]
indexsets=[[0,1,3],[0,1,2]]
#indexsets_ts=[] def gene():
for n in range(1,5):
indexsets_ts+=list(itertools.combinations([0,1,2,3],n)) #forget what is itertool now
return indexsets_ts #sig functions
def sigsnd():
for actmod in ('diract','apnact'):
act(actmod)
for connmod in ('TCP','UDP'):
conn(connmod)
connt=0
for dismod in ('dirsht','closht'):
for sndmod in ('uctl','fixl'):
snd(sndmod)
dis(dismod)
if connt<1:
conn(connmod)
connt+=1 def init():
swrt(chr(0x27),1)
swrt('\r\n',1)
ser.write('+++')
swrt('\r\n',1)
def shutConn():
swrt('at+cipshut',4)
def cloShut():
swrt('at+cipclose',4)
swrt('at+cipshut',4)
def cipmod():
swrt('at+cipmode=0',2)
def olmod():
swrt('at+cipmode=1',2)
def muxmod():
swrt('at+cipmux=1',2)
def sigmod():
swrt('at+cipmux=0',2)
def srd():
srd=ser.readlines()
for line in srd:
print line
fid=open('tcp_snd.log','a')
fid.write(line)
fid.close()
return srd
def swrt(atcmd_str,wt):
#fid=open('tcp_snd.log','a')
#fid.write(atcmd_str)
#fid.close()
ser.write(atcmd_str+'\r\n')
time.sleep(wt)
srd()
def wrtmsg(transtr,wstm):
ser.write(transtr+chr(0x1a))
time.sleep(wstm)
srd()
def act(actmod):
if actmod=='apnact':
swrt('at+cstt="CMNET","",""',2)
swrt('at+ciicr',4)
if actmod=='diract':
pass
def conn(connmod):
if connmod=='TCP':
swrt('at+cipstart="TCP","124.205.119.38",1562',6)
if connmod=='UDP':
swrt('at+cipstart="UDP","124.205.119.38",1562',6)
def snd(sndmod):
if sndmod=='uctl':
for tran in transno:
for n in range(2):
swrt('at+cipsend',1)
wrtmsg(tran*'v',8)
if sndmod=='fixl':
for tran in transno:
for n in range(2):
swrt('at+cipsend='+str(tran),1)
wrtmsg(tran*'v',8)
def dis(dismod):
if dismod=='dirsht':
shutConn()
if dismod=='closht':
cloShut() #online mode function
def modTs():
for actmod in ('diract','apnact'):
act(actmod)
for connmod in ('TCP','UDP'):
print connmod
conn(connmod)
connt=0
for dismod in ('dirsht','closht'):
print dismod
olsnd()
dis(dismod)
print dismod
if connt<1:
conn(connmod)
connt+=1 def olsnd():
for rtm in range(2):
for tran in transno:
swrt(tran*'v',1)
nmipmd()
ato()
nmipmd()
def ato():
swrt('ato',2)
def nmipmd():
ser.write('+++')
time.sleep(3)
srd() #mux-mode functions indset=[0,1,3]
def muxTS(indset):
for actmod in ('diract','apnact'):
act(actmod)
for dismod in ('dirsht','closht'):
for x in range(2**len(indset)):
binstr=bin(int(str(x),10))[2:].rjust(len(indset),'')
typset=[]
for nc in binstr:
if nc=='':
typset.append('"TCP"')
else:
typset.append('"UDP"')
for ind in range(len(indset)):
constr='at+cipstart='+str(indset[ind])+','+typset[ind]+',"124.205.119.38",1562'
swrt(constr,7)
print 'wrt done' ##connect OK
for sndmod in ('uctl','fixl'):
for index in indset:
print indset,index
for tran in transno:
for n in range(2):
if sndmod=='uctl':
swrt('at+cipsend='+str(index),1)
wrtmsg(tran*'v',15)
else:
swrt('at+cipsend='+str(index)+','+str(tran),1)
wrtmsg(tran*'v',15)
dis(dismod) sndmod=''
def muxmod():
swrt('at+cipmux=1',2) def muxsnd(indset):
for index in indset:
print indset,index
for tran in transno:
for n in range(5):
if sndmod=='uctl':
swrt('at+cipsend='+str(index),1)
wrtmsg(tran*'v',15)
else:
swrt('at+cipsend='+str(index)+','+str(tran),1)
wrtmsg(tran*'v',15) #sigle-mode Ts
init()
shutConn()
cipmod()
sigmod()
sigsnd() #online-mode Ts
init()
shutConn()
cipmod()
sigmod()
olmod()
modTs() #mux-mode Ts
init()
shutConn()
cipmod()
sigmod()
muxmod()
[muxTS(indset) for indset in indexsets] init()
shutConn()
ser.close()

simple python code when @ simplnano的更多相关文章

  1. Exploring Python Code Objects

    Exploring Python Code Objects https://late.am/post/2012/03/26/exploring-python-code-objects.html Ins ...

  2. 机器学习算法实现(R&Python code)

    Machine Learning Algorithms Machine Learning Algorithms (Python and R) 明天考试,今天就来简单写写机器学习的算法 Types Su ...

  3. How to run Python code from Sublime

    How to run Python Code from Sublime,and How to run Python Code with input from sublime Using Sublime ...

  4. 46 Simple Python Exercises (前20道题)

    46 Simple Python Exercises This is version 0.45 of a collection of simple Python exercises construct ...

  5. Python code 提取UML

    Python是一门支持面向对象编程的语言,在大型软件项目中,我们往往会使用面向对象的特性去组织我们的代码,那有没有这样一种工具,可以帮助我们从已有代码中提取出UML图呢?答案是有的.以下,我们逐个介绍 ...

  6. PEP 8 – Style Guide for Python Code

    原文:PEP 8 – Style Guide for Python Code PEP:8 题目:Python代码风格指南 作者:Guido van Rossum, www.yszx11.cnBarry ...

  7. 46 Simple Python Exercises-Very simple exercises

    46 Simple Python Exercises-Very simple exercises 4.Write a function that takes a character (i.e. a s ...

  8. Change the environment variable for python code running

    python程序运行中改变环境变量: Trying to change the way the loader works for a running Python is very tricky; pr ...

  9. python code

    执行动态语句 执行字符串中的代码 http://www.cnblogs.com/fanweibin/p/5418817.html #!usr/bin/env python #coding:utf-8 ...

随机推荐

  1. PHP程序员函数注释规格(麻烦大家遵守)

    PHP程序员函数注释规格(麻烦大家遵守)   以前我也不愿意写注释,但是2个月后发现自己写的什么都不知道了.. 为了宇宙的发展,为了二次开发的便捷,为了代码的可读性,建议大家把注释写好.. <? ...

  2. ActionResult,PartialViewResult,EmptyResult,ContentResult

    HttpGet  HttpPost  HttpDelete  HttpPut  HeepHead HttpOptions HttpPatch属性都是动作方法选定器的一份子,比如若在action上套用H ...

  3. 性能测试工具JMeter

    JMeter介绍     Apache JMeter是Apache组织的开放源代码项目,具有极高的可扩展性,是一个100%纯Java桌面应用,用于压力/性能测试.JMeter可以用于测试静态或者动态资 ...

  4. LR中HTTP协议录制模式选择

    在LR中使用HTML/HTTP协议进行脚本录制时面临正确选择HTTP-based script / URL-base script 录制模式的问题,以下是比较官方的建议:1)基于浏览器的应用程序推荐使 ...

  5. PHP MongoDB 扩展安装配置

    近日对MongoDB比较感兴趣,在linux下部署了一套LAMP,想把MongoDB加进来,下面进入正题: 1.确保安装好LAMP环境,假设php安装目录:/usr/local/php5 2.下载ht ...

  6. os

    内核,Shell和文件结构一起形成了基本的操作系统结构. from:大学生攻克Linux系统教程(又名天下没有难学的Linux) 发问: 0-内核,再怎么分出层次呢?

  7. 【No.4 Ionic】修改 cordova 插件

    在使用 cordova 过程 使用的插件 有可能不能满足个人需求,就需要修改,下面就直接说说步骤 插件结构 我用 cordova-plugin-inappbrowser 插件 讲解 在目录中有个 sr ...

  8. Eclipse反编译插件JadEclipse 【转】

    JAVA的反编译插件JadEclipse,官网地址为:http://java.decompiler.free.fr/ 这里面有3个,Jad-Gui大家都知道是一个单独的可执行程序,把要反编绎的jar直 ...

  9. JS面相对象

    一.理解对象: //第一种:基于Object对象 var person = new Object(); person.name = 'My Name'; person.age = ; person.g ...

  10. android硬件调试之无法识别android设备解决办法

    DDMS 中无法识别华为荣耀六手机,  用豌豆荚开始显示无法连接,  用豌豆荚安装完驱动后,就可以连接了 http://www.zhihu.com/question/30588024 http://w ...