diff --git a/source/data_analysis.py b/source/data_analysis.py index 7e3dc4f..5f9b745 100644 --- a/source/data_analysis.py +++ b/source/data_analysis.py @@ -14,32 +14,61 @@ from sqlalchemy import MetaData, Table, Column, String, Float, Integer API_URL = "https://energy-iot.chinatowercom.cn/api/device/device/historyPerformance" API_HEADER = { + "accept": "application/json, text/plain, */*", "Accept-Encoding": "gzip, deflate, br, zstd", + "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6", "Connection": "keep-alive", "Content-Length": "170", - "Cookie": "HWWAFSESTIME=1732496660747; HWWAFSESID=880ee8eff3a2d23536; dc04ed2361044be8a9355f6efb378cf2=WyIzNTI0NjE3OTgzIl0", - "authorization": "Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiIl0sInVzZXJfbmFtZSI6IndlYl9tYW5hZ2V8d2FuZ2xlaTQiLCJzY29wZSI6WyJhbGwiXSwiZXhwIjoxNzMyNTQ4Nzc5LCJ1c2VySWQiOjI0Mjg1LCJqdGkiOiI1Y2I3ZDA2ZC1hNzczLTQ5ZDQtYmRiMy05ZjdiOWNmMjY3ZTYiLCJjbGllbnRfaWQiOiJ3ZWJfbWFuYWdlIn0.Gpk9eYc3W4gcGLTG4aLSEL7E-VD-qPYsELcyyPuZ29e9STfa18WNcbosdIDulbH-5LDqY6i6aFAWpVm41bIgwzLZpAhlp2dthJcoBn9a90wWO4nz-Xi-MK9MVhNR0C28fyxv7h8jP_LRQkBi-pAzm2j65gkSTL3Vakky6znawZ5pY42U74lF-SnYdGyNFK3Ryy3xeMG4N1Pu_OJFdjXdGANUJZcXg1gh8WrERPo2SvuiCzOVTuUQZO7lRc8qGyILTKC-snz5CoonHaCWMaRzcV5VtCGd-yBncpyMQN9rGPqCiiLmuyTG29aZh5UfR_mloGCQHacqRmYSq3uGkPodBg", + "content-type": "application/json;charset=UTF-8", + "Cookie": "HWWAFSESID=455f2793ca86a3aaf0; HWWAFSESTIME=1734509454212; dc04ed2361044be8a9355f6efb378cf2=WyIyODM4MDM2MDcxIl0", + "authorization": "Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiIl0sInVzZXJfbmFtZSI6IndlYl9tYW5hZ2V8d2FuZ2xlaTQiLCJzY29wZSI6WyJhbGwiXSwiZXhwIjoxNzM0NjYzNDQ5LCJ1c2VySWQiOjI0Mjg1LCJqdGkiOiJhZmZhNmY1My05ZDA4LTQ2ODUtODU3MS05YzA5ODAxMGJjZWYiLCJjbGllbnRfaWQiOiJ3ZWJfbWFuYWdlIn0.q0X4qrgL4wRUTZL8c_5oTIUGW0Lsivxw8pYQ1iMIqLnyJrUeS7IQKNRavMhc4NEdQ9uG6ZgFVHIj80HbzH8DHCxssCPLdv9_TXksI5podU2aU6Vjh6AaN1THFYAE2uflj1saBnQ5_gKiK0-cAcXDeJNSt_u6Cd9hI1ejEUPPzO_hLg-NLzch7yIB-HPvhoDNnl0n5pSYoQpT8XaKT14HezL3VQrLII69Vme38S2dMmmkiAeIyhHQi56kXZ11K45Lu5bHXv6fDg2Mfr9VgVuTleZldiO69BAmG0h1-HqTQuGE39jtGWrrCnFduRZR6VsaOWWJy3qyqUbXWMOli1Yy1g", "Host": "energy-iot.chinatowercom.cn", "Origin": "https://energy-iot.chinatowercom.cn", "Sec-Fetch-Dest": "empty", "Sec-Fetch-Mode": "cors", "Sec-Fetch-Site": "same-origin", - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0", - "accept": "application/json, text/plain, */*", - "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6", - "content-type": "application/json;charset=UTF-8", "sec-ch-ua": "\"Microsoft Edge\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"", "sec-ch-ua-mobile": "?0", "sec-ch-ua-platform": "Windows", + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0", } -SemaMap = { - 'apt_temp': ('0305117001', 'adapter', "设备温度"), - 'apt_volt_in': ('0305118001', 'adapter', "输入电压"), - 'apt_curr_in': ('0305119001', 'adapter', "输入电流"), - 'apt_volt_out': ('0305120001', 'adapter', "输出电压"), - 'apt_curr_out': ('0305121001', 'adapter', "输出电流"), - 'apt_power_out': ('0305122001', 'adapter', "输出功率"), +SemaMap_adapter = { + 'facturer': ('0305113001', 'adapter', False, "厂家"), + 'version': ('0305114001', 'adapter', False, "软件版本"), + 'model': ('0305115001', 'adapter', False, "型号"), + 'status': ('0305116001', 'adapter', False, "开关机状态"), + 'temp': ('0305117001', 'adapter', True, "温度"), + 'volt_in': ('0305118001', 'adapter', True, "输入电压"), + 'curr_in': ('0305119001', 'adapter', True, "输入电流"), + 'volt_out': ('0305120001', 'adapter', True, "输出电压"), + 'curr_out': ('0305121001', 'adapter', True, "输出电流"), + 'power_out': ('0305122001', 'adapter', True, "输出功率"), +} +SemaMap_meter = { + 'mtr_id': ('0305123001', 'meter', False, "电表号"), + 'mtr_volt': ('0305124001', 'meter', True, "直流电压"), + 'mtr_curr': ('0436101001', 'meter', True, "直流总电流"), + 'mtr_power': ('0436102001', 'meter', True, "总有功功率"), + 'mtr_energy_total': ('0305125001', 'meter', True, "总有功电能"), + 'mtr_energy_daily': ('0305126001', 'meter', True, "日有功电能"), + 'mtr_energy_total_T': ('0305127001', 'meter', True, "尖时段总正向有功电能"), + 'mtr_energy_total_P': ('0305128001', 'meter', True, "峰时段总正向有功电能"), + 'mtr_energy_total_F': ('0305129001', 'meter', True, "平时段总正向有功电能"), + 'mtr_energy_total_V': ('0305130001', 'meter', True, "谷时段总正向有功电能"), + 'mtr_energy_daily_T': ('0305131001', 'meter', True, "尖时段日正向有功电能"), + 'mtr_energy_daily_P': ('0305132001', 'meter', True, "峰时段日正向有功电能"), + 'mtr_energy_daily_F': ('0305133001', 'meter', True, "平时段日正向有功电能"), + 'mtr_energy_daily_V': ('0305134001', 'meter', True, "谷时段日正向有功电能"), +} + +API_Map = { + 'search_dev': ['https://energy-iot.chinatowercom.cn/api/device/device/page', None], + 'dev_info': ['https://energy-iot.chinatowercom.cn/api/device/device/devInfo', None], + 'perf_real': ['https://energy-iot.chinatowercom.cn/api/device/device/perfReal', None], + 'history': ['https://energy-iot.chinatowercom.cn/api/device/device/historyPerformance', [SemaMap_adapter, SemaMap_meter]], + 'page': ['https://energy-iot.chinatowercom.cn/api/device/device/page', None], + 'station': ['https://energy-iot.chinatowercom.cn/api/device/station/detail/', None], } class Lamina_Data(object): @@ -60,6 +89,16 @@ class Lamina_Data(object): ) metadata.create_all(self.engine) + if 'log' not in metadata.tables: + log_table = Table( + 'log', metadata, + Column('dev', String(50)), + Column('mid', String(50)), + Column('Timestamp_start', Integer), + Column('Timestamp_end', Integer), + ) + metadata.create_all(self.engine) + self.data = { 'history': pd.read_sql_table('history', self.engine), } @@ -75,33 +114,34 @@ class Lamina_Data(object): data_memory = self.data['history'] data_file = pd.read_sql_table('history', self.engine) - # 合并新数据和现有数据 - combined_df = pd.concat([data_file, data_memory], ignore_index=True) - - # 通过 'dev', 'mid', 'time' 三列进行去重 - combined_df.drop_duplicates(subset=['dev', 'mid', 'time'], inplace=True) - - # 将去重后的数据插入数据库 - combined_df.to_sql('history', self.engine, if_exists='replace', index=False) + merged_df = pd.merge(data_memory, data_file[['dev', 'mid', 'time']], on=['dev', 'mid', 'time'], how='left', indicator=True) + filtered_data_memory = merged_df[merged_df['_merge'] == 'left_only'].drop(columns='_merge') + filtered_data_memory.to_sql('history', self.engine, if_exists='append', index=False) - print(f"成功插入 {len(combined_df)} 条数据") + print(f"成功插入 {len(filtered_data_memory)} 条数据") - return len(combined_df) + return len(filtered_data_memory) - def get_histoty_data(self, device_id, data_type, time_start:int, time_end:int): + def save_data(func): + """ 保存函数返回数据 """ + def wrapper(*args, **kwds): + self: Lamina_Data = args[0] + result = func(*args, **kwds) + if isinstance(result, pd.DataFrame): + self.data['history'] = pd.concat([self.data['history'], result], ignore_index=True) + self.save_history_data() + return result + return wrapper + + def get_histoty_data_by_database(self, device_id, data_type, time_start:int, time_end:int): """ 读取历史数据 """ - flag = 0 - time_Interval = 20 * 60 database = self.data['history'] filter_data = database[database['dev'] == device_id & - database['mid'] == SemaMap[data_type][0] & + database['mid'] == SemaMap_adapter[data_type][0] & database['time'].between(time_start, time_end)] - if filter_data.shape[1] == 0 or (filter_data['time'].min() - time_start > time_Interval) or (time_end - filter_data['time'].max() > time_Interval): - """ 需要从网页获取数据 """ - flag = 1 - return filter_data + @save_data def get_history_data_by_net(self, device_id, data_type, time_start:int, time_end:int, header=None): """ 读取信号量历史数据, 返回接口json数据 """ if header is None: @@ -122,38 +162,163 @@ class Lamina_Data(object): json_data = req.json() if json_data['code'] == 200: """ 数据读取成功 """ - print(f"Get data success, len={len(json_data['data'])}") + print(f"Get data success, mid={data_type[0]}, len={len(json_data['data'])}") table_data = pd.DataFrame(json_data['data'], columns=['collectTime', 'mid', 'midName', 'value']) table_data['time'] = table_data['collectTime'].apply(lambda x: int(time.mktime(time.strptime(x, r"%Y-%m-%d %H:%M:%S")))) table_data['dev'] = device_id return table_data[['dev', 'mid', 'time', 'value']] else: - print(f"Get data fail, code={json_data['code']}, msg=\n\t{json_data['msg']}") + print(f"Get data fail, code={json_data['code']}, msg=\n\t{json_data['message']}") return pd.DataFrame([], columns=['dev', 'mid', 'time', 'value']) + def get_real_data_by_net(self, device_id, fsu_id=None, header=None): + """ 读取设备当前数据, 返回接口json数据 """ + if header is None: + header = self.api_origin['header'] + + body = { + "businessType": "7", + "devType": device_id[3:7], + "deviceCodes": device_id, + "type": "遥测" + } + + if device_id[3:7] != "0101": + if fsu_id is None: + raise ValueError(f"Missing required parameters: fsu_id={fsu_id}") + body["fsuCode"] = fsu_id + + req = requests.post(API_Map['perf_real'][0], json=body, headers=header) + json_data = req.json() + if json_data['code'] == 200: + """ 数据读取成功 """ + print(f"Get data success, len={len(json_data['data'])}") + table_data = pd.DataFrame(json_data['data']) + column_name = sorted(table_data.columns) + table_data['time'] = table_data['updateTime'].apply(lambda x: int(time.mktime(time.strptime(x, r"%Y-%m-%d %H:%M:%S")))) + table_data = table_data[['time', *column_name]].drop(columns='updateTime') + return table_data + else: + print(f"Get data fail, code={json_data['code']}, msg=\n\t{json_data['message']}") + return pd.DataFrame([]) + + def get_devinfo_data_by_net(self, device_id, data_type, time_start:int, time_end:int, header=None): + """ 读取设备信息, 返回接口json数据 """ + if header is None: + header = self.api_origin['header'] + + body = { + "businessType": "7", + "id": int(data_type), + } + + req = requests.post(API_Map['dev_info'][0], json=body, headers=header) + json_data = req.json() + if json_data['code'] == 200: + """ 数据读取成功 """ + print(f"Get data success, len={len(json_data['data'])}") + table_data = pd.DataFrame(json_data['data']) + return table_data + else: + print(f"Get data fail, code={json_data['code']}, msg=\n\t{json_data['message']}") + return pd.DataFrame([], columns=['dev', 'mid', 'time', 'value']) + + def spider_adapter(self, device_id:str, time_start:int, time_end:int): + """ 爬取适配器数据 """ + result = {} + columns_adapter = list(filter(lambda x: SemaMap_adapter[x][2], SemaMap_adapter.keys())) + data_adapter = pd.DataFrame([], columns=['time', *columns_adapter]) + for k in columns_adapter: + result[k] = self.get_history_data_by_net(device_id, SemaMap_adapter[k], time_start, time_end) + if data_adapter.empty: + data_adapter.time = result[k].time + data_adapter[k] = result[k].value.apply(float) + return data_adapter + + def spider_meter(self, device_id:str, time_start:int, time_end:int): + """ 爬取电表数据 """ + result = {} + columns_meter = list(map(lambda x: x[4:], filter(lambda x: SemaMap_meter[x][2], SemaMap_meter.keys()))) + data_meter = pd.DataFrame([], columns=['time', *columns_meter]) + for k, v in SemaMap_meter.items(): + if v[2]: + result[k] = self.get_history_data_by_net(device_id, v, time_start, time_end) + if data_meter.empty: + data_meter.time = result[k].time + data_meter[k[4:]] = result[k].value.apply(float) + return data_meter + + def spider_station(self, device_id:str, time_start:int, time_end:int, header=None): + """ 爬取站点数据 """ + if header is None: + header = self.api_origin['header'] + + body = { + "devType": "", + "accessPointId": "", + "pageNum": 1, + "pageSize": 10, + "businessType": "7", + "devCode": device_id, + "deptIds": [] + } + + req = requests.post(API_Map['search_dev'][0], json=body, headers=header) + json_data = req.json() + if json_data['code'] != 200: + """ 数据读取失败 """ + print(f"Get data fail, code={json_data['code']}, msg=\n\t{json_data['message']}") + return pd.DataFrame([]) + elif search_dev := json_data['rows']: + print(f"Search device success, len={len(search_dev)}") + station_id = search_dev[0]['stationCode'] + else: + print(f"Search device fail.") + return pd.DataFrame([]) + + body = { + "businessType": "7", + "stationCode": station_id, + } + time.sleep(0.5) + print(f"Get Data for Station: {station_id}") + req = requests.post(API_Map['page'][0], json=body, headers=header) + json_data = req.json() + for dev in sorted(json_data['rows'], key=lambda x: x['devCode']): + print(f"Dev: {dev['devTypeName']}, id={dev['devCode']}") + time.sleep(0.5) + fsu_id = dev['parentCode'] if 'parentCode' in dev.keys() else None + self.get_real_data_by_net(dev['devCode'], fsu_id, header=header) + time.sleep(0.5) + match dev['devType']: + case "0101": + fsu_id = dev['devCode'] + case "0102": + self.spider_adapter(dev['devCode'], time_start, time_end) + case "0103": + self.spider_meter(dev['devCode'], time_start, time_end) + print(f"Station Done.") + + def spider(self, device_id:str, time_start:int, time_end:int): + """ 通用爬虫 """ + if device_id[:8] == "TTE0102DX": + """ 适配器数据 """ + self.spider_adapter(device_id, time_start, time_end) + elif device_id[:8] == "TTE0103DX": + """ 电表数据 """ + self.spider_meter(device_id, time_start, time_end) + def graphs_adapter(self, device_id, time_start:int|str, time_end:int|str): """ 绘制图表-适配器数据 """ if type(time_start) is str: time_start = time.mktime(time.strptime(time_start, r"%Y-%m-%d %H:%M:%S")) if type(time_end) is str: time_end = time.mktime(time.strptime(time_end, r"%Y-%m-%d %H:%M:%S")) - data_volt_in = self.get_history_data_by_net(device_id, SemaMap["apt_volt_in"], time_start, time_end) - data_curr_in = self.get_history_data_by_net(device_id, SemaMap["apt_curr_in"], time_start, time_end) - data_volt_out = self.get_history_data_by_net(device_id, SemaMap["apt_volt_out"], time_start, time_end) - data_power_out = self.get_history_data_by_net(device_id, SemaMap["apt_power_out"], time_start, time_end) + data = self.spider_adapter(device_id, time_start, time_end) - combined_df = pd.concat([data_volt_in, data_curr_in, data_volt_out, data_power_out], ignore_index=True) - self.data['history'] = pd.concat([self.data['history'], combined_df], ignore_index=True) - self.save_history_data() + self.chart_adapter(data) - data_adapter = pd.DataFrame([], columns=['time', 'volt_in', 'volt_out', 'curr_in', 'power_out']) - data_adapter.time = data_volt_in.time - data_adapter.volt_in = data_volt_in.value - data_adapter.volt_out = data_volt_out.value - data_adapter.curr_in = data_curr_in.value - data_adapter.power_out = data_power_out.value - - return data_adapter + return data def chart_adapter(self, data_adapter): """ 绘制适配器信息图表 """ @@ -204,15 +369,30 @@ def sim_data_apt(times:tuple[int, int]): if __name__=='__main__': - - # API_HEADER['authorization'] = 'Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiIl0sInVzZXJfbmFtZSI6IndlYl9tYW5hZ2V8d2FuZ2xlaTQiLCJzY29wZSI6WyJhbGwiXSwiZXhwIjoxNzMyNTQzMzIyLCJ1c2VySWQiOjI0Mjg1LCJqdGkiOiI2MGZlZjYxNC0zM2QyLTQ5NjMtYjM5Mi1mNTJlYzJhM2RmYTEiLCJjbGllbnRfaWQiOiJ3ZWJfbWFuYWdlIn0.jumI9T8swSPCKITrCU06DWRea0tpvwCidw6jFP-F26JH0fRCp801fbzPs5kHkrgh-sm_ayzO2mD9NCkC2hoC-YDQs8HCvXHZXwtYpn3qJ6vpWRQrMr8Vwk8HnuxbFUn-8Ccs88hHOa8rtrEVsglfl0gqU1C8LL1rsHxgYI3MAwwU_eHo74jNjSHuIn79iq4Gyxc6lial6Pb6WWOw1erqKRGRQPcfUtAXMjwXbQ03vFk6G-As_u353yKvznsGR4A70hFHkJJGugK3en8kJO3_g3sE6ddcx0CYicucRLckro4Md_S8mIPkw2RgGEK38vvEo2fqiyT8E67dC5D4_zMw5A' - data_lamina = Lamina_Data('sqlite:///result/chinatowercom.db') + """ 主体调用流程 """ + if hasattr(__builtins__,"__IPYTHON__"): + path_db = '../result/chinatowercom.db' + else: + path_db = 'result/chinatowercom.db' + + API_HEADER['Cookie'] = "HWWAFSESTIME=1735108780906; HWWAFSESID=1c91597e07b0014c4d; dc04ed2361044be8a9355f6efb378cf2=WyIzNTI0NjE3OTgzIl0" + API_HEADER['authorization'] = 'Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiIl0sInVzZXJfbmFtZSI6IndlYl9tYW5hZ2V8d2FuZ2xlaTQiLCJzY29wZSI6WyJhbGwiXSwiZXhwIjoxNzM1MjI2NDAyLCJ1c2VySWQiOjI0Mjg1LCJqdGkiOiJmNzA1ZTlkZC1mNTA5LTQwYzUtODFhNi0zYzdlMzhhZjE0ODgiLCJjbGllbnRfaWQiOiJ3ZWJfbWFuYWdlIn0.e8p-hKWoFyLJbtqKEvlIbLpz-_OB7Ak32d8qdTHNZEny12lUrUE0YYrWQTu0gGtT-eRNDJ62q51IUYOkM_5Ou0Qk2HLouR9-iygtgtjIno72466bv_ao5wvD2PZihXKaKet_c9mnpOqDpvaaApAU4_rk0u6Pg7uJG4stV-akaaMMqRLR-cK5ARePeyHophyGUx80kkSlnhYfGP2rJjEFva36iPaCzM6oiezObMoXWtAPw67vPS-5saTWnjYLrzxr3_s5Idk1pwWPNWfSa6Rl_YMKKiTdtWAEepyrxxOWVfMaeAQYt-ndHhxyBPjRluDTSwUViWmDidoFxkKPMQixVw' + data_lamina = Lamina_Data('sqlite:///' + path_db) + + today = datetime.datetime.today() + yesterday = today - datetime.timedelta(days=1) + today_midnight = today.replace(hour=0, minute=0, second=0, microsecond=0) + yesterday_midnight = yesterday.replace(hour=0, minute=0, second=0, microsecond=0) + today_midnight_timestamp = time.mktime(today_midnight.timetuple()) + yesterday_midnight_timestamp = time.mktime(yesterday_midnight.timetuple()) + + # 依据站点内设备爬取整个站点的实时与历史数据 + data = data_lamina.spider_station('TTE0102DX2406272727', yesterday_midnight_timestamp, today_midnight_timestamp) # data = sim_data_apt(('2024-10-1 00:00:00', '2024-10-1 12:00:00')) # chart_apt(data) - table_apt = data_lamina.graphs_adapter('TTE0102DX2406180988', '2024-11-23 00:00:00', '2024-11-26 00:00:00') - - data_lamina.chart_adapter(table_apt) - while True: - plt.waitforbuttonpress() + if not hasattr(__builtins__,"__IPYTHON__"): + table_apt = data_lamina.graphs_adapter('TTE0102DX2406180988', '2024-11-23 00:00:00', '2024-11-26 00:00:00') + while True: + plt.waitforbuttonpress() diff --git a/source/dev_LaminaAdapter.ipynb b/source/dev_LaminaAdapter.ipynb new file mode 100644 index 0000000..2a2ed8a --- /dev/null +++ b/source/dev_LaminaAdapter.ipynb @@ -0,0 +1,1466 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 环境设置\n", + "1. 输出电压设置58V\n", + "2. 输入源设置光伏模式, Vmppt=42V, Power=650W\n", + "3. 初始化设备;" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import time\n", + "from pathlib import Path\n", + "from device.LaminaAdapter import LaminaAdapter\n", + "from device.LaminaAdapter import GeneratePackage_SLCP001_p4a0, GeneratePackage_SLCP101_p460, GeneratePackage_DLSY001_p460\n", + "from device.LaminaAdapter import GeneratePackage_SLCP102_p460\n", + "from device.tools.ByteConv import trans_list_to_str, trans_str_to_list" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "mode_config = {\n", + " \"Log\": {'com_name': None, \n", + " # 'addr_645': [0x01, 0x00, 0x00, 0x00, 0x00, 0x40], \n", + " },\n", + " \"Debug\": {'com_name': 'COM3', 'baudrate': 115200, 'parity': 'N', 'bytesize': 8, 'stopbits': 1,\n", + " # 'addr_645': [0x01, 0x02, 0x03, 0x04, 0x05, 0x06], \n", + " 'frame_print': True, \n", + " 'time_out': 0.5, 'retry': 1, 'retry_sub': 10},\n", + " \"HPLC\": {'com_name': 'COM9', 'baudrate': 9600, 'parity': 'E', 'bytesize': 8, 'stopbits': 1,\n", + " 'addr_645': trans_str_to_list(\"02 01 00 00 24 20\"), \n", + " 'frame_print': True, \n", + " 'time_out': 3, 'time_gap': 0.1, 'retry': 3, 'retry_sub': 10},\n", + "}\n", + "\n", + "dev_lamina = LaminaAdapter(type_dev=\"SLCP101\", **mode_config['Debug'])" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "def test_communication(time_out=2):\n", + " \"\"\" 通信成功率测试 \"\"\"\n", + " time_start = time.time()\n", + " param_saved = dev_lamina.flag_print, dev_lamina.retry, dev_lamina.time_out\n", + " dev_lamina.flag_print = False\n", + " dev_lamina.retry = 1\n", + " try:\n", + " while True:\n", + " dev_lamina.frame_read(0x0C, 0x20)\n", + " print(f\"Time Stamp: {time.ctime()}\")\n", + " print(f\"Success Frame: {dev_lamina.log['read']}\")\n", + " print(f\"Failed Frame: {dev_lamina.log['send'] - dev_lamina.log['read']}\")\n", + " print(f\"Max Series Failed Frame: {dev_lamina.log['keep-fail']}\")\n", + " time.sleep(time_out)\n", + " finally:\n", + " time_end = time.time()\n", + " print(\"Test Result: \")\n", + " print(f\"Time Start: {time.strftime(r'%Y-%m-%d %H:%M:%S', time.localtime(time_start))}, \\tTime End: {time.strftime(r'%Y-%m-%d %H:%M:%S', time.localtime(time_end))}\")\n", + " print(f\"Time Elapsed: {time_end - time_start}\")\n", + " print(f\"Success Rate: {dev_lamina.log['read'] / dev_lamina.log['send'] * 100}%\")\n", + " dev_lamina.flag_print, dev_lamina.retry, dev_lamina.time_out = param_saved" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Send Frame: 68 AA AA AA AA AA AA 68 1F 08 01 03 01 00 00 20 45 EE 4B 16\n", + "Read Frame: 68 01 02 03 04 05 06 68 9F 45 01 03 40 48 46 45 43 30 30 5F 31 34 32 31 31 37 30 31 5F 30 37 5F 30 33 56 30 2E 00 31 00 00 00 00 00 00 48 46 45 43 30 30 00 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 BF A8 EE 16\n", + "Parse Result:\n", + "0x0100: FHCE001_241107_1700_V3.01\u0000\u0000\u0000\u0000\u0000\u0000\u0000 版本(ODM)\n", + "0x0110: FHCE001\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000 型号 \n" + ] + }, + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dev_lamina.frame_read(0x0100, 0x20)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 设备升级" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 单次升级" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Package generated successfully.\n", + "File name: lamina_adapter.hex\n", + "File Info:\n", + "\t header_length=184, bin_length=127750[0x1f306]\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "File Transmitting: 100%|██████████| 592/592 [00:27<00:00, 21.20it/s]\n" + ] + }, + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# 工程-即时转换\n", + "if dev_lamina.device == 'SLCP001':\n", + " file_hex = Path(r\"D:\\WorkingProject\\LightStackAdapter\\software\\lamina_adapter\\release\\device_V1\\lamina_adapter\\Debug\\lamina_adapter.hex\")\n", + "elif dev_lamina.device == 'SLCP101':\n", + " file_hex = Path(r\"D:\\WorkingProject\\LightStackAdapter\\software\\lamina_adapter\\release\\device_V2.03\\lamina_adapter\\Debug\\lamina_adapter.hex\")\n", + "elif dev_lamina.device == 'SLCP102':\n", + " file_hex = Path(r\"D:\\WorkingProject\\LightStackAdapter\\software\\lamina_adapter\\release\\device_V3.01\\lamina_adapter\\Debug\\lamina_adapter.hex\")\n", + "elif dev_lamina.device == 'DLSY001':\n", + " file_hex = Path(r\"D:\\WorkingProject\\LightStackOptimizer\\software\\lamina_optimizer\\lamina_optimizer\\Debug\\lamina_optimizer.hex\")\n", + "else:\n", + " file_hex = Path(r\"D:\\WorkingProject\\LightStackAdapter\\software\\lamina_adapter\\lamina_adapter\\Debug\\lamina_adapter.hex\")\n", + "if not file_hex.exists():\n", + " raise Exception(\"工程编译目标文件不存在.\")\n", + "\n", + "dev_lamina.frame_update(file_hex, makefile=True)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 连续升级" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# 工程-即时转换\n", + "if dev_lamina.device == 'SLCP001':\n", + " file_hex = Path(r\"D:\\WorkingProject\\LightStackAdapter\\software\\lamina_adapter\\release\\device_V1\\lamina_adapter\\Debug\\lamina_adapter.hex\")\n", + "elif dev_lamina.device == 'SLCP101':\n", + " file_hex = Path(r\"D:\\WorkingProject\\LightStackAdapter\\software\\lamina_adapter\\release\\device_V2.03\\lamina_adapter\\Debug\\lamina_adapter.hex\")\n", + "elif dev_lamina.device == 'SLCP102':\n", + " file_hex = Path(r\"D:\\WorkingProject\\LightStackAdapter\\software\\lamina_adapter\\release\\device_V3.01\\lamina_adapter\\Debug\\lamina_adapter.hex\")\n", + "elif dev_lamina.device == 'DLSY001':\n", + " file_hex = Path(r\"D:\\WorkingProject\\LightStackOptimizer\\software\\lamina_optimizer\\lamina_optimizer\\Debug\\lamina_optimizer.hex\")\n", + "else:\n", + " file_hex = Path(r\"D:\\WorkingProject\\LightStackAdapter\\software\\lamina_adapter\\lamina_adapter\\Debug\\lamina_adapter.hex\")\n", + "if not file_hex.exists():\n", + " raise Exception(\"工程编译目标文件不存在.\")\n", + "print(dev_lamina.device)\n", + "print(file_hex)\n", + "\n", + "# 设置升级配置\n", + "version = \"SLCP101_241030_2000_V2.03\"\n", + "addr = [0x24, 0x09, 0x12, 0x00, 0x00, 0x00]\n", + "dev_lamina.flag_print = False" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "while True:\n", + " \"\"\" 自动检测升级流程 \"\"\"\n", + " ret = False\n", + " while not (ret and ('Regs' in dev_lamina.output.keys()) and \n", + " (version == dev_lamina.output['Regs'][0x0100][1].strip('\\000'))):\n", + " # dev_lamina.frame_read(0x82, 3)\n", + " ret = dev_lamina.frame_read(0x0100, 0x20)\n", + " time.sleep(1)\n", + "\n", + " dev_lamina.frame_update(file_hex, makefile=True)\n", + "\n", + " time.sleep(3)\n", + "\n", + " ret = dev_lamina.frame_read(0x0100, 0x20)\n", + "\n", + " if ret and (version == dev_lamina.output['Regs'][0x0100][1]):\n", + " dev_lamina.frame_write_one(0x52, 0x01)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 参数还原" + ] + }, + { + "cell_type": "code", + "execution_count": 166, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Send Frame: 68 AA AA AA AA AA AA 68 1F 08 01 06 00 52 00 01 E9 DB 11 16\n", + "Read Frame: 68 16 95 11 16 06 24 68 9F 08 01 06 00 52 00 01 E9 DB 91 16\n", + "Send Frame: 68 AA AA AA AA AA AA 68 1F 08 01 06 00 53 00 01 B8 1B 21 16\n", + "Read Frame: 68 16 95 11 16 06 24 68 9F 08 01 06 00 53 00 01 B8 1B A1 16\n" + ] + }, + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 166, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dev_lamina.frame_write_one(0x52, 0x01)\n", + "time.sleep(4.5)\n", + "dev_lamina.frame_write_one(0x53, 0x01)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 读取设备状态" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Send Frame: 68 AA AA AA AA AA AA 68 1F 08 01 03 00 60 00 60 45 FC F8 16\n", + "Read Frame: 68 01 02 03 04 05 06 68 9F C5 01 03 C0 00 00 00 79 02 62 00 5A 02 6C 00 64 02 1C 01 CC 02 3A 01 A4 02 44 02 94 02 58 01 B8 09 60 07 D0 00 0A 08 98 02 3A 02 35 02 21 04 1A 03 B6 03 52 01 5E 02 30 AE 60 00 0A 03 E8 00 00 EB 10 00 09 EB 10 00 09 05 06 03 04 01 02 09 C4 FE 0C 00 64 00 00 00 64 00 0D 03 96 00 96 C3 50 00 00 00 C8 00 00 00 FA 00 00 00 14 00 00 00 02 00 00 03 E8 00 00 03 E8 00 00 03 E8 00 00 03 E8 00 00 03 E8 00 00 00 00 00 00 00 00 03 E8 37 E2 2D BE 02 23 00 00 0C AD 03 FF FF FF FF FF FF FF FF FF FF FF 4C 53 50 43 30 31 5F 32 34 32 31 31 37 30 31 5F 30 37 5F 30 33 56 30 2E 00 31 00 00 00 00 00 00 99 46 20 16\n", + "Parse Result:\n", + "0x0060: 0x0000 光伏通道使能 \n", + "0x0061: 12.1 最小启动输入电压 \n", + "0x0062: 61.0 最大启动输入电压 \n", + "0x0063: 9.0 最小停止输入电压 \n", + "0x0064: 62.0 最大停止输入电压 \n", + "0x0065: 10.0 最小MPPT电压 \n", + "0x0066: 54.0 最大MPPT电压 \n", + "0x0067: 46.0 最小启动输出电压 \n", + "0x0068: 57.0 最大启动输出电压 \n", + "0x0069: 42.0 最小停止输出电压 \n", + "0x006A: 58.0 最大停止输出电压 \n", + "0x006B: 66.0 输入过压保护值 \n", + "0x006C: 60.0 输出过压保护值 \n", + "0x006D: 44.0 输出欠压保护值 \n", + "0x006E: 24.0 电感过流保护值 \n", + "0x006F: 20.0 输入过流保护值 \n", + "0x0070: 0.1 最小电感电流限值 \n", + "0x0071: 22.0 最大电感电流限值 \n", + "0x0072: 57.0 浮充电压阈值 \n", + "0x0073: 56.5 三点法中间阈值 \n", + "0x0074: 54.5 恒压充电电压 \n", + "0x0075: 105.0 过温故障值 \n", + "0x0076: 95.0 过温告警值 \n", + "0x0077: 85.0 温度恢复值 \n", + "0x0078: 35.0 最低满载电压 \n", + "0x0079: 56.0 最高满载电压 \n", + "0x007A: 700.0 输入过载保护值 \n", + "0x007C: 1.0 最小功率限值 \n", + "0x007E: 650.0 最大功率限值 \n", + "0x0080: 650.0 最大功率限值存储值 \n", + "0x0082: 06 05 04 03 02 01 载波通信地址 \n", + "0x0085: 25.0 电压环out_max \n", + "0x0086: -5.0 电压环out_min \n", + "0x0087: 1.0 电流环out_max \n", + "0x0088: 0.0 电流环out_min \n", + "0x0089: 1.0 MPPT扰动系数k_d_vin \n", + "0x008A: 0.013 dmin \n", + "0x008B: 0.918 dmax \n", + "0x008C: 15.0 扫描电压偏移scanvolt_offset\n", + "0x008D: 0.5 电压环Kp \n", + "0x008F: 0.002 电压环Ki \n", + "0x0091: 0.0025 电流环Kp \n", + "0x0093: 0.0002 电流环Ki \n", + "0x0095: 0x0002 日志级别 \n", + "0x0096: 0x0000 日志输出方式 \n", + "0x0097: 1.0 采样校准volt_in_a \n", + "0x0098: 0.0 采样校准volt_in_b \n", + "0x0099: 1.0 采样校准volt_out_a \n", + "0x009A: 0.0 采样校准volt_out_b \n", + "0x009B: 1.0 采样校准curr_in_a \n", + "0x009C: 0.0 采样校准curr_in_b \n", + "0x009D: 1.0 采样校准curr_induc_a \n", + "0x009E: 0.0 采样校准curr_induc_b \n", + "0x009F: 1.0 采样校准volt_12V_a \n", + "0x00A0: 0.0 采样校准volt_12V_b \n", + "0x00A1: 0.0 温度补偿temp1_b \n", + "0x00A2: 0.0 温度补偿temp2_b \n", + "0x00A3: 0 系统工作模式 \n", + "0x00A4: 10.0 电感电流给定值curr_set \n", + "0x00A5: 143.06 抖动频率上限 \n", + "0x00A6: 117.1 抖动频率下限 \n", + "0x00A7: 54.7 电池电压判断限值 \n", + "0x00A8: 0x0000 MPPT追踪模式 \n", + "0x00A9: 3.245 ADC参考电压 \n", + "0x00AA: 0x03FF 保留 \n", + "0x00AB: 0xFFFF 保留 \n", + "0x00AC: 0xFFFF 保留 \n", + "0x00AD: 0xFFFF 保留 \n", + "0x00AE: 0xFFFF 保留 \n", + "0x00AF: 0xFFFF 保留 \n", + "0x00B0: SLCP102_241107_1700_V3.01\u0000\u0000\u0000\u0000\u0000\u0000\u0000 版本 \n", + "Send Frame: 68 AA AA AA AA AA AA 68 1F 08 01 03 00 0E 00 20 25 D1 1B 16\n", + "Read Frame: 68 01 02 03 04 05 06 68 9F 2D 01 03 28 20 30 00 00 00 00 00 04 00 00 00 73 00 05 00 40 00 10 00 05 00 5E 01 27 00 00 00 00 01 27 00 00 02 1C AE 60 00 0A 02 35 5B E2 56 16\n", + "Parse Result:\n", + "0x000E: 0x2030 故障字1 \n", + "0x000F: 0x0000 故障字2 \n", + "0x0010: 0x0000 MPPT工作状态 \n", + "0x0011: 0x0004 系统工作状态 \n", + "0x0012: 0x0000 系统工作模式 \n", + "0x0013: 11.5 输入电压 \n", + "0x0014: 0.05 电感电流 \n", + "0x0015: 6.4 12V电压 \n", + "0x0016: 1.6 输出电压 \n", + "0x0017: 0.05 输入电流 \n", + "0x0018: 9.4 温度1 \n", + "0x0019: 29.5 温度2 \n", + "0x001A: 0.0 输入功率 \n", + "0x001C: 29.5 设备温度 \n", + "0x001D: 0x0000 开关机状态 \n", + "0x001E: 54.0 电池电压 \n", + "0x001F: 700.0 并机功率限值 \n", + "0x0021: 56.5 输出限功率电压阈值\n" + ] + }, + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dev_lamina.frame_read(0x60, 0x60)\n", + "time.sleep(0.5)\n", + "dev_lamina.frame_read(0x0E, 0x20)" + ] + }, + { + "cell_type": "code", + "execution_count": 164, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Parse Result:\n", + "0x000C: 0xFFFF 未知数据 \n", + "0x000D: 0xFFFF 未知数据 \n", + "0x000E: 0x0000 故障字1 \n", + "0x000F: 0x0000 故障字2 \n", + "0x0010: 0x0000 MPPT工作状态 \n", + "0x0011: 0x0000 系统工作状态 \n", + "0x0012: 0x0000 系统工作模式 \n", + "0x0013: 5.6 输入电压 \n", + "0x0014: 0.0 电感电流 \n", + "0x0015: 11.1 12V电压 \n", + "0x0016: 57.2 输出电压 \n", + "0x0017: 0.01 输入电流 \n", + "0x0018: 20.9 温度1 \n", + "0x0019: 22.0 温度2 \n", + "0x001A: 0.0 输入功率 \n", + "0x001C: 22.0 设备温度 \n", + "0x001D: 0x0000 开关机状态 \n", + "0x001E: 54.0 电池电压 \n", + "0x001F: 700.0 并机功率限值 \n", + "0x0021: 56.5 输出限功率电压阈值\n", + "Time Stamp: Mon Dec 16 15:44:58 2024\n", + "Success Frame: 4\n", + "Failed Frame: 0\n", + "Max Series Failed Frame: 0\n", + "Parse Result:\n", + "0x000C: 0xFFFF 未知数据 \n", + "0x000D: 0xFFFF 未知数据 \n", + "0x000E: 0x0000 故障字1 \n", + "0x000F: 0x0000 故障字2 \n", + "0x0010: 0x0000 MPPT工作状态 \n", + "0x0011: 0x0000 系统工作状态 \n", + "0x0012: 0x0000 系统工作模式 \n", + "0x0013: 5.6 输入电压 \n", + "0x0014: 0.0 电感电流 \n", + "0x0015: 11.1 12V电压 \n", + "0x0016: 57.2 输出电压 \n", + "0x0017: 0.01 输入电流 \n", + "0x0018: 20.9 温度1 \n", + "0x0019: 22.0 温度2 \n", + "0x001A: 0.0 输入功率 \n", + "0x001C: 22.0 设备温度 \n", + "0x001D: 0x0000 开关机状态 \n", + "0x001E: 54.0 电池电压 \n", + "0x001F: 700.0 并机功率限值 \n", + "0x0021: 56.5 输出限功率电压阈值\n", + "Time Stamp: Mon Dec 16 15:45:00 2024\n", + "Success Frame: 5\n", + "Failed Frame: 0\n", + "Max Series Failed Frame: 0\n", + "Parse Result:\n", + "0x000C: 0xFFFF 未知数据 \n", + "0x000D: 0xFFFF 未知数据 \n", + "0x000E: 0x0000 故障字1 \n", + "0x000F: 0x0000 故障字2 \n", + "0x0010: 0x0000 MPPT工作状态 \n", + "0x0011: 0x0000 系统工作状态 \n", + "0x0012: 0x0000 系统工作模式 \n", + "0x0013: 5.6 输入电压 \n", + "0x0014: 0.0 电感电流 \n", + "0x0015: 11.1 12V电压 \n", + "0x0016: 57.2 输出电压 \n", + "0x0017: 0.01 输入电流 \n", + "0x0018: 20.9 温度1 \n", + "0x0019: 22.0 温度2 \n", + "0x001A: 0.0 输入功率 \n", + "0x001C: 22.0 设备温度 \n", + "0x001D: 0x0000 开关机状态 \n", + "0x001E: 54.0 电池电压 \n", + "0x001F: 700.0 并机功率限值 \n", + "0x0021: 56.5 输出限功率电压阈值\n", + "Time Stamp: Mon Dec 16 15:45:02 2024\n", + "Success Frame: 6\n", + "Failed Frame: 0\n", + "Max Series Failed Frame: 0\n", + "Parse Result:\n", + "0x000C: 0xFFFF 未知数据 \n", + "0x000D: 0xFFFF 未知数据 \n", + "0x000E: 0x0000 故障字1 \n", + "0x000F: 0x0000 故障字2 \n", + "0x0010: 0x0000 MPPT工作状态 \n", + "0x0011: 0x0000 系统工作状态 \n", + "0x0012: 0x0000 系统工作模式 \n", + "0x0013: 5.6 输入电压 \n", + "0x0014: 0.0 电感电流 \n", + "0x0015: 11.1 12V电压 \n", + "0x0016: 57.2 输出电压 \n", + "0x0017: 0.01 输入电流 \n", + "0x0018: 20.9 温度1 \n", + "0x0019: 22.0 温度2 \n", + "0x001A: 0.0 输入功率 \n", + "0x001C: 22.0 设备温度 \n", + "0x001D: 0x0000 开关机状态 \n", + "0x001E: 54.0 电池电压 \n", + "0x001F: 700.0 并机功率限值 \n", + "0x0021: 56.5 输出限功率电压阈值\n", + "Time Stamp: Mon Dec 16 15:45:04 2024\n", + "Success Frame: 7\n", + "Failed Frame: 0\n", + "Max Series Failed Frame: 0\n", + "Parse Result:\n", + "0x000C: 0xFFFF 未知数据 \n", + "0x000D: 0xFFFF 未知数据 \n", + "0x000E: 0x0000 故障字1 \n", + "0x000F: 0x0000 故障字2 \n", + "0x0010: 0x0000 MPPT工作状态 \n", + "0x0011: 0x0000 系统工作状态 \n", + "0x0012: 0x0000 系统工作模式 \n", + "0x0013: 5.6 输入电压 \n", + "0x0014: 0.0 电感电流 \n", + "0x0015: 11.1 12V电压 \n", + "0x0016: 57.2 输出电压 \n", + "0x0017: 0.01 输入电流 \n", + "0x0018: 20.9 温度1 \n", + "0x0019: 22.0 温度2 \n", + "0x001A: 0.0 输入功率 \n", + "0x001C: 22.0 设备温度 \n", + "0x001D: 0x0000 开关机状态 \n", + "0x001E: 54.0 电池电压 \n", + "0x001F: 700.0 并机功率限值 \n", + "0x0021: 56.5 输出限功率电压阈值\n", + "Time Stamp: Mon Dec 16 15:45:06 2024\n", + "Success Frame: 8\n", + "Failed Frame: 0\n", + "Max Series Failed Frame: 0\n", + "Parse Result:\n", + "0x000C: 0xFFFF 未知数据 \n", + "0x000D: 0xFFFF 未知数据 \n", + "0x000E: 0x0000 故障字1 \n", + "0x000F: 0x0000 故障字2 \n", + "0x0010: 0x0000 MPPT工作状态 \n", + "0x0011: 0x0000 系统工作状态 \n", + "0x0012: 0x0000 系统工作模式 \n", + "0x0013: 5.6 输入电压 \n", + "0x0014: 0.0 电感电流 \n", + "0x0015: 11.1 12V电压 \n", + "0x0016: 57.2 输出电压 \n", + "0x0017: 0.01 输入电流 \n", + "0x0018: 20.9 温度1 \n", + "0x0019: 22.1 温度2 \n", + "0x001A: 0.0 输入功率 \n", + "0x001C: 22.1 设备温度 \n", + "0x001D: 0x0000 开关机状态 \n", + "0x001E: 54.0 电池电压 \n", + "0x001F: 700.0 并机功率限值 \n", + "0x0021: 56.5 输出限功率电压阈值\n", + "Time Stamp: Mon Dec 16 15:45:08 2024\n", + "Success Frame: 9\n", + "Failed Frame: 0\n", + "Max Series Failed Frame: 0\n", + "Parse Result:\n", + "0x000C: 0xFFFF 未知数据 \n", + "0x000D: 0xFFFF 未知数据 \n", + "0x000E: 0x0000 故障字1 \n", + "0x000F: 0x0000 故障字2 \n", + "0x0010: 0x0000 MPPT工作状态 \n", + "0x0011: 0x0000 系统工作状态 \n", + "0x0012: 0x0000 系统工作模式 \n", + "0x0013: 5.6 输入电压 \n", + "0x0014: 0.0 电感电流 \n", + "0x0015: 11.1 12V电压 \n", + "0x0016: 57.2 输出电压 \n", + "0x0017: 0.01 输入电流 \n", + "0x0018: 21.0 温度1 \n", + "0x0019: 22.1 温度2 \n", + "0x001A: 0.0 输入功率 \n", + "0x001C: 22.1 设备温度 \n", + "0x001D: 0x0000 开关机状态 \n", + "0x001E: 54.0 电池电压 \n", + "0x001F: 700.0 并机功率限值 \n", + "0x0021: 56.5 输出限功率电压阈值\n", + "Time Stamp: Mon Dec 16 15:45:10 2024\n", + "Success Frame: 10\n", + "Failed Frame: 0\n", + "Max Series Failed Frame: 0\n", + "Parse Result:\n", + "0x000C: 0xFFFF 未知数据 \n", + "0x000D: 0xFFFF 未知数据 \n", + "0x000E: 0x0000 故障字1 \n", + "0x000F: 0x0000 故障字2 \n", + "0x0010: 0x0000 MPPT工作状态 \n", + "0x0011: 0x0000 系统工作状态 \n", + "0x0012: 0x0000 系统工作模式 \n", + "0x0013: 5.6 输入电压 \n", + "0x0014: 0.0 电感电流 \n", + "0x0015: 11.1 12V电压 \n", + "0x0016: 57.2 输出电压 \n", + "0x0017: 0.01 输入电流 \n", + "0x0018: 21.0 温度1 \n", + "0x0019: 22.1 温度2 \n", + "0x001A: 0.0 输入功率 \n", + "0x001C: 22.1 设备温度 \n", + "0x001D: 0x0000 开关机状态 \n", + "0x001E: 54.0 电池电压 \n", + "0x001F: 700.0 并机功率限值 \n", + "0x0021: 56.5 输出限功率电压阈值\n", + "Time Stamp: Mon Dec 16 15:45:12 2024\n", + "Success Frame: 11\n", + "Failed Frame: 0\n", + "Max Series Failed Frame: 0\n", + "Parse Result:\n", + "0x000C: 0xFFFF 未知数据 \n", + "0x000D: 0xFFFF 未知数据 \n", + "0x000E: 0x0000 故障字1 \n", + "0x000F: 0x0000 故障字2 \n", + "0x0010: 0x0000 MPPT工作状态 \n", + "0x0011: 0x0000 系统工作状态 \n", + "0x0012: 0x0000 系统工作模式 \n", + "0x0013: 5.6 输入电压 \n", + "0x0014: 0.0 电感电流 \n", + "0x0015: 11.1 12V电压 \n", + "0x0016: 57.2 输出电压 \n", + "0x0017: 0.01 输入电流 \n", + "0x0018: 21.0 温度1 \n", + "0x0019: 22.1 温度2 \n", + "0x001A: 0.0 输入功率 \n", + "0x001C: 22.1 设备温度 \n", + "0x001D: 0x0000 开关机状态 \n", + "0x001E: 54.0 电池电压 \n", + "0x001F: 700.0 并机功率限值 \n", + "0x0021: 56.5 输出限功率电压阈值\n", + "Time Stamp: Mon Dec 16 15:45:14 2024\n", + "Success Frame: 12\n", + "Failed Frame: 0\n", + "Max Series Failed Frame: 0\n", + "Parse Result:\n", + "0x000C: 0xFFFF 未知数据 \n", + "0x000D: 0xFFFF 未知数据 \n", + "0x000E: 0x0000 故障字1 \n", + "0x000F: 0x0000 故障字2 \n", + "0x0010: 0x0000 MPPT工作状态 \n", + "0x0011: 0x0000 系统工作状态 \n", + "0x0012: 0x0000 系统工作模式 \n", + "0x0013: 5.6 输入电压 \n", + "0x0014: 0.0 电感电流 \n", + "0x0015: 11.1 12V电压 \n", + "0x0016: 57.2 输出电压 \n", + "0x0017: 0.01 输入电流 \n", + "0x0018: 21.0 温度1 \n", + "0x0019: 22.1 温度2 \n", + "0x001A: 0.0 输入功率 \n", + "0x001C: 22.1 设备温度 \n", + "0x001D: 0x0000 开关机状态 \n", + "0x001E: 54.0 电池电压 \n", + "0x001F: 700.0 并机功率限值 \n", + "0x0021: 56.5 输出限功率电压阈值\n", + "Time Stamp: Mon Dec 16 15:45:16 2024\n", + "Success Frame: 13\n", + "Failed Frame: 0\n", + "Max Series Failed Frame: 0\n", + "Parse Result:\n", + "0x000C: 0xFFFF 未知数据 \n", + "0x000D: 0xFFFF 未知数据 \n", + "0x000E: 0x0000 故障字1 \n", + "0x000F: 0x0000 故障字2 \n", + "0x0010: 0x0000 MPPT工作状态 \n", + "0x0011: 0x0000 系统工作状态 \n", + "0x0012: 0x0000 系统工作模式 \n", + "0x0013: 5.6 输入电压 \n", + "0x0014: 0.0 电感电流 \n", + "0x0015: 11.1 12V电压 \n", + "0x0016: 57.2 输出电压 \n", + "0x0017: 0.01 输入电流 \n", + "0x0018: 21.0 温度1 \n", + "0x0019: 22.1 温度2 \n", + "0x001A: 0.0 输入功率 \n", + "0x001C: 22.1 设备温度 \n", + "0x001D: 0x0000 开关机状态 \n", + "0x001E: 54.0 电池电压 \n", + "0x001F: 700.0 并机功率限值 \n", + "0x0021: 56.5 输出限功率电压阈值\n", + "Time Stamp: Mon Dec 16 15:45:18 2024\n", + "Success Frame: 14\n", + "Failed Frame: 0\n", + "Max Series Failed Frame: 0\n", + "Parse Result:\n", + "0x000C: 0xFFFF 未知数据 \n", + "0x000D: 0xFFFF 未知数据 \n", + "0x000E: 0x0000 故障字1 \n", + "0x000F: 0x0000 故障字2 \n", + "0x0010: 0x0000 MPPT工作状态 \n", + "0x0011: 0x0000 系统工作状态 \n", + "0x0012: 0x0000 系统工作模式 \n", + "0x0013: 5.6 输入电压 \n", + "0x0014: 0.0 电感电流 \n", + "0x0015: 11.1 12V电压 \n", + "0x0016: 57.2 输出电压 \n", + "0x0017: 0.01 输入电流 \n", + "0x0018: 21.0 温度1 \n", + "0x0019: 22.1 温度2 \n", + "0x001A: 0.0 输入功率 \n", + "0x001C: 22.1 设备温度 \n", + "0x001D: 0x0000 开关机状态 \n", + "0x001E: 54.0 电池电压 \n", + "0x001F: 700.0 并机功率限值 \n", + "0x0021: 56.5 输出限功率电压阈值\n", + "Time Stamp: Mon Dec 16 15:45:20 2024\n", + "Success Frame: 15\n", + "Failed Frame: 0\n", + "Max Series Failed Frame: 0\n", + "Parse Result:\n", + "0x000C: 0xFFFF 未知数据 \n", + "0x000D: 0xFFFF 未知数据 \n", + "0x000E: 0x0000 故障字1 \n", + "0x000F: 0x0000 故障字2 \n", + "0x0010: 0x0000 MPPT工作状态 \n", + "0x0011: 0x0000 系统工作状态 \n", + "0x0012: 0x0000 系统工作模式 \n", + "0x0013: 5.6 输入电压 \n", + "0x0014: 0.0 电感电流 \n", + "0x0015: 11.1 12V电压 \n", + "0x0016: 57.2 输出电压 \n", + "0x0017: 0.01 输入电流 \n", + "0x0018: 21.0 温度1 \n", + "0x0019: 22.2 温度2 \n", + "0x001A: 0.0 输入功率 \n", + "0x001C: 22.2 设备温度 \n", + "0x001D: 0x0000 开关机状态 \n", + "0x001E: 54.0 电池电压 \n", + "0x001F: 700.0 并机功率限值 \n", + "0x0021: 56.5 输出限功率电压阈值\n", + "Time Stamp: Mon Dec 16 15:45:22 2024\n", + "Success Frame: 16\n", + "Failed Frame: 0\n", + "Max Series Failed Frame: 0\n", + "Parse Result:\n", + "0x000C: 0xFFFF 未知数据 \n", + "0x000D: 0xFFFF 未知数据 \n", + "0x000E: 0x0000 故障字1 \n", + "0x000F: 0x0000 故障字2 \n", + "0x0010: 0x0000 MPPT工作状态 \n", + "0x0011: 0x0000 系统工作状态 \n", + "0x0012: 0x0000 系统工作模式 \n", + "0x0013: 5.6 输入电压 \n", + "0x0014: 0.0 电感电流 \n", + "0x0015: 11.1 12V电压 \n", + "0x0016: 57.2 输出电压 \n", + "0x0017: 0.01 输入电流 \n", + "0x0018: 21.0 温度1 \n", + "0x0019: 22.2 温度2 \n", + "0x001A: 0.0 输入功率 \n", + "0x001C: 22.2 设备温度 \n", + "0x001D: 0x0000 开关机状态 \n", + "0x001E: 54.0 电池电压 \n", + "0x001F: 700.0 并机功率限值 \n", + "0x0021: 56.5 输出限功率电压阈值\n", + "Time Stamp: Mon Dec 16 15:45:24 2024\n", + "Success Frame: 17\n", + "Failed Frame: 0\n", + "Max Series Failed Frame: 0\n", + "Parse Result:\n", + "0x000C: 0xFFFF 未知数据 \n", + "0x000D: 0xFFFF 未知数据 \n", + "0x000E: 0x0000 故障字1 \n", + "0x000F: 0x0000 故障字2 \n", + "0x0010: 0x0000 MPPT工作状态 \n", + "0x0011: 0x0000 系统工作状态 \n", + "0x0012: 0x0000 系统工作模式 \n", + "0x0013: 5.6 输入电压 \n", + "0x0014: 0.0 电感电流 \n", + "0x0015: 11.1 12V电压 \n", + "0x0016: 57.2 输出电压 \n", + "0x0017: 0.01 输入电流 \n", + "0x0018: 21.0 温度1 \n", + "0x0019: 22.2 温度2 \n", + "0x001A: 0.0 输入功率 \n", + "0x001C: 22.2 设备温度 \n", + "0x001D: 0x0000 开关机状态 \n", + "0x001E: 54.0 电池电压 \n", + "0x001F: 700.0 并机功率限值 \n", + "0x0021: 56.5 输出限功率电压阈值\n", + "Time Stamp: Mon Dec 16 15:45:26 2024\n", + "Success Frame: 18\n", + "Failed Frame: 0\n", + "Max Series Failed Frame: 0\n", + "Parse Result:\n", + "0x000C: 0xFFFF 未知数据 \n", + "0x000D: 0xFFFF 未知数据 \n", + "0x000E: 0x0000 故障字1 \n", + "0x000F: 0x0000 故障字2 \n", + "0x0010: 0x0001 MPPT工作状态 \n", + "0x0011: 0x0000 系统工作状态 \n", + "0x0012: 0x0000 系统工作模式 \n", + "0x0013: 41.2 输入电压 \n", + "0x0014: 0.0 电感电流 \n", + "0x0015: 11.1 12V电压 \n", + "0x0016: 57.2 输出电压 \n", + "0x0017: 0.01 输入电流 \n", + "0x0018: 21.0 温度1 \n", + "0x0019: 22.2 温度2 \n", + "0x001A: 0.0 输入功率 \n", + "0x001C: 22.2 设备温度 \n", + "0x001D: 0x0000 开关机状态 \n", + "0x001E: 54.0 电池电压 \n", + "0x001F: 700.0 并机功率限值 \n", + "0x0021: 56.5 输出限功率电压阈值\n", + "Time Stamp: Mon Dec 16 15:45:28 2024\n", + "Success Frame: 19\n", + "Failed Frame: 0\n", + "Max Series Failed Frame: 0\n", + "Parse Result:\n", + "0x000C: 0xFFFF 未知数据 \n", + "0x000D: 0xFFFF 未知数据 \n", + "0x000E: 0x0000 故障字1 \n", + "0x000F: 0x0000 故障字2 \n", + "0x0010: 0x0002 MPPT工作状态 \n", + "0x0011: 0x0003 系统工作状态 \n", + "0x0012: 0x0000 系统工作模式 \n", + "0x0013: 58.5 输入电压 \n", + "0x0014: 4.55 电感电流 \n", + "0x0015: 11.1 12V电压 \n", + "0x0016: 58.0 输出电压 \n", + "0x0017: 4.53 输入电流 \n", + "0x0018: 21.0 温度1 \n", + "0x0019: 22.2 温度2 \n", + "0x001A: 265.005 输入功率 \n", + "0x001C: 22.2 设备温度 \n", + "0x001D: 0x0001 开关机状态 \n", + "0x001E: 54.0 电池电压 \n", + "0x001F: 700.0 并机功率限值 \n", + "0x0021: 56.5 输出限功率电压阈值\n", + "Time Stamp: Mon Dec 16 15:45:30 2024\n", + "Success Frame: 20\n", + "Failed Frame: 0\n", + "Max Series Failed Frame: 0\n", + "Parse Result:\n", + "0x000C: 0xFFFF 未知数据 \n", + "0x000D: 0xFFFF 未知数据 \n", + "0x000E: 0x0000 故障字1 \n", + "0x000F: 0x0000 故障字2 \n", + "0x0010: 0x0003 MPPT工作状态 \n", + "0x0011: 0x0003 系统工作状态 \n", + "0x0012: 0x0000 系统工作模式 \n", + "0x0013: 53.9 输入电压 \n", + "0x0014: 10.78 电感电流 \n", + "0x0015: 11.1 12V电压 \n", + "0x0016: 58.3 输出电压 \n", + "0x0017: 10.26 输入电流 \n", + "0x0018: 21.0 温度1 \n", + "0x0019: 22.2 温度2 \n", + "0x001A: 553.014 输入功率 \n", + "0x001C: 22.2 设备温度 \n", + "0x001D: 0x0001 开关机状态 \n", + "0x001E: 54.0 电池电压 \n", + "0x001F: 700.0 并机功率限值 \n", + "0x0021: 56.5 输出限功率电压阈值\n", + "Time Stamp: Mon Dec 16 15:45:32 2024\n", + "Success Frame: 21\n", + "Failed Frame: 0\n", + "Max Series Failed Frame: 0\n", + "Parse Result:\n", + "0x000C: 0xFFFF 未知数据 \n", + "0x000D: 0xFFFF 未知数据 \n", + "0x000E: 0x0000 故障字1 \n", + "0x000F: 0x0000 故障字2 \n", + "0x0010: 0x0003 MPPT工作状态 \n", + "0x0011: 0x0003 系统工作状态 \n", + "0x0012: 0x0000 系统工作模式 \n", + "0x0013: 53.9 输入电压 \n", + "0x0014: 10.79 电感电流 \n", + "0x0015: 11.1 12V电压 \n", + "0x0016: 58.3 输出电压 \n", + "0x0017: 10.27 输入电流 \n", + "0x0018: 21.1 温度1 \n", + "0x0019: 22.2 温度2 \n", + "0x001A: 553.553 输入功率 \n", + "0x001C: 22.2 设备温度 \n", + "0x001D: 0x0001 开关机状态 \n", + "0x001E: 54.0 电池电压 \n", + "0x001F: 700.0 并机功率限值 \n", + "0x0021: 56.5 输出限功率电压阈值\n", + "Time Stamp: Mon Dec 16 15:45:34 2024\n", + "Success Frame: 22\n", + "Failed Frame: 0\n", + "Max Series Failed Frame: 0\n", + "Parse Result:\n", + "0x000C: 0xFFFF 未知数据 \n", + "0x000D: 0xFFFF 未知数据 \n", + "0x000E: 0x0000 故障字1 \n", + "0x000F: 0x0000 故障字2 \n", + "0x0010: 0x0003 MPPT工作状态 \n", + "0x0011: 0x0003 系统工作状态 \n", + "0x0012: 0x0000 系统工作模式 \n", + "0x0013: 53.9 输入电压 \n", + "0x0014: 10.79 电感电流 \n", + "0x0015: 11.1 12V电压 \n", + "0x0016: 58.3 输出电压 \n", + "0x0017: 10.27 输入电流 \n", + "0x0018: 21.2 温度1 \n", + "0x0019: 22.3 温度2 \n", + "0x001A: 553.553 输入功率 \n", + "0x001C: 22.3 设备温度 \n", + "0x001D: 0x0001 开关机状态 \n", + "0x001E: 54.0 电池电压 \n", + "0x001F: 700.0 并机功率限值 \n", + "0x0021: 56.5 输出限功率电压阈值\n", + "Time Stamp: Mon Dec 16 15:45:37 2024\n", + "Success Frame: 23\n", + "Failed Frame: 0\n", + "Max Series Failed Frame: 0\n", + "Parse Result:\n", + "0x000C: 0xFFFF 未知数据 \n", + "0x000D: 0xFFFF 未知数据 \n", + "0x000E: 0x0000 故障字1 \n", + "0x000F: 0x0000 故障字2 \n", + "0x0010: 0x0003 MPPT工作状态 \n", + "0x0011: 0x0003 系统工作状态 \n", + "0x0012: 0x0000 系统工作模式 \n", + "0x0013: 53.9 输入电压 \n", + "0x0014: 10.8 电感电流 \n", + "0x0015: 11.1 12V电压 \n", + "0x0016: 58.3 输出电压 \n", + "0x0017: 10.28 输入电流 \n", + "0x0018: 21.3 温度1 \n", + "0x0019: 22.3 温度2 \n", + "0x001A: 554.092 输入功率 \n", + "0x001C: 22.3 设备温度 \n", + "0x001D: 0x0001 开关机状态 \n", + "0x001E: 54.0 电池电压 \n", + "0x001F: 700.0 并机功率限值 \n", + "0x0021: 56.5 输出限功率电压阈值\n", + "Time Stamp: Mon Dec 16 15:45:39 2024\n", + "Success Frame: 24\n", + "Failed Frame: 0\n", + "Max Series Failed Frame: 0\n", + "Parse Result:\n", + "0x000C: 0xFFFF 未知数据 \n", + "0x000D: 0xFFFF 未知数据 \n", + "0x000E: 0x0000 故障字1 \n", + "0x000F: 0x0000 故障字2 \n", + "0x0010: 0x0003 MPPT工作状态 \n", + "0x0011: 0x0003 系统工作状态 \n", + "0x0012: 0x0000 系统工作模式 \n", + "0x0013: 53.9 输入电压 \n", + "0x0014: 10.8 电感电流 \n", + "0x0015: 11.1 12V电压 \n", + "0x0016: 58.3 输出电压 \n", + "0x0017: 10.28 输入电流 \n", + "0x0018: 21.5 温度1 \n", + "0x0019: 22.3 温度2 \n", + "0x001A: 554.092 输入功率 \n", + "0x001C: 22.3 设备温度 \n", + "0x001D: 0x0001 开关机状态 \n", + "0x001E: 54.0 电池电压 \n", + "0x001F: 700.0 并机功率限值 \n", + "0x0021: 56.5 输出限功率电压阈值\n", + "Time Stamp: Mon Dec 16 15:45:41 2024\n", + "Success Frame: 25\n", + "Failed Frame: 0\n", + "Max Series Failed Frame: 0\n", + "Parse Result:\n", + "0x000C: 0xFFFF 未知数据 \n", + "0x000D: 0xFFFF 未知数据 \n", + "0x000E: 0x0000 故障字1 \n", + "0x000F: 0x0000 故障字2 \n", + "0x0010: 0x0003 MPPT工作状态 \n", + "0x0011: 0x0003 系统工作状态 \n", + "0x0012: 0x0000 系统工作模式 \n", + "0x0013: 53.9 输入电压 \n", + "0x0014: 10.81 电感电流 \n", + "0x0015: 11.1 12V电压 \n", + "0x0016: 58.3 输出电压 \n", + "0x0017: 10.29 输入电流 \n", + "0x0018: 21.6 温度1 \n", + "0x0019: 22.4 温度2 \n", + "0x001A: 554.631 输入功率 \n", + "0x001C: 22.4 设备温度 \n", + "0x001D: 0x0001 开关机状态 \n", + "0x001E: 54.0 电池电压 \n", + "0x001F: 700.0 并机功率限值 \n", + "0x0021: 56.5 输出限功率电压阈值\n", + "Time Stamp: Mon Dec 16 15:45:43 2024\n", + "Success Frame: 26\n", + "Failed Frame: 0\n", + "Max Series Failed Frame: 0\n", + "Test Result: \n", + "Time Start: 2024-12-16 15:44:58, \tTime End: 2024-12-16 15:45:45\n", + "Time Elapsed: 47.00012421607971\n", + "Success Rate: 100.0%\n" + ] + }, + { + "ename": "KeyboardInterrupt", + "evalue": "", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[164], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mtest_communication\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", + "Cell \u001b[1;32mIn[163], line 14\u001b[0m, in \u001b[0;36mtest_communication\u001b[1;34m(time_out)\u001b[0m\n\u001b[0;32m 12\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mFailed Frame: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mdev_lamina\u001b[38;5;241m.\u001b[39mlog[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124msend\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;250m \u001b[39m\u001b[38;5;241m-\u001b[39m\u001b[38;5;250m \u001b[39mdev_lamina\u001b[38;5;241m.\u001b[39mlog[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mread\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m 13\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mMax Series Failed Frame: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mdev_lamina\u001b[38;5;241m.\u001b[39mlog[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mkeep-fail\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m---> 14\u001b[0m time\u001b[38;5;241m.\u001b[39msleep(time_out)\n\u001b[0;32m 15\u001b[0m \u001b[38;5;28;01mfinally\u001b[39;00m:\n\u001b[0;32m 16\u001b[0m time_end \u001b[38;5;241m=\u001b[39m time\u001b[38;5;241m.\u001b[39mtime()\n", + "\u001b[1;31mKeyboardInterrupt\u001b[0m: " + ] + } + ], + "source": [ + "test_communication()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 解除限功率限制\n", + "1. 设置输出限功率阈值电压为60V\n", + "2. 输出电压停机阈值上升至58.5V\n", + "3. 输出电压启机阈值上升至58V" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Send Frame: 68 AA AA AA AA AA AA 68 1F 08 01 06 00 21 02 58 D9 5A A8 16\n", + "Read Frame: 68 16 95 11 16 06 24 68 9F 08 01 06 00 21 02 58 D9 5A 28 16\n", + "Send Frame: 68 AA AA AA AA AA AA 68 1F 08 01 06 00 6A 02 49 69 40 58 16\n", + "Read Frame: 68 16 95 11 16 06 24 68 9F 08 01 06 00 6A 02 49 69 40 D8 16\n", + "Send Frame: 68 AA AA AA AA AA AA 68 1F 08 01 06 00 68 02 44 09 45 F6 16\n", + "Read Frame: 68 16 95 11 16 06 24 68 9F 08 01 06 00 68 02 44 09 45 76 16\n" + ] + } + ], + "source": [ + "# 解除限功率限制\n", + "dev_lamina.frame_write_one(0x21, 600)\n", + "time.sleep(0.5)\n", + "# 接触输出电压停机限制\n", + "dev_lamina.frame_write_one(0x6A, 585)\n", + "time.sleep(0.5)\n", + "# 修改输出电压启机限制\n", + "dev_lamina.frame_write_one(0x68, 580)\n", + "time.sleep(0.5)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Send Frame: 68 AA AA AA AA AA AA 68 1F 08 01 03 00 0E 00 20 25 D1 1B 16\n", + "Error Info: No frame data\n" + ] + }, + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dev_lamina.frame_read(0x0E, 0x20)" + ] + }, + { + "cell_type": "code", + "execution_count": 104, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Send Frame: 68 AA AA AA AA AA AA 68 1F 08 01 03 00 0E 00 20 25 D1 1B 16\n", + "Read Frame: 68 16 95 11 16 06 24 68 9F 2D 01 03 28 00 00 00 00 00 03 00 03 00 00 01 B1 06 A1 00 6F 02 49 05 D2 01 05 00 D5 D8 32 00 09 01 05 00 01 02 1C AE 60 00 0A 02 58 76 3F EE 16\n", + "Parse Result:\n", + "0x000E: 0x0000 故障字1 \n", + "0x000F: 0x0000 故障字2 \n", + "0x0010: 0x0003 MPPT工作状态 \n", + "0x0011: 0x0003 系统工作状态 \n", + "0x0012: 0x0000 系统工作模式 \n", + "0x0013: 43.3 输入电压 \n", + "0x0014: 16.97 电感电流 \n", + "0x0015: 11.1 12V电压 \n", + "0x0016: 58.5 输出电压 \n", + "0x0017: 14.9 输入电流 \n", + "0x0018: 26.1 温度1 \n", + "0x0019: 21.3 温度2 \n", + "0x001A: 645.17 输入功率 \n", + "0x001C: 26.1 设备温度 \n", + "0x001D: 0x0001 开关机状态 \n", + "0x001E: 54.0 电池电压 \n", + "0x001F: 700.0 并机功率限值 \n", + "0x0021: 60.0 输出限功率电压阈值\n" + ] + }, + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 104, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dev_lamina.frame_read(0x0E, 0x20)" + ] + }, + { + "cell_type": "code", + "execution_count": 156, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Send Frame: 68 AA AA AA AA AA AA 68 1F 08 01 03 00 0E 00 20 25 D1 1B 16\n", + "Read Frame: 68 16 95 11 16 06 24 68 9F 2D 01 03 28 00 00 00 00 00 03 00 03 00 00 01 A7 06 D7 00 6F 02 49 05 FD 01 27 00 E6 E5 0B 00 09 01 27 00 01 02 1C AE 60 00 0A 02 58 4F 90 AA 16\n", + "Parse Result:\n", + "0x000E: 0x0000 故障字1 \n", + "0x000F: 0x0000 故障字2 \n", + "0x0010: 0x0003 MPPT工作状态 \n", + "0x0011: 0x0003 系统工作状态 \n", + "0x0012: 0x0000 系统工作模式 \n", + "0x0013: 42.3 输入电压 \n", + "0x0014: 17.51 电感电流 \n", + "0x0015: 11.1 12V电压 \n", + "0x0016: 58.5 输出电压 \n", + "0x0017: 15.33 输入电流 \n", + "0x0018: 29.5 温度1 \n", + "0x0019: 23.0 温度2 \n", + "0x001A: 648.459 输入功率 \n", + "0x001C: 29.5 设备温度 \n", + "0x001D: 0x0001 开关机状态 \n", + "0x001E: 54.0 电池电压 \n", + "0x001F: 700.0 并机功率限值 \n", + "0x0021: 60.0 输出限功率电压阈值\n" + ] + }, + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 156, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dev_lamina.frame_read(0x0E, 0x20)" + ] + }, + { + "cell_type": "code", + "execution_count": 157, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Send Frame: 68 AA AA AA AA AA AA 68 1F 08 01 03 00 0E 00 20 25 D1 1B 16\n", + "Read Frame: 68 16 95 11 16 06 24 68 9F 2D 01 03 28 00 00 00 00 00 03 00 03 00 00 01 A7 06 D8 00 6F 02 49 05 FD 01 2B 00 E8 E5 0B 00 09 01 2B 00 01 02 1C AE 60 00 0A 02 58 07 E9 C6 16\n", + "Parse Result:\n", + "0x000E: 0x0000 故障字1 \n", + "0x000F: 0x0000 故障字2 \n", + "0x0010: 0x0003 MPPT工作状态 \n", + "0x0011: 0x0003 系统工作状态 \n", + "0x0012: 0x0000 系统工作模式 \n", + "0x0013: 42.3 输入电压 \n", + "0x0014: 17.52 电感电流 \n", + "0x0015: 11.1 12V电压 \n", + "0x0016: 58.5 输出电压 \n", + "0x0017: 15.33 输入电流 \n", + "0x0018: 29.9 温度1 \n", + "0x0019: 23.2 温度2 \n", + "0x001A: 648.459 输入功率 \n", + "0x001C: 29.9 设备温度 \n", + "0x001D: 0x0001 开关机状态 \n", + "0x001E: 54.0 电池电压 \n", + "0x001F: 700.0 并机功率限值 \n", + "0x0021: 60.0 输出限功率电压阈值\n" + ] + }, + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 157, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dev_lamina.frame_read(0x0E, 0x20)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 运行效果\n", + "1. 设备以650W功率正常运行\n", + "2. 输出电压采样结果上升至58.5V" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Send Frame: 68 AA AA AA AA AA AA 68 1F 08 01 06 00 50 00 00 89 DB AE 16\n", + "Read Frame: 68 88 88 88 88 89 22 68 9F 08 01 06 00 50 00 00 89 DB FD 16\n", + "Send Frame: 68 AA AA AA AA AA AA 68 1F 08 01 03 00 0E 00 20 25 D1 1B 16\n", + "Read Frame: 68 88 88 88 88 89 22 68 9F 2D 01 03 28 00 00 00 00 00 01 00 00 00 00 02 0D 00 00 00 72 02 17 00 00 01 1A 01 00 00 00 00 00 01 1A 00 00 02 1C AE 60 00 0A 02 35 06 1D F5 16\n", + "Parse Result:\n", + "0x000E: 0x0000 故障字1 \n", + "0x000F: 0x0000 故障字2 \n", + "0x0010: 0x0001 MPPT工作状态 \n", + "0x0011: 0x0000 系统工作状态 \n", + "0x0012: 0x0000 系统工作模式 \n", + "0x0013: 52.5 输入电压 \n", + "0x0014: 0.0 电感电流 \n", + "0x0015: 11.4 12V电压 \n", + "0x0016: 53.5 输出电压 \n", + "0x0017: 0.0 输入电流 \n", + "0x0018: 28.2 温度1 \n", + "0x0019: 25.6 温度2 \n", + "0x001A: 0.0 输入功率 \n", + "0x001C: 28.2 设备温度 \n", + "0x001D: 0x0000 开关机状态 \n", + "0x001E: 54.0 电池电压 \n", + "0x001F: 700.0 并机功率限值 \n", + "0x0021: 56.5 输出限功率电压阈值\n" + ] + }, + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dev_lamina.frame_write_one(0x50, 0)\n", + "time.sleep(1.5)\n", + "dev_lamina.frame_read(0x0E, 0x20)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Send Frame: 68 AA AA AA AA AA AA 68 1F 08 01 03 01 A0 00 60 44 3C 78 16\n", + "Read Frame: 68 88 88 88 88 89 22 68 9F C5 01 03 C0 02 A2 01 00 01 09 14 50 6F 77 65 72 20 66 61 73 74 20 72 65 6C 65 61 73 65 2E 00 00 00 00 00 00 5C 9B 01 00 01 08 0D 53 79 73 20 70 72 65 72 52 75 6E 2E 00 00 00 00 00 00 00 00 00 00 00 00 00 92 9A 01 00 01 07 0D 53 79 73 20 73 74 61 72 74 75 70 2E 00 00 00 00 00 00 00 00 00 00 00 00 00 C0 92 01 00 02 06 08 41 00 00 00 00 0E 02 19 02 00 00 00 00 58 1B 00 00 46 61 75 6C 74 20 52 65 0E 0A 01 00 02 05 08 21 01 00 00 00 5C 02 58 02 00 00 00 00 58 1B 01 00 46 61 75 6C 74 20 54 72 0E 0A 01 00 01 04 0D 53 79 73 20 73 74 61 72 74 75 70 2E 00 00 00 00 00 00 00 00 00 00 00 00 00 D9 6B 77 16\n", + "Parse Result:\n", + "0x01A0: Event: 1\n", + "\ttime: 107010\n", + "\tnumber: 9\n", + "\tData: Power fast release.\n", + " 事件记录1\n", + "0x01B0: Event: 1\n", + "\ttime: 105308\n", + "\tnumber: 8\n", + "\tData: Sys prerRun.\n", + " 事件记录2\n", + "0x01C0: Event: 1\n", + "\ttime: 105106\n", + "\tnumber: 7\n", + "\tData: Sys startup.\n", + " 事件记录3\n", + "0x01D0: Event: 2\n", + "\ttime: 103104\n", + "\tnumber: 6\n", + "\tData: Fault Re\n", + "\t\tstatus: 41\n", + "\t\tflag_fault: 0\n", + "\t\tflag_alarm: 0\n", + "\t\tvolt_in: 52.6\n", + "\t\tvolt_out: 53.7\n", + "\t\tcurr_in: 0.0\n", + "\t\tcurr_induc: 0.0\n", + "\t\tcbox_power_limit: 700.0\n", + "\t\tflag_control: 0\n", + " 事件记录4\n", + "0x01E0: Event: 2\n", + "\ttime: 68110\n", + "\tnumber: 5\n", + "\tData: Fault Tr\n", + "\t\tstatus: 21\n", + "\t\tflag_fault: 1\n", + "\t\tflag_alarm: 0\n", + "\t\tvolt_in: 60.4\n", + "\t\tvolt_out: 60.0\n", + "\t\tcurr_in: 0.0\n", + "\t\tcurr_induc: 0.0\n", + "\t\tcbox_power_limit: 700.0\n", + "\t\tflag_control: 1\n", + " 事件记录5\n", + "0x01F0: Event: 1\n", + "\ttime: 68110\n", + "\tnumber: 4\n", + "\tData: Sys startup.\n", + " 事件记录6\n" + ] + }, + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dev_lamina.frame_read(0x1A0, 0x60)" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Send Frame: 68 AA AA AA AA AA AA 68 1F 08 01 06 00 6F 09 56 3F B9 C0 16\n", + "Read Frame: 68 88 88 88 88 89 22 68 9F 08 01 06 00 6F 09 56 3F B9 0F 16\n" + ] + }, + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dev_lamina.frame_write_one(0x6F, 2390)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Send Frame: 68 AA AA AA AA AA AA 68 1F 08 01 03 01 00 00 20 45 EE 4B 16\n", + "Error Info: No frame data\n" + ] + }, + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dev_lamina.close_connection()\n", + "time.sleep(0.5)\n", + "dev_lamina.open_connection()\n", + "dev_lamina.frame_read(0x100, 0x20)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Send Frame: 68 AA AA AA AA AA AA 68 1F 0F 01 10 00 82 00 03 06 05 06 03 04 01 02 09 23 D7 16\n", + "Read Frame: 68 01 02 03 04 05 06 68 9F 08 01 10 00 82 00 03 20 20 62 16\n" + ] + }, + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dev_lamina.frame_write_str()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "test", + "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.11.6" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/source/dev_LaminaAdapter.py b/source/dev_LaminaAdapter.py index 9838f7c..820bb52 100644 --- a/source/dev_LaminaAdapter.py +++ b/source/dev_LaminaAdapter.py @@ -154,15 +154,23 @@ if __name__=='__main__': # dev_lamina.frame_log() # dev_lamina.frame_read(0x1A0, 0x20) + # 工程-即时转换 + if dev_lamina.device == 'SLCP001': + file_hex = Path(r"D:\WorkingProject\LightStackAdapter\software\lamina_adapter\release\device_V1\lamina_adapter\Debug\lamina_adapter.hex") + elif dev_lamina.device == 'SLCP101': + file_hex = Path(r"D:\WorkingProject\LightStackAdapter\software\lamina_adapter\release\device_V2.03\lamina_adapter\Debug\lamina_adapter.hex") + elif dev_lamina.device == 'SLCP102': + file_hex = Path(r"D:\WorkingProject\LightStackAdapter\software\lamina_adapter\release\device_V3.01\lamina_adapter\Debug\lamina_adapter.hex") + elif dev_lamina.device == 'DLSY001': + file_hex = Path(r"D:\WorkingProject\LightStackOptimizer\software\lamina_optimizer\lamina_optimizer\Debug\lamina_optimizer.hex") + else: + file_hex = Path(r"D:\WorkingProject\LightStackAdapter\software\lamina_adapter\lamina_adapter\Debug\lamina_adapter.hex") + if not file_hex.exists(): + raise Exception("工程编译目标文件不存在.") + print(dev_lamina.device) + print(file_hex) if not hasattr(__builtins__,"__IPYTHON__"): - # 工程-即时转换 - # file_hex = Path(r"D:\WorkingProject\LightStackAdapter\software\lamina_adapter\lamina_adapter\Debug\lamina_adapter.hex") - file_hex = Path(r"D:\WorkingProject\LightStackAdapter\software\lamina_adapter\release\device_V1\lamina_adapter\Debug\lamina_adapter.hex") - # file_hex = Path(r"D:\WorkingProject\LightStackOptimizer\software\lamina_optimizer\lamina_optimizer\Debug\lamina_optimizer.hex") - if not file_hex.exists(): - raise Exception("工程编译目标文件不存在.") - version = "SLCP101_241030_2000_V2.03" addr = [0x24, 0x09, 0x12, 0x00, 0x00, 0x00] diff --git a/source/dev_station.py b/source/dev_station.py index ceeae27..1b4e61b 100644 --- a/source/dev_station.py +++ b/source/dev_station.py @@ -28,6 +28,26 @@ ParamMap_LaminaCombiner = { 0x000: ["系统型号", 4, 16], 0x010: ["程序版本", 4, 16], + 0x100: ["主板温度" , 2, 10], + 0x101: ["输入电流1" , 2, 100], + 0x102: ["输入电流2" , 2, 100], + 0x103: ["输入电流3" , 2, 100], + 0x104: ["输入电流4" , 2, 100], + 0x105: ["输入电流5" , 2, 100], + 0x106: ["输入电流6" , 2, 100], + 0x107: ["输入电流7" , 2, 100], + 0x108: ["输入电流8" , 2, 100], + + 0x200: ["从板温度" , 2, 10], + 0x201: ["输入电流9" , 2, 100], + 0x202: ["输入电流10" , 2, 100], + 0x203: ["输入电流11" , 2, 100], + 0x204: ["输入电流12" , 2, 100], + 0x205: ["输入电流13" , 2, 100], + 0x206: ["输入电流14" , 2, 100], + 0x207: ["输入电流15" , 2, 100], + 0x208: ["输入电流16" , 2, 100], + 0x800: ["设备地址", 5, 3], 0x803: ["时间", 5, 3], 0x806: ["文件记录日志级别", 1], @@ -193,11 +213,30 @@ if __name__ == '__main__': "dev10": {'device_id': 'TTE0101DX2406270018', # 张家港兆丰北单管塔 'frame_print': True, 'time_out': 4, 'retry': 1}, + "dev11": {'device_id': 'TTE0101DX2407290011', # 昆山市吴淞江污水厂基站机房 + 'frame_print': True, + 'time_out': 4, 'retry': 1}, + "dev12": {'device_id': 'TTE0101DX2409210071', # 丰顺村铁路搬迁-光伏 + 'frame_print': True, + 'time_out': 6, 'retry': 1}, + "dev13": {'device_id': 'TTE0101DX2410110017', # 张家港市福源纺织基站机房 + 'frame_print': True, + 'time_out': 6, 'retry': 1}, + "dev14": {'device_id': 'TTE0101DX2406140008', # 张家港乐余良种场落地外爬单管塔 + 'frame_print': True, + 'time_out': 6, 'retry': 1}, + "dev15": {'device_id': 'TTE0101DX2406270099', # 张家港塘市东落地景观塔 + 'frame_print': True, + 'time_out': 6, 'retry': 1}, + "dev16": {'device_id': 'TTE0101DX2409210027', # 2017-YD:定州北只东 + 'frame_print': True, + 'time_out': 6, 'retry': 1}, } - dev_lamina = LaminaStation(**mode_config["dev8"]) + dev_lamina = LaminaStation(**mode_config["dev16"]) dev_lamina.frame_read(0x0000, 0x20) - # dev_lamina.frame_read(0x4100, 0x20) + time.sleep(2) + dev_lamina.frame_read(0x857, 0x40) if not hasattr(__builtins__,"__IPYTHON__"): pass diff --git a/source/device/LaminaAdapter.py b/source/device/LaminaAdapter.py index 7985de2..6bfd836 100644 --- a/source/device/LaminaAdapter.py +++ b/source/device/LaminaAdapter.py @@ -47,6 +47,8 @@ ParamMap_LaminaAdapter = { 0x54: ["主动故障命令" , 2], 0x55: ["短时停机命令" , 2], + 0x5E: ["抖动频率上限", 2, 100], + 0x5F: ["抖动频率下限", 2, 100], 0x60: ["光伏通道使能", 1], 0x61: ["最小启动输入电压", 2, 10], 0x62: ["最大启动输入电压", 2, 10], @@ -229,7 +231,7 @@ class LaminaAdapter(DeviceSerial): self.block['data']['data_val'] = dval return self._transfer_data() - def frame_log(self, step='next') -> bool: + def frame_read_log(self, step='next') -> bool: self.block['data']['type'] = 'log' self.block['data']['step'] = step return self._transfer_data()