{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2\n", "\n", "import sys\n", "\n", "# https://github.com/fzinfz/flask-DLT645\n", "sys.path.append(\"/data_nfs/flask-DLT645/lib\")\n", "from read import *\n", "\n", "%run /data_nfs/conf/flask-DLT645/dev.py" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Tag
Addr
010128318569UPS
000080853040市电
\n", "
" ], "text/plain": [ " Tag\n", "Addr \n", "010128318569 UPS\n", "000080853040 市电" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "devices = Meters(meter_list_str)\n", "df_meters = devices.df\n", "df_meters" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Serial(port='/dev/ttyUSB0', baudrate=2400, bytesize=8, parity='E', stopbits=1, timeout=0, xonxoff=False, rtscts=False, dsrdtr=False)\n", "\n", " ===== ['010128318569', 'UPS'] =====\n", "{'功率-瞬时总有功': ('89.80', 'W'), '电能-组合有功总-当前': (8.87, 'kWh')}\n", "\n", " ===== ['000080853040', '市电'] =====\n", "{'功率-瞬时总有功': ('49.60', 'W'), '电能-组合有功总-当前': (3286.75, 'kWh')}\n" ] } ], "source": [ "result = devices.read_meters(chn, level=2, verbose=0)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Tag功率-瞬时总有功电能-组合有功总-当前
Addr
010128318569UPS89.808.87
000080853040市电49.603286.75
\n", "
" ], "text/plain": [ " Tag 功率-瞬时总有功 电能-组合有功总-当前\n", "Addr \n", "010128318569 UPS 89.80 8.87\n", "000080853040 市电 49.60 3286.75" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import copy\n", "result_list = copy.deepcopy(result)\n", "\n", "for k,v in result_list.items():\n", " v['Addr'] = k, ''\n", "\n", "for m in result_list.values():\n", " for k in m.keys():\n", " m[k] = m[k][0]\n", "\n", "df = pd.DataFrame(result_list.values()).set_index('Addr')\n", "df = df_meters[['Tag']].merge(df, on='Addr')\n", "df" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.3" } }, "nbformat": 4, "nbformat_minor": 4 }