• seriallibary 使用 robotframe work


    1、安装  pip install robotframework-seriallibrary

    https://pypi.org/project/robotframework-seriallibrary/

    2、导入改库

    SerialLibrary

    3、简单使用  注意 格式和   波特率

    https://github.com/whosaysni/robotframework-seriallibrary/blob/develop/src/SerialLibrary/__init__.py          可以查询 port的参数

    #baudrate, bytesize, parity, stopbits,         timeout, xonxoff, rtscts, write_timeout, dsrdtr and         inter_byte_timeout.

    基本用例 com——test 

    注意格式:

    com_test
        SerialLibrary.Add Port    COM1    baudrate=9600
        #baudrate, bytesize, parity, stopbits,         timeout, xonxoff, rtscts, write_timeout, dsrdtr and         inter_byte_timeout.
        SerialLibrary.Open Port
        ${a}    SerialLibrary.Get Encoding
        log    ${a}
        SerialLibrary.Write Data    
        UTF-8
        SerialLibrary.Flush Port
        sleep    2
        SerialLibrary.Write Data    
        UTF-8
        sleep    5
        SerialLibrary.Read All Data
        sleep    2
        Comment    ${result2}    ${return2}    Run Keyword And Ignore Error    com_data_judge    ${read}    ${val_condition}
        Comment    Run Keyword If    '${result2}'=='FAIL'    log    ok
        ...    ELSE    log    not_ok
        Wait Until Keyword Succeeds    100X    3    com_data_judge    display current-configuration    local-user admin password cipher OUM!K%F<+$[Q=^Q`MAF4<1!!
        SerialLibrary.Flush Port
        SerialLibrary.Write Data    
        UTF-8
        sleep    3
        SerialLibrary.Close Port
        SerialLibrary.Delete All Ports

    4、关键字  com_data_judge

    com_data_judge
        [Arguments]    ${cli}    ${judeg_condition}
        SerialLibrary.Write Data    ${cli}    UTF-8
        sleep    2
        SerialLibrary.Write Data    
        UTF-8
        sleep    5
        ${read}    SerialLibrary.Read All Data
        log    ${read}
        sleep    2
        ${judeg_condition}    Convert To String    ${judeg_condition}
        ${ok}    ${num_idex}    Com Data    ${read}    ${judeg_condition}
        log    ${ok}
        log    ${num_idex}
        Should Be Equal As Strings    ${ok}    ok

    5、判断data  的py脚本

    字符串的去除空格

     编码转换(串口hexlify 转换到  unhexlify )

    字符串 分片

    字符串去除首尾空格

    比对字符串的值

    脚本:

    # -*- coding: utf-8 -*-
    import binascii
    def com_data(data1,val):
       
        data1 = data1.replace(" ","")
        
        data = binascii.unhexlify(data1)
        print data
        data = data.split("
    ")
        val = val.encode('gbk')
        
        for i in data:
            com_data1 = i.strip()
            if com_data1 == val:
                num = data.index(i)
                return "ok",num
           
        return "not_ok"
    
    if __name__ == "__main__":
        s = "72 6F 6F 74 6E 45 37 6A 41 25 35 6D"
        a,b=com_data(s,"vlan batch 4000 to 4001")
        print a,b
  • 相关阅读:
    15款精美的 WordPress 电子商务网站模板
    15套免费的扁平化界面设计素材【免费下载】
    35幅使用小图片组成的创意插图作品 【上篇】
    sqlserver2014两台不同服务器上数据库同步
    C++ Reflection Library
    美国的包容主要体现在接受移民,那么,中国的包容主要体现在哪里呢?答案就是资本
    mysql主从复制
    Kubernetes+Istio
    Net异步编程
    研发的困境----DEVOPS
  • 原文地址:https://www.cnblogs.com/classics/p/11155841.html
Copyright © 2020-2023  润新知