跳到主要内容

测试插件

准备Modbus测试设备程序

如果需要测试Modbus插件,参考如何自己生成modbus测试设备程序?

使用coapthon库(python)

可以使用coapthon库,编写python程序来访问插件所提供的微服务。请注意需要先安装wa-edge软件,安装并启用所测试的插件。

如下例所示:

#!/usr/bin/env python3

# -*- coding: utf-8 -*-
import argparse
import datetime
import os
import pprint
import random
import re
import shlex
import subprocess
import signal
import sys
import time
import shutil
import json

repo_root_dir="/chang_it_to_your_path"

sys.path.append(repo_root_dir + "/deps/CoAPthon3/coapthon")
from coapthon.client.helperclient import HelperClient
from coapthon import defines
if __name__ == "__main__":

device_id="change_it";

wa_client = HelperClient(server=("127.0.0.1", 5683))

# WRITE 3 REG from 120, but PLC APP will interpreter it as BOOL
path = "/mb2?DI={}&area=Holding&ITEMS=3".format(device_id)
value = [100, 0, 10000]
wa_client.put(path, (defines.Content_types["application/json"],json.dumps(value)))

response2 = wa_client.get(path)
# print(str(response2.payload))
j_result = json.loads(response2.payload)
if (j_result != value):
print ("error.")
sys.exit(1)
print("Modbus #1: Ok")