From 628ce8bf27bf12942be5c51b61ea03697527edce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=20=E6=B3=BD=E9=9A=86?= Date: Sat, 16 Nov 2024 18:57:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0SLCP102=E6=89=93=E5=8C=85?= =?UTF-8?q?=E9=80=BB=E8=BE=91;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resource/Untitled-1.py | 45 +++++++++++++++++++++++++++++++++++++ source/data_analy.py | 39 ++++++++++++++++++++++++++++++++ source/dev_LaminaAdapter.py | 9 ++++---- source/post_work.py | 4 ++-- 4 files changed, 91 insertions(+), 6 deletions(-) create mode 100644 resource/Untitled-1.py create mode 100644 source/data_analy.py diff --git a/resource/Untitled-1.py b/resource/Untitled-1.py new file mode 100644 index 0000000..a1f9be0 --- /dev/null +++ b/resource/Untitled-1.py @@ -0,0 +1,45 @@ +# %% +from paho.mqtt import client as mqtt_client + +broker = '123.249.75.235' +port = 1883 +topic = "python/mqtt" +client_id = f'python-mqtt-{random.randint(0, 1000)}' +username = 'TTE0101TC2311000003' +password = 'qh10579lcb7au8o2' + + +# %% +import random +from paho.mqtt import client as mqtt_client + +broker = '123.249.75.235' +port = 1883 +topic = "python/mqtt" +client_id = f'python-mqtt-{random.randint(0, 1000)}' +username = 'TTE0101TC2311000003' +password = 'qh10579lcb7au8o2' + + +# %% +def connect_mqtt(): + def on_connect(client, userdata, flags, rc): + # For paho-mqtt 2.0.0, you need to add the properties parameter. + # def on_connect(client, userdata, flags, rc, properties): + if rc == 0: + print("Connected to MQTT Broker!") + else: + print("Failed to connect, return code %d\n", rc) + # Set Connecting Client ID + client = mqtt_client.Client(client_id) + + # For paho-mqtt 2.0.0, you need to set callback_api_version. + # client = mqtt_client.Client(client_id=client_id, callback_api_version=mqtt_client.CallbackAPIVersion.VERSION2) + + # client.username_pw_set(username, password) + client.on_connect = on_connect + client.connect(broker, port) + return client + + + diff --git a/source/data_analy.py b/source/data_analy.py new file mode 100644 index 0000000..f2512f1 --- /dev/null +++ b/source/data_analy.py @@ -0,0 +1,39 @@ +import pandas as pd +from pathlib import Path +from bs4 import BeautifulSoup + +# 1. 读取本地HTML文件 +file_path = Path(r'D:\WorkingProject\LightStackAdapter\Log\设备测试数据记录-铁塔主站\南和县牧村\Untitled-1.html') +html_content = file_path.read_text() + + +# 2. 解析HTML文件 +soup = BeautifulSoup(html_content, 'html.parser') + +# 3. 找到表格元素 +table = soup.find_all('table') # 假设页面中只有一个表格,如果有多个表格,可能需要进一步筛选 + +# 4. 提取表格数据 +data = [] +headers = [] + +# 提取表头 +header_row = table.find('thead').find('tr') +for header in header_row.find_all('th'): + headers.append(header.text.strip()) + +# 提取数据行 +for row in table.find('tbody').find_all('tr'): + row_data = [] + for cell in row.find_all(['td', 'th']): + row_data.append(cell.text.strip()) + data.append(row_data) + +# 5. 将数据保存为DataFrame +df = pd.DataFrame(data, columns=headers) + +# 6. 将DataFrame保存为CSV文件 +output_file = 'extracted_table.csv' +df.to_csv(output_file, index=False, encoding='utf-8') + +print(f'表格数据已成功提取并保存到 {output_file}') \ No newline at end of file diff --git a/source/dev_LaminaAdapter.py b/source/dev_LaminaAdapter.py index a5adfd9..f6f87f6 100644 --- a/source/dev_LaminaAdapter.py +++ b/source/dev_LaminaAdapter.py @@ -3,7 +3,8 @@ from pathlib import Path from typing import Callable, Any from device.LaminaAdapter import LaminaAdapter from device.LaminaAdapter import GeneratePackage_SLCP001_p4a0, GeneratePackage_SLCP101_p460, GeneratePackage_DLSY001_p460 -from device.tools.ByteConv import trans_list_to_str +from device.LaminaAdapter import GeneratePackage_SLCP102_p460 +from device.tools.ByteConv import trans_list_to_str, trans_str_to_list def test_communication(time_out=2): """ 通信成功率测试 """ @@ -140,8 +141,8 @@ if __name__=='__main__': # 'addr_645': [0x01, 0x02, 0x03, 0x04, 0x05, 0x06], 'frame_print': True, 'time_out': 0.1, 'retry': 1, 'retry_sub': 10}, - "HPLC": {'com_name': 'COM10', 'baudrate': 9600, 'parity': 'E', 'bytesize': 8, 'stopbits': 1, - # 'addr_645': [0x33, 0x00, 0x10, 0x03, 0x09, 0x24], + "HPLC": {'com_name': 'COM9', 'baudrate': 9600, 'parity': 'E', 'bytesize': 8, 'stopbits': 1, + # 'addr_645': [0x11, 0x01, 0x18, 0x06, 0x24, 0x02], 'frame_print': True, 'time_out': 3, 'time_gap': 0.1, 'retry': 3, 'retry_sub': 10}, } @@ -157,7 +158,7 @@ if __name__=='__main__': # file_hex = Path(r"D:\WorkingProject\LightStackOptimizer\software\lamina_optimizer\lamina_optimizer\Debug\lamina_optimizer.hex") if not file_hex.exists(): raise Exception("工程编译目标文件不存在.") - file_package = make_Pakeage(file_hex, GeneratePackage_SLCP101_p460) + file_package = make_Pakeage(file_hex, GeneratePackage_SLCP102_p460) version = "SLCP101_241030_2000_V2.03" addr = [0x24, 0x09, 0x12, 0x00, 0x00, 0x00] diff --git a/source/post_work.py b/source/post_work.py index ee170c7..e0a5c35 100644 --- a/source/post_work.py +++ b/source/post_work.py @@ -204,6 +204,6 @@ if __name__ == "__main__": path_main = Path(r"D:\WorkingProject\LightStackAdapter\software\lamina_adapter\lamina_adapter\Debug") # Process0(path_boot1, path_main) # 适配器SLCP001 - # Process1(path_boot2, path_main) # 适配器SLCP101 - Process1_v2(path_boot2, path_main) # 适配器SLCP102 + Process1(path_boot2, path_main) # 适配器SLCP101 + # Process1_v2(path_boot2, path_main) # 适配器SLCP102 # Process2()