模拟FIBERPRO偏振消光比测试仪ER2200的Python程序

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了模拟FIBERPRO偏振消光比测试仪ER2200的Python程序相关的知识,希望对你有一定的参考价值。

版权声明:本文为博主原创文章,欢迎转载,并请注明出处。联系方式:[email protected]

在上一篇随笔中采用VSPD、ModbusTool模拟串口、MODBUS TCP设备进行Python采集软件开发写了模拟ER2200的程序,后来进行了完善:数据进行随机变化,打印输出进行了完善。

# -*- coding:utf-8 -*-

u"""FIBERPRO偏振消光比测试仪ER2200模拟程序"""

__author__ = zhengbiqing [email protected]

import binascii
import signal
import sys
from random import random
import time

import serial

ser = serial.Serial(COM4, 115200, timeout=1)

print Welcome to , __doc__, ,, device is %s % (Ready if ser.isOpen() else Error)
print Author is , __author__


# ctrl+c处理函数
def signal_handler(signal, frame):
    ser.close()
    print You pressed Ctrl+C! , device is %s % (Closed if not ser.isOpen() else Error)
    print Goodbye!
    sys.exit(0)


# 程序是死循环,通过ctrl+c退出,为了在退出时关闭串口,捕获该信号
signal.signal(signal.SIGINT, signal_handler)

while True:
    data = ser.read(7)
    if len(data):
        # 调试打印,b2a_hex(data)是把字符串data转换为十六进制数
        now = time.localtime(time.time())
        HMS = time.strftime(%H:%M:%S, now)
        print %s <- %s(%r) % (HMS, binascii.b2a_hex(data), data)

    if data == read?\\r\\n:
        # 三个数字分别表示被测光的消光比,偏振角度,和光功率
        classtalk = 19.35 + round(random(), 2)
        angle = 53.47 + round(random(), 2)
        power = -5.17 + round(random(), 2)
        sendstr = str(classtalk) + , + str(angle) + , + str(power) + \\r
        now = time.localtime(time.time())
        HMS = time.strftime(%H:%M:%S, now)
        print %s -> %s % (HMS, sendstr)
        ser.write(sendstr)

 

以上是关于模拟FIBERPRO偏振消光比测试仪ER2200的Python程序的主要内容,如果未能解决你的问题,请参考以下文章

NRZ眼图的消光比(Extinction Ratio)测量测试---陡峭粗线的原因

半导体物理实验 04 - | 椭圆仪测量薄膜厚度

关于22.5KHz模拟脉冲信号(60V)占空比测试,占空比精度0.1%

如何模拟像素比以在 Windows 上使用 Google Chrome 或 Firefox 测试媒体查询?

Baumer工业相机中偏振相机如何使用Baumer堡盟GAPI SDK来进行偏振数据的计算转换输出(C++)

屏幕时序水平2200,垂直1125