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    \n    UTF-8
    SerialLibrary.Flush Port
    sleep    2
    SerialLibrary.Write Data    \n    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    \n    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    \n    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("\r\n")
    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

 

转载于:https://www.cnblogs.com/classics/p/11155841.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值