simple python code when @ simplnano
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的更多相关文章
- Exploring Python Code Objects
Exploring Python Code Objects https://late.am/post/2012/03/26/exploring-python-code-objects.html Ins ...
- 机器学习算法实现(R&Python code)
Machine Learning Algorithms Machine Learning Algorithms (Python and R) 明天考试,今天就来简单写写机器学习的算法 Types Su ...
- 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 ...
- 46 Simple Python Exercises (前20道题)
46 Simple Python Exercises This is version 0.45 of a collection of simple Python exercises construct ...
- Python code 提取UML
Python是一门支持面向对象编程的语言,在大型软件项目中,我们往往会使用面向对象的特性去组织我们的代码,那有没有这样一种工具,可以帮助我们从已有代码中提取出UML图呢?答案是有的.以下,我们逐个介绍 ...
- PEP 8 – Style Guide for Python Code
原文:PEP 8 – Style Guide for Python Code PEP:8 题目:Python代码风格指南 作者:Guido van Rossum, www.yszx11.cnBarry ...
- 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 ...
- 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 ...
- python code
执行动态语句 执行字符串中的代码 http://www.cnblogs.com/fanweibin/p/5418817.html #!usr/bin/env python #coding:utf-8 ...
随机推荐
- 使用AndroidStudio自动生成JavaDoc文档
选中所需要生成的Module,找到工具栏上的 Tools,选择 Generate JavaDoc 出现如图的窗口 选择输出路径,就自动生成. 如果出现编码错误提示,则在 Other command l ...
- Xamarin迁移到 Unified API 注意事项
参考官方文档: Migrating to Unified API for Components #if __UNIFIED__ ... // Mappings Unified CoreGraphic ...
- linux 相关系列安装
以Red Hat Enterprise Linux 5为例进行讲解. 相关系列: linux下jdk的安装 linux下ant的安装 linux下redis的安装 linux下svn的安装 linux ...
- Apache Apex
http://apex.apache.org/docs.html https://apex.apache.org/docs/apex/application_development/
- ArcGIS Server发布服务,打包成功,发布失败
打包成功,发布失败 部分解决方案: ① 查看Server对于源数据所在文件夹是否有读写权限,若无赋予Server账户至少读写权限.读写权限的赋予:对应存放数据的文件夹上右键→属性→ 安全 赋予ar ...
- 【Demo】微信上墙
先看看微信墙效果图 使用简单说明 关于微信公众号 回复 "上墙",点击授权文章进行授权 回复"#上墙内容" 即可发表上墙消息了 查看微信墙列表,点击这里 原文地 ...
- Decimal、 Float、 Double 使用
一.Java 1.float型定义的数据末尾必须 有"f "或"F",为了和double区别.例float x=123.456f, y=2e20f; publ ...
- 桌面应用程序ClickOne打包部署
http://www.cnblogs.com/weixing/p/3358740.html
- Shell 字符串常见操作
参考文章:http://blog.csdn.net/chen_jp/article/details/8922582 一 字符替换 origin=原字符串 str=替换后的字符串 替换命令: str= ...
- CSS弹性盒布局
<html> <head> <meta charset="utf-8"/> <title></title> <st ...