diff --git a/source/Interactive-1.ipynb b/source/Interactive-1.ipynb new file mode 100644 index 0000000..6f8195f --- /dev/null +++ b/source/Interactive-1.ipynb @@ -0,0 +1,1644 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "已连接到 test (Python 3.11.6)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "ename": "ModuleNotFoundError", + "evalue": "No module named 'device'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[1], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mdevice\u001b[39;00m\n", + "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'device'" + ] + } + ], + "source": [ + "import device" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'d:\\\\WorkSpace\\\\UserTool\\\\SelfTool\\\\FrameParser'" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "%pwd" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import source.device as device" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "my_block = {\n", + " 'addr_dev' : 0x00,\n", + " 'data_define': None,\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bfda458c-1c82-43cc-bc0e-8eed6f1c53f7", + "metadata": {}, + "outputs": [], + "source": [ + "list_param = [\n", + "(0x0400, 16),\n", + "(0x0410, 16),\n", + "(0x0420, 32),\n", + "(0x0440, 32),\n", + "(0x0460, 2),\n", + "(0x0462, 5),\n", + "(0x0467, 4),\n", + "(0x046B, 3),\n", + "(0x046E, 1),\n", + "(0x046F, 1),\n", + "(0x0470, 2),\n", + "(0x0472, 16),\n", + "(0x0482, 12),\n", + "(0x048E, 12),\n", + "(0x049A, 5),\n", + "(0x049F, 5),\n", + "(0x04A4, 5),\n", + "(0x04A9, 2),\n", + "(0x04AB, 1),\n", + "(0x04AC, 9),\n", + "(0x04B5, 175),\n", + "(0x0564, 16),\n", + "(0x0574, 2),\n", + "(0x0576, 2),\n", + "(0x0578, 16),\n", + "]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "00 03 04 00 00 10 44 E7\n", + "00 03 04 10 00 10 45 22\n", + "00 03 04 20 00 20 45 39\n", + "00 03 04 40 00 20 45 27\n", + "00 03 04 60 00 02 C4 F4\n", + "00 03 04 62 00 05 24 F6\n", + "00 03 04 67 00 04 F5 37\n", + "00 03 04 6B 00 03 74 F6\n", + "00 03 04 6E 00 01 E5 36\n", + "00 03 04 6F 00 01 B4 F6\n", + "00 03 04 70 00 02 C5 31\n", + "00 03 04 72 00 10 E4 FC\n", + "00 03 04 82 00 0C E5 06\n", + "00 03 04 8E 00 0C 25 05\n", + "00 03 04 9A 00 05 A5 07\n", + "00 03 04 9F 00 05 B5 06\n", + "00 03 04 A4 00 05 C4 CB\n", + "00 03 04 A9 00 02 14 CA\n", + "00 03 04 AB 00 01 F5 0B\n", + "00 03 04 AC 00 09 45 0C\n", + "00 03 04 B5 00 AF 14 B1\n", + "00 03 05 64 00 10 04 C4\n", + "00 03 05 74 00 02 85 0C\n", + "00 03 05 76 00 02 24 CC\n", + "00 03 05 78 00 10 C5 02\n" + ] + } + ], + "source": [ + "my_block = {\n", + " 'addr_dev' : 0x00,\n", + " 'type': 'read',\n", + " 'data_addr': 0x00,\n", + " 'data_len': 0x00,\n", + " 'data_define': {},\n", + "}\n", + "\n", + "for addr, len in list_param:\n", + " my_block['data_addr'] = addr\n", + " my_block['data_len'] = len\n", + " frame = device.function.protocols.make_frame_modbus(my_block)\n", + " print(device.tools.ByteConv.trans_list_to_str(frame))\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "已重启 test (Python 3.11.6)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import source.device as device" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "63803d7f-4b39-4990-9417-e8b5fcdca397", + "metadata": {}, + "outputs": [], + "source": [ + "list_param = [\n", + "(0x0400, 16),\n", + "(0x0410, 16),\n", + "(0x0420, 32),\n", + "(0x0440, 32),\n", + "(0x0460, 2),\n", + "(0x0462, 5),\n", + "(0x0467, 4),\n", + "(0x046B, 3),\n", + "(0x046E, 1),\n", + "(0x046F, 1),\n", + "(0x0470, 2),\n", + "(0x0472, 16),\n", + "(0x0482, 12),\n", + "(0x048E, 12),\n", + "(0x049A, 5),\n", + "(0x049F, 5),\n", + "(0x04A4, 5),\n", + "(0x04A9, 2),\n", + "(0x04AB, 1),\n", + "(0x04AC, 9),\n", + "(0x04B5, 175),\n", + "(0x0564, 16),\n", + "(0x0574, 2),\n", + "(0x0576, 2),\n", + "(0x0578, 16),\n", + "]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'frame' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[3], line 13\u001b[0m\n\u001b[0;32m 11\u001b[0m my_block[\u001b[39m'\u001b[39m\u001b[39mdata_len\u001b[39m\u001b[39m'\u001b[39m] \u001b[39m=\u001b[39m \u001b[39mlen\u001b[39m\n\u001b[0;32m 12\u001b[0m frame_read \u001b[39m=\u001b[39m device\u001b[39m.\u001b[39mfunction\u001b[39m.\u001b[39mprotocols\u001b[39m.\u001b[39mmake_frame_modbus(my_block)\n\u001b[1;32m---> 13\u001b[0m \u001b[39mprint\u001b[39m(device\u001b[39m.\u001b[39mtools\u001b[39m.\u001b[39mByteConv\u001b[39m.\u001b[39mtrans_list_to_str(frame))\n\u001b[0;32m 14\u001b[0m my_block[\u001b[39m'\u001b[39m\u001b[39mtype\u001b[39m\u001b[39m'\u001b[39m] \u001b[39m=\u001b[39m \u001b[39m'\u001b[39m\u001b[39mwrite_str\u001b[39m\u001b[39m'\u001b[39m\n\u001b[0;32m 15\u001b[0m my_block[\u001b[39m'\u001b[39m\u001b[39mdata_val\u001b[39m\u001b[39m'\u001b[39m] \u001b[39m=\u001b[39m \u001b[39mlist\u001b[39m(\u001b[39mrange\u001b[39m(\u001b[39m0x10\u001b[39m, \u001b[39m0x10\u001b[39m \u001b[39m+\u001b[39m \u001b[39mlen\u001b[39m))\n", + "\u001b[1;31mNameError\u001b[0m: name 'frame' is not defined" + ] + } + ], + "source": [ + "my_block = {\n", + " 'addr_dev' : 0x00,\n", + " 'type': 'read',\n", + " 'data_addr': 0x00,\n", + " 'data_len': 0x00,\n", + " 'data_define': {},\n", + "}\n", + "\n", + "for addr, len in list_param:\n", + " my_block['data_addr'] = addr\n", + " my_block['data_len'] = len\n", + " frame_read = device.function.protocols.make_frame_modbus(my_block)\n", + " print(device.tools.ByteConv.trans_list_to_str(frame))\n", + " my_block['type'] = 'write_str'\n", + " my_block['data_val'] = list(range(0x10, 0x10 + len))\n", + " frame_write = device.function.protocols.make_frame_modbus(my_block)\n", + " print(device.tools.ByteConv.trans_list_to_str(frame))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "00 03 04 00 00 10 44 E7\n", + "00 10 04 00 00 08 10 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E F0 74\n", + "00 10 04 10 00 08 10 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 32 E7\n", + "00 10 04 10 00 08 10 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 32 E7\n", + "00 10 04 20 00 08 10 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 77 13\n", + "00 10 04 20 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E C3 8F\n", + "00 10 04 40 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E CC 07\n", + "00 10 04 40 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E CC 07\n", + "00 10 04 60 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E C8 BF\n", + "00 10 04 60 00 01 02 11 10 EA 3C\n", + "00 10 04 62 00 01 02 11 10 EB DE\n", + "00 10 04 62 00 02 05 11 10 13 12 F6 66\n", + "00 10 04 67 00 02 05 11 10 13 12 36 59\n", + "00 10 04 67 00 02 04 11 10 13 12 0B 99\n", + "00 10 04 6B 00 02 04 11 10 13 12 0B CC\n", + "00 10 04 6B 00 01 03 11 10 BA 87\n", + "00 10 04 6E 00 01 03 11 10 BA D2\n", + "00 10 04 6E 00 00 01 35 78\n", + "00 10 04 6F 00 00 01 34 84\n", + "00 10 04 6F 00 00 01 34 84\n", + "00 10 04 70 00 00 01 33 50\n", + "00 10 04 70 00 01 02 11 10 E8 AC\n", + "00 10 04 72 00 01 02 11 10 E9 4E\n", + "00 10 04 72 00 08 10 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E C2 AD\n", + "00 10 04 82 00 08 10 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 96 48\n", + "00 10 04 82 00 06 0C 11 10 13 12 15 14 17 16 19 18 1B 1A 0B 5B\n", + "00 10 04 8E 00 06 0C 11 10 13 12 15 14 17 16 19 18 1B 1A 0E 5E\n", + "00 10 04 8E 00 06 0C 11 10 13 12 15 14 17 16 19 18 1B 1A 0E 5E\n", + "00 10 04 9A 00 06 0C 11 10 13 12 15 14 17 16 19 18 1B 1A 01 51\n", + "00 10 04 9A 00 02 05 11 10 13 12 F8 84\n", + "00 10 04 9F 00 02 05 11 10 13 12 38 BB\n", + "00 10 04 9F 00 02 05 11 10 13 12 38 BB\n", + "00 10 04 A4 00 02 05 11 10 13 12 7A 1C\n", + "00 10 04 A4 00 02 05 11 10 13 12 7A 1C\n", + "00 10 04 A9 00 02 05 11 10 13 12 BB 85\n", + "00 10 04 A9 00 01 02 11 10 FB A5\n", + "00 10 04 AB 00 01 02 11 10 FA 47\n", + "00 10 04 AB 00 00 01 09 B4\n", + "00 10 04 AC 00 00 01 08 C0\n", + "00 10 04 AC 00 04 09 11 10 13 12 15 14 17 16 46 28\n", + "00 10 04 B5 00 04 09 11 10 13 12 15 14 17 16 9B CB\n", + "00 10 04 B5 00 57 AF 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 31 30 33 32 35 34 37 36 39 38 3B 3A 3D 3C 3F 3E 41 40 43 42 45 44 47 46 49 48 4B 4A 4D 4C 4F 4E 51 50 53 52 55 54 57 56 59 58 5B 5A 5D 5C 5F 5E 61 60 63 62 65 64 67 66 69 68 6B 6A 6D 6C 6F 6E 71 70 73 72 75 74 77 76 79 78 7B 7A 7D 7C 7F 7E 81 80 83 82 85 84 87 86 89 88 8B 8A 8D 8C 8F 8E 91 90 93 92 95 94 97 96 99 98 9B 9A 9D 9C 9F 9E A1 A0 A3 A2 A5 A4 A7 A6 A9 A8 AB AA AD AC AF AE B1 B0 B3 B2 B5 B4 B7 B6 B9 B8 BB BA BD BC 72 BF\n", + "00 10 05 64 00 57 AF 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 31 30 33 32 35 34 37 36 39 38 3B 3A 3D 3C 3F 3E 41 40 43 42 45 44 47 46 49 48 4B 4A 4D 4C 4F 4E 51 50 53 52 55 54 57 56 59 58 5B 5A 5D 5C 5F 5E 61 60 63 62 65 64 67 66 69 68 6B 6A 6D 6C 6F 6E 71 70 73 72 75 74 77 76 79 78 7B 7A 7D 7C 7F 7E 81 80 83 82 85 84 87 86 89 88 8B 8A 8D 8C 8F 8E 91 90 93 92 95 94 97 96 99 98 9B 9A 9D 9C 9F 9E A1 A0 A3 A2 A5 A4 A7 A6 A9 A8 AB AA AD AC AF AE B1 B0 B3 B2 B5 B4 B7 B6 B9 B8 BB BA BD BC 10 3E\n", + "00 10 05 64 00 08 10 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 98 89\n", + "00 10 05 74 00 08 10 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 5A 1A\n", + "00 10 05 74 00 01 02 11 10 F9 E8\n", + "00 10 05 76 00 01 02 11 10 F8 0A\n", + "00 10 05 76 00 01 02 11 10 F8 0A\n", + "00 10 05 78 00 01 02 11 10 F9 24\n", + "00 10 05 78 00 08 10 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 4A D7\n" + ] + } + ], + "source": [ + "my_block = {\n", + " 'addr_dev' : 0x00,\n", + " 'type': 'read',\n", + " 'data_addr': 0x00,\n", + " 'data_len': 0x00,\n", + " 'data_define': {},\n", + "}\n", + "\n", + "for addr, len in list_param:\n", + " my_block['data_addr'] = addr\n", + " my_block['data_len'] = len\n", + " frame_read = device.function.protocols.make_frame_modbus(my_block)\n", + " print(device.tools.ByteConv.trans_list_to_str(frame_read))\n", + " my_block['type'] = 'write_str'\n", + " my_block['data_val'] = list(range(0x10, 0x10 + len))\n", + " frame_write = device.function.protocols.make_frame_modbus(my_block)\n", + " print(device.tools.ByteConv.trans_list_to_str(frame_write))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "00 03 04 00 00 10 44 E7\n", + "00 10 04 00 00 08 10 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E F0 74\n", + "00 03 04 10 00 10 45 22\n", + "00 10 04 10 00 08 10 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 32 E7\n", + "00 03 04 20 00 20 45 39\n", + "00 10 04 20 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E C3 8F\n", + "00 03 04 40 00 20 45 27\n", + "00 10 04 40 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E CC 07\n", + "00 03 04 60 00 02 C4 F4\n", + "00 10 04 60 00 01 02 11 10 EA 3C\n", + "00 03 04 62 00 05 24 F6\n", + "00 10 04 62 00 02 05 11 10 13 12 F6 66\n", + "00 03 04 67 00 04 F5 37\n", + "00 10 04 67 00 02 04 11 10 13 12 0B 99\n", + "00 03 04 6B 00 03 74 F6\n", + "00 10 04 6B 00 01 03 11 10 BA 87\n", + "00 03 04 6E 00 01 E5 36\n", + "00 10 04 6E 00 00 01 35 78\n", + "00 03 04 6F 00 01 B4 F6\n", + "00 10 04 6F 00 00 01 34 84\n", + "00 03 04 70 00 02 C5 31\n", + "00 10 04 70 00 01 02 11 10 E8 AC\n", + "00 03 04 72 00 10 E4 FC\n", + "00 10 04 72 00 08 10 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E C2 AD\n", + "00 03 04 82 00 0C E5 06\n", + "00 10 04 82 00 06 0C 11 10 13 12 15 14 17 16 19 18 1B 1A 0B 5B\n", + "00 03 04 8E 00 0C 25 05\n", + "00 10 04 8E 00 06 0C 11 10 13 12 15 14 17 16 19 18 1B 1A 0E 5E\n", + "00 03 04 9A 00 05 A5 07\n", + "00 10 04 9A 00 02 05 11 10 13 12 F8 84\n", + "00 03 04 9F 00 05 B5 06\n", + "00 10 04 9F 00 02 05 11 10 13 12 38 BB\n", + "00 03 04 A4 00 05 C4 CB\n", + "00 10 04 A4 00 02 05 11 10 13 12 7A 1C\n", + "00 03 04 A9 00 02 14 CA\n", + "00 10 04 A9 00 01 02 11 10 FB A5\n", + "00 03 04 AB 00 01 F5 0B\n", + "00 10 04 AB 00 00 01 09 B4\n", + "00 03 04 AC 00 09 45 0C\n", + "00 10 04 AC 00 04 09 11 10 13 12 15 14 17 16 46 28\n", + "00 03 04 B5 00 AF 14 B1\n", + "00 10 04 B5 00 57 AF 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 31 30 33 32 35 34 37 36 39 38 3B 3A 3D 3C 3F 3E 41 40 43 42 45 44 47 46 49 48 4B 4A 4D 4C 4F 4E 51 50 53 52 55 54 57 56 59 58 5B 5A 5D 5C 5F 5E 61 60 63 62 65 64 67 66 69 68 6B 6A 6D 6C 6F 6E 71 70 73 72 75 74 77 76 79 78 7B 7A 7D 7C 7F 7E 81 80 83 82 85 84 87 86 89 88 8B 8A 8D 8C 8F 8E 91 90 93 92 95 94 97 96 99 98 9B 9A 9D 9C 9F 9E A1 A0 A3 A2 A5 A4 A7 A6 A9 A8 AB AA AD AC AF AE B1 B0 B3 B2 B5 B4 B7 B6 B9 B8 BB BA BD BC 72 BF\n", + "00 03 05 64 00 10 04 C4\n", + "00 10 05 64 00 08 10 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 98 89\n", + "00 03 05 74 00 02 85 0C\n", + "00 10 05 74 00 01 02 11 10 F9 E8\n", + "00 03 05 76 00 02 24 CC\n", + "00 10 05 76 00 01 02 11 10 F8 0A\n", + "00 03 05 78 00 10 C5 02\n", + "00 10 05 78 00 08 10 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 4A D7\n" + ] + } + ], + "source": [ + "my_block = {\n", + " 'addr_dev' : 0x00,\n", + " 'data_define': {},\n", + "}\n", + "\n", + "for addr, len in list_param:\n", + " my_block['type'] = 'read'\n", + " my_block['data_addr'] = addr\n", + " my_block['data_len'] = len\n", + " frame_read = device.function.protocols.make_frame_modbus(my_block)\n", + " print(device.tools.ByteConv.trans_list_to_str(frame_read))\n", + " my_block['type'] = 'write_str'\n", + " my_block['data_val'] = list(range(0x10, 0x10 + len))\n", + " frame_write = device.function.protocols.make_frame_modbus(my_block)\n", + " print(device.tools.ByteConv.trans_list_to_str(frame_write))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "00 03 04 00 00 10 44 E7\n", + "00 10 04 00 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E C7 37\n", + "00 03 04 10 00 10 45 22\n", + "00 10 04 10 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E C5 6B\n", + "00 03 04 20 00 20 45 39\n", + "00 10 04 20 00 20 40 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 31 30 33 32 35 34 37 36 39 38 3B 3A 3D 3C 3F 3E 41 40 43 42 45 44 47 46 49 48 4B 4A 4D 4C 4F 4E BD 9E\n", + "00 03 04 40 00 20 45 27\n", + "00 10 04 40 00 20 40 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 31 30 33 32 35 34 37 36 39 38 3B 3A 3D 3C 3F 3E 41 40 43 42 45 44 47 46 49 48 4B 4A 4D 4C 4F 4E 3B 36\n", + "00 03 04 60 00 02 C4 F4\n", + "00 10 04 60 00 02 04 11 10 13 12 4A 7F\n", + "00 03 04 62 00 05 24 F6\n", + "00 10 04 62 00 05 0A 11 10 13 12 15 14 17 16 19 18 04 6D\n", + "00 03 04 67 00 04 F5 37\n", + "00 10 04 67 00 04 08 11 10 13 12 15 14 17 16 AD 22\n", + "00 03 04 6B 00 03 74 F6\n", + "00 10 04 6B 00 03 06 11 10 13 12 15 14 EB F6\n", + "00 03 04 6E 00 01 E5 36\n", + "00 10 04 6E 00 01 02 11 10 EB 12\n", + "00 03 04 6F 00 01 B4 F6\n", + "00 10 04 6F 00 01 02 11 10 EA C3\n", + "00 03 04 70 00 02 C5 31\n", + "00 10 04 70 00 02 04 11 10 13 12 4B 73\n", + "00 03 04 72 00 10 E4 FC\n", + "00 10 04 72 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 4B 18\n", + "00 03 04 82 00 0C E5 06\n", + "00 10 04 82 00 0C 18 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 C2 58\n", + "00 03 04 8E 00 0C 25 05\n", + "00 10 04 8E 00 0C 18 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 DF 98\n", + "00 03 04 9A 00 05 A5 07\n", + "00 10 04 9A 00 05 0A 11 10 13 12 15 14 17 16 19 18 FD 55\n", + "00 03 04 9F 00 05 B5 06\n", + "00 10 04 9F 00 05 0A 11 10 13 12 15 14 17 16 19 18 F8 50\n", + "00 03 04 A4 00 05 C4 CB\n", + "00 10 04 A4 00 05 0A 11 10 13 12 15 14 17 16 19 18 C2 AB\n", + "00 03 04 A9 00 02 14 CA\n", + "00 10 04 A9 00 02 04 11 10 13 12 86 45\n", + "00 03 04 AB 00 01 F5 0B\n", + "00 10 04 AB 00 01 02 11 10 FA 47\n", + "00 03 04 AC 00 09 45 0C\n", + "00 10 04 AC 00 09 12 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 7F E1\n", + "00 03 04 B5 00 AF 14 B1\n" + ] + }, + { + "ename": "ValueError", + "evalue": "byte must be in range(0, 256)", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[1], line 25\u001b[0m, in \u001b[0;36m__VSCODE_wrap_run_cell..wrapper\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 24\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[1;32m---> 25\u001b[0m store_history \u001b[39m=\u001b[39m args[\u001b[39m2\u001b[39m] \u001b[39mif\u001b[39;00m \u001b[39mlen\u001b[39;49m(args) \u001b[39m>\u001b[39m \u001b[39m2\u001b[39m \u001b[39melse\u001b[39;00m kwargs[\u001b[39m\"\u001b[39m\u001b[39mstore_history\u001b[39m\u001b[39m\"\u001b[39m]\n\u001b[0;32m 26\u001b[0m \u001b[39mif\u001b[39;00m store_history:\n", + "\u001b[1;31mTypeError\u001b[0m: 'int' object is not callable", + "\nDuring handling of the above exception, another exception occurred:\n", + "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[6], line 14\u001b[0m\n\u001b[0;32m 12\u001b[0m my_block[\u001b[39m'\u001b[39m\u001b[39mtype\u001b[39m\u001b[39m'\u001b[39m] \u001b[39m=\u001b[39m \u001b[39m'\u001b[39m\u001b[39mwrite_str\u001b[39m\u001b[39m'\u001b[39m\n\u001b[0;32m 13\u001b[0m my_block[\u001b[39m'\u001b[39m\u001b[39mdata_val\u001b[39m\u001b[39m'\u001b[39m] \u001b[39m=\u001b[39m \u001b[39mlist\u001b[39m(\u001b[39mrange\u001b[39m(\u001b[39m0x10\u001b[39m, \u001b[39m0x10\u001b[39m \u001b[39m+\u001b[39m \u001b[39m2\u001b[39m \u001b[39m*\u001b[39m \u001b[39mlen\u001b[39m))\n\u001b[1;32m---> 14\u001b[0m frame_write \u001b[39m=\u001b[39m device\u001b[39m.\u001b[39;49mfunction\u001b[39m.\u001b[39;49mprotocols\u001b[39m.\u001b[39;49mmake_frame_modbus(my_block)\n\u001b[0;32m 15\u001b[0m \u001b[39mprint\u001b[39m(device\u001b[39m.\u001b[39mtools\u001b[39m.\u001b[39mByteConv\u001b[39m.\u001b[39mtrans_list_to_str(frame_write))\n", + "File \u001b[1;32md:\\WorkSpace\\UserTool\\SelfTool\\FrameParser\\source\\device\\function\\protocols.py:169\u001b[0m, in \u001b[0;36mmake_frame_modbus\u001b[1;34m(block)\u001b[0m\n\u001b[0;32m 166\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[0;32m 167\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mException\u001b[39;00m(\u001b[39m\"\u001b[39m\u001b[39mModbus Frame Type Error.\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[1;32m--> 169\u001b[0m crc \u001b[39m=\u001b[39m calculator\u001b[39m.\u001b[39mchecksum(\u001b[39mbytearray\u001b[39;49m(frame))\n\u001b[0;32m 170\u001b[0m frame\u001b[39m.\u001b[39mappend(crc \u001b[39m%\u001b[39m \u001b[39m256\u001b[39m)\n\u001b[0;32m 171\u001b[0m frame\u001b[39m.\u001b[39mappend(crc \u001b[39m/\u001b[39m\u001b[39m/\u001b[39m \u001b[39m256\u001b[39m)\n", + "\u001b[1;31mValueError\u001b[0m: byte must be in range(0, 256)" + ] + } + ], + "source": [ + "my_block = {\n", + " 'addr_dev' : 0x00,\n", + " 'data_define': {},\n", + "}\n", + "\n", + "for addr, len in list_param:\n", + " my_block['type'] = 'read'\n", + " my_block['data_addr'] = addr\n", + " my_block['data_len'] = len\n", + " frame_read = device.function.protocols.make_frame_modbus(my_block)\n", + " print(device.tools.ByteConv.trans_list_to_str(frame_read))\n", + " my_block['type'] = 'write_str'\n", + " my_block['data_val'] = list(range(0x10, 0x10 + 2 * len))\n", + " frame_write = device.function.protocols.make_frame_modbus(my_block)\n", + " print(device.tools.ByteConv.trans_list_to_str(frame_write))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "00 03 04 00 00 10 44 E7\n", + "00 10 04 00 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E C7 37\n", + "00 03 04 10 00 10 45 22\n", + "00 10 04 10 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E C5 6B\n", + "00 03 04 20 00 20 45 39\n", + "00 10 04 20 00 20 40 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 31 30 33 32 35 34 37 36 39 38 3B 3A 3D 3C 3F 3E 41 40 43 42 45 44 47 46 49 48 4B 4A 4D 4C 4F 4E BD 9E\n", + "00 03 04 40 00 20 45 27\n", + "00 10 04 40 00 20 40 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 31 30 33 32 35 34 37 36 39 38 3B 3A 3D 3C 3F 3E 41 40 43 42 45 44 47 46 49 48 4B 4A 4D 4C 4F 4E 3B 36\n", + "00 03 04 60 00 02 C4 F4\n", + "00 10 04 60 00 02 04 11 10 13 12 4A 7F\n", + "00 03 04 62 00 05 24 F6\n", + "00 10 04 62 00 05 0A 11 10 13 12 15 14 17 16 19 18 04 6D\n", + "00 03 04 67 00 04 F5 37\n", + "00 10 04 67 00 04 08 11 10 13 12 15 14 17 16 AD 22\n", + "00 03 04 6B 00 03 74 F6\n", + "00 10 04 6B 00 03 06 11 10 13 12 15 14 EB F6\n", + "00 03 04 6E 00 01 E5 36\n", + "00 10 04 6E 00 01 02 11 10 EB 12\n", + "00 03 04 6F 00 01 B4 F6\n", + "00 10 04 6F 00 01 02 11 10 EA C3\n", + "00 03 04 70 00 02 C5 31\n", + "00 10 04 70 00 02 04 11 10 13 12 4B 73\n", + "00 03 04 72 00 10 E4 FC\n", + "00 10 04 72 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 4B 18\n", + "00 03 04 82 00 0C E5 06\n", + "00 10 04 82 00 0C 18 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 C2 58\n", + "00 03 04 8E 00 0C 25 05\n", + "00 10 04 8E 00 0C 18 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 DF 98\n", + "00 03 04 9A 00 05 A5 07\n", + "00 10 04 9A 00 05 0A 11 10 13 12 15 14 17 16 19 18 FD 55\n", + "00 03 04 9F 00 05 B5 06\n", + "00 10 04 9F 00 05 0A 11 10 13 12 15 14 17 16 19 18 F8 50\n", + "00 03 04 A4 00 05 C4 CB\n", + "00 10 04 A4 00 05 0A 11 10 13 12 15 14 17 16 19 18 C2 AB\n", + "00 03 04 A9 00 02 14 CA\n", + "00 10 04 A9 00 02 04 11 10 13 12 86 45\n", + "00 03 04 AB 00 01 F5 0B\n", + "00 10 04 AB 00 01 02 11 10 FA 47\n", + "00 03 04 AC 00 09 45 0C\n", + "00 10 04 AC 00 09 12 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 7F E1\n", + "00 03 04 B5 00 AF 14 B1\n" + ] + }, + { + "ename": "ValueError", + "evalue": "byte must be in range(0, 256)", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[1], line 25\u001b[0m, in \u001b[0;36m__VSCODE_wrap_run_cell..wrapper\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 24\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[1;32m---> 25\u001b[0m store_history \u001b[39m=\u001b[39m args[\u001b[39m2\u001b[39m] \u001b[39mif\u001b[39;00m \u001b[39mlen\u001b[39;49m(args) \u001b[39m>\u001b[39m \u001b[39m2\u001b[39m \u001b[39melse\u001b[39;00m kwargs[\u001b[39m\"\u001b[39m\u001b[39mstore_history\u001b[39m\u001b[39m\"\u001b[39m]\n\u001b[0;32m 26\u001b[0m \u001b[39mif\u001b[39;00m store_history:\n", + "\u001b[1;31mTypeError\u001b[0m: 'int' object is not callable", + "\nDuring handling of the above exception, another exception occurred:\n", + "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[7], line 16\u001b[0m\n\u001b[0;32m 14\u001b[0m \u001b[39mcontinue\u001b[39;00m\n\u001b[0;32m 15\u001b[0m my_block[\u001b[39m'\u001b[39m\u001b[39mdata_val\u001b[39m\u001b[39m'\u001b[39m] \u001b[39m=\u001b[39m \u001b[39mlist\u001b[39m(\u001b[39mrange\u001b[39m(\u001b[39m0x10\u001b[39m, \u001b[39m0x10\u001b[39m \u001b[39m+\u001b[39m \u001b[39m2\u001b[39m \u001b[39m*\u001b[39m \u001b[39mlen\u001b[39m))\n\u001b[1;32m---> 16\u001b[0m frame_write \u001b[39m=\u001b[39m device\u001b[39m.\u001b[39;49mfunction\u001b[39m.\u001b[39;49mprotocols\u001b[39m.\u001b[39;49mmake_frame_modbus(my_block)\n\u001b[0;32m 17\u001b[0m \u001b[39mprint\u001b[39m(device\u001b[39m.\u001b[39mtools\u001b[39m.\u001b[39mByteConv\u001b[39m.\u001b[39mtrans_list_to_str(frame_write))\n", + "File \u001b[1;32md:\\WorkSpace\\UserTool\\SelfTool\\FrameParser\\source\\device\\function\\protocols.py:169\u001b[0m, in \u001b[0;36mmake_frame_modbus\u001b[1;34m(block)\u001b[0m\n\u001b[0;32m 166\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[0;32m 167\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mException\u001b[39;00m(\u001b[39m\"\u001b[39m\u001b[39mModbus Frame Type Error.\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[1;32m--> 169\u001b[0m crc \u001b[39m=\u001b[39m calculator\u001b[39m.\u001b[39mchecksum(\u001b[39mbytearray\u001b[39;49m(frame))\n\u001b[0;32m 170\u001b[0m frame\u001b[39m.\u001b[39mappend(crc \u001b[39m%\u001b[39m \u001b[39m256\u001b[39m)\n\u001b[0;32m 171\u001b[0m frame\u001b[39m.\u001b[39mappend(crc \u001b[39m/\u001b[39m\u001b[39m/\u001b[39m \u001b[39m256\u001b[39m)\n", + "\u001b[1;31mValueError\u001b[0m: byte must be in range(0, 256)" + ] + } + ], + "source": [ + "my_block = {\n", + " 'addr_dev' : 0x00,\n", + " 'data_define': {},\n", + "}\n", + "\n", + "for addr, len in list_param:\n", + " my_block['type'] = 'read'\n", + " my_block['data_addr'] = addr\n", + " my_block['data_len'] = len\n", + " frame_read = device.function.protocols.make_frame_modbus(my_block)\n", + " print(device.tools.ByteConv.trans_list_to_str(frame_read))\n", + " my_block['type'] = 'write_str'\n", + " if len >= 0x100:\n", + " continue\n", + " my_block['data_val'] = list(range(0x10, 0x10 + 2 * len))\n", + " frame_write = device.function.protocols.make_frame_modbus(my_block)\n", + " print(device.tools.ByteConv.trans_list_to_str(frame_write))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "00 03 04 00 00 10 44 E7\n", + "00 10 04 00 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E C7 37\n", + "00 03 04 10 00 10 45 22\n", + "00 10 04 10 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E C5 6B\n", + "00 03 04 20 00 20 45 39\n", + "00 10 04 20 00 20 40 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 31 30 33 32 35 34 37 36 39 38 3B 3A 3D 3C 3F 3E 41 40 43 42 45 44 47 46 49 48 4B 4A 4D 4C 4F 4E BD 9E\n", + "00 03 04 40 00 20 45 27\n", + "00 10 04 40 00 20 40 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 31 30 33 32 35 34 37 36 39 38 3B 3A 3D 3C 3F 3E 41 40 43 42 45 44 47 46 49 48 4B 4A 4D 4C 4F 4E 3B 36\n", + "00 03 04 60 00 02 C4 F4\n", + "00 10 04 60 00 02 04 11 10 13 12 4A 7F\n", + "00 03 04 62 00 05 24 F6\n", + "00 10 04 62 00 05 0A 11 10 13 12 15 14 17 16 19 18 04 6D\n", + "00 03 04 67 00 04 F5 37\n", + "00 10 04 67 00 04 08 11 10 13 12 15 14 17 16 AD 22\n", + "00 03 04 6B 00 03 74 F6\n", + "00 10 04 6B 00 03 06 11 10 13 12 15 14 EB F6\n", + "00 03 04 6E 00 01 E5 36\n", + "00 10 04 6E 00 01 02 11 10 EB 12\n", + "00 03 04 6F 00 01 B4 F6\n", + "00 10 04 6F 00 01 02 11 10 EA C3\n", + "00 03 04 70 00 02 C5 31\n", + "00 10 04 70 00 02 04 11 10 13 12 4B 73\n", + "00 03 04 72 00 10 E4 FC\n", + "00 10 04 72 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 4B 18\n", + "00 03 04 82 00 0C E5 06\n", + "00 10 04 82 00 0C 18 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 C2 58\n", + "00 03 04 8E 00 0C 25 05\n", + "00 10 04 8E 00 0C 18 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 DF 98\n", + "00 03 04 9A 00 05 A5 07\n", + "00 10 04 9A 00 05 0A 11 10 13 12 15 14 17 16 19 18 FD 55\n", + "00 03 04 9F 00 05 B5 06\n", + "00 10 04 9F 00 05 0A 11 10 13 12 15 14 17 16 19 18 F8 50\n", + "00 03 04 A4 00 05 C4 CB\n", + "00 10 04 A4 00 05 0A 11 10 13 12 15 14 17 16 19 18 C2 AB\n", + "00 03 04 A9 00 02 14 CA\n", + "00 10 04 A9 00 02 04 11 10 13 12 86 45\n", + "00 03 04 AB 00 01 F5 0B\n", + "00 10 04 AB 00 01 02 11 10 FA 47\n", + "00 03 04 AC 00 09 45 0C\n", + "00 10 04 AC 00 09 12 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 7F E1\n", + "00 03 04 B5 00 AF 14 B1\n", + "00 03 05 64 00 10 04 C4\n", + "00 10 05 64 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E D5 98\n", + "00 03 05 74 00 02 85 0C\n", + "00 10 05 74 00 02 04 11 10 13 12 47 10\n", + "00 03 05 76 00 02 24 CC\n", + "00 10 05 76 00 02 04 11 10 13 12 C6 C9\n", + "00 03 05 78 00 10 C5 02\n", + "00 10 05 78 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E D7 5D\n" + ] + } + ], + "source": [ + "my_block = {\n", + " 'addr_dev' : 0x00,\n", + " 'data_define': {},\n", + "}\n", + "\n", + "for addr, len in list_param:\n", + " my_block['type'] = 'read'\n", + " my_block['data_addr'] = addr\n", + " my_block['data_len'] = len\n", + " frame_read = device.function.protocols.make_frame_modbus(my_block)\n", + " print(device.tools.ByteConv.trans_list_to_str(frame_read))\n", + " my_block['type'] = 'write_str'\n", + " if len >= 0x80:\n", + " continue\n", + " my_block['data_val'] = list(range(0x10, 0x10 + 2 * len))\n", + " frame_write = device.function.protocols.make_frame_modbus(my_block)\n", + " print(device.tools.ByteConv.trans_list_to_str(frame_write))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import serial" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "com = serial.Serial('COM8', 115200, 8,'E', 1, 1)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "00 03 04 00 00 10 44 E7\n", + "00 10 04 00 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E C7 37\n", + "00 03 04 10 00 10 45 22\n", + "00 10 04 10 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E C5 6B\n", + "00 03 04 20 00 20 45 39\n", + "00 10 04 20 00 20 40 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 31 30 33 32 35 34 37 36 39 38 3B 3A 3D 3C 3F 3E 41 40 43 42 45 44 47 46 49 48 4B 4A 4D 4C 4F 4E BD 9E\n", + "00 03 04 40 00 20 45 27\n", + "00 10 04 40 00 20 40 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 31 30 33 32 35 34 37 36 39 38 3B 3A 3D 3C 3F 3E 41 40 43 42 45 44 47 46 49 48 4B 4A 4D 4C 4F 4E 3B 36\n", + "00 03 04 60 00 02 C4 F4\n", + "00 10 04 60 00 02 04 11 10 13 12 4A 7F\n", + "00 03 04 62 00 05 24 F6\n", + "00 10 04 62 00 05 0A 11 10 13 12 15 14 17 16 19 18 04 6D\n", + "00 03 04 67 00 04 F5 37\n", + "00 10 04 67 00 04 08 11 10 13 12 15 14 17 16 AD 22\n", + "00 03 04 6B 00 03 74 F6\n", + "00 10 04 6B 00 03 06 11 10 13 12 15 14 EB F6\n", + "00 03 04 6E 00 01 E5 36\n", + "00 10 04 6E 00 01 02 11 10 EB 12\n", + "00 03 04 6F 00 01 B4 F6\n", + "00 10 04 6F 00 01 02 11 10 EA C3\n", + "00 03 04 70 00 02 C5 31\n", + "00 10 04 70 00 02 04 11 10 13 12 4B 73\n", + "00 03 04 72 00 10 E4 FC\n", + "00 10 04 72 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 4B 18\n", + "00 03 04 82 00 0C E5 06\n", + "00 10 04 82 00 0C 18 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 C2 58\n", + "00 03 04 8E 00 0C 25 05\n", + "00 10 04 8E 00 0C 18 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 DF 98\n", + "00 03 04 9A 00 05 A5 07\n", + "00 10 04 9A 00 05 0A 11 10 13 12 15 14 17 16 19 18 FD 55\n", + "00 03 04 9F 00 05 B5 06\n", + "00 10 04 9F 00 05 0A 11 10 13 12 15 14 17 16 19 18 F8 50\n", + "00 03 04 A4 00 05 C4 CB\n", + "00 10 04 A4 00 05 0A 11 10 13 12 15 14 17 16 19 18 C2 AB\n", + "00 03 04 A9 00 02 14 CA\n", + "00 10 04 A9 00 02 04 11 10 13 12 86 45\n", + "00 03 04 AB 00 01 F5 0B\n", + "00 10 04 AB 00 01 02 11 10 FA 47\n", + "00 03 04 AC 00 09 45 0C\n", + "00 10 04 AC 00 09 12 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 7F E1\n", + "00 03 04 B5 00 AF 14 B1\n", + "00 03 05 64 00 10 04 C4\n", + "00 10 05 64 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E D5 98\n", + "00 03 05 74 00 02 85 0C\n", + "00 10 05 74 00 02 04 11 10 13 12 47 10\n", + "00 03 05 76 00 02 24 CC\n", + "00 10 05 76 00 02 04 11 10 13 12 C6 C9\n", + "00 03 05 78 00 10 C5 02\n", + "00 10 05 78 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E D7 5D\n" + ] + } + ], + "source": [ + "my_block = {\n", + " 'addr_dev' : 0x00,\n", + " 'data_define': {},\n", + "}\n", + "\n", + "frames = {}\n", + "for addr, len in list_param:\n", + " my_block['type'] = 'read'\n", + " my_block['data_addr'] = addr\n", + " my_block['data_len'] = len\n", + " frame_read = device.function.protocols.make_frame_modbus(my_block)\n", + " print(device.tools.ByteConv.trans_list_to_str(frame_read))\n", + " my_block['type'] = 'write_str'\n", + " if len >= 0x80:\n", + " continue\n", + " my_block['data_val'] = list(range(0x10, 0x10 + 2 * len))\n", + " frame_write = device.function.protocols.make_frame_modbus(my_block)\n", + " print(device.tools.ByteConv.trans_list_to_str(frame_write))\n", + " frames[addr] = frame_read, frame_write" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "8\n", + "00 03 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 84 5D\n" + ] + } + ], + "source": [ + "import time\n", + "ret = com.write(frames[0x400][0])\n", + "print(ret)\n", + "time.sleep(0.2)\n", + "frame_recv = com.read_all()\n", + "print(device.tools.ByteConv.trans_list_to_str(frame_recv))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "8\n", + "00 03 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 84 5D\n" + ] + }, + { + "ename": "TypeError", + "evalue": "a bytes-like object is required, not 'str'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[1], line 25\u001b[0m, in \u001b[0;36m__VSCODE_wrap_run_cell..wrapper\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 24\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[1;32m---> 25\u001b[0m store_history \u001b[39m=\u001b[39m args[\u001b[39m2\u001b[39m] \u001b[39mif\u001b[39;00m \u001b[39mlen\u001b[39;49m(args) \u001b[39m>\u001b[39m \u001b[39m2\u001b[39m \u001b[39melse\u001b[39;00m kwargs[\u001b[39m\"\u001b[39m\u001b[39mstore_history\u001b[39m\u001b[39m\"\u001b[39m]\n\u001b[0;32m 26\u001b[0m \u001b[39mif\u001b[39;00m store_history:\n", + "\u001b[1;31mTypeError\u001b[0m: 'int' object is not callable", + "\nDuring handling of the above exception, another exception occurred:\n", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[14], line 7\u001b[0m\n\u001b[0;32m 5\u001b[0m frame_recv \u001b[39m=\u001b[39m com\u001b[39m.\u001b[39mread_all()\n\u001b[0;32m 6\u001b[0m \u001b[39mprint\u001b[39m(device\u001b[39m.\u001b[39mtools\u001b[39m.\u001b[39mByteConv\u001b[39m.\u001b[39mtrans_list_to_str(frame_recv))\n\u001b[1;32m----> 7\u001b[0m \u001b[39mprint\u001b[39m(device\u001b[39m.\u001b[39;49mtools\u001b[39m.\u001b[39;49mByteConv\u001b[39m.\u001b[39;49mtrans_str_to_list(frame_recv)[\u001b[39m3\u001b[39m:\u001b[39m-\u001b[39m\u001b[39m2\u001b[39m])\n", + "File \u001b[1;32md:\\WorkSpace\\UserTool\\SelfTool\\FrameParser\\source\\device\\tools\\ByteConv.py:10\u001b[0m, in \u001b[0;36mtrans_str_to_list\u001b[1;34m(data)\u001b[0m\n\u001b[0;32m 8\u001b[0m \u001b[39m\u001b[39m\u001b[39m\"\"\" 标准串口字符串转换列表 \"\"\"\u001b[39;00m\n\u001b[0;32m 9\u001b[0m func_trans \u001b[39m=\u001b[39m \u001b[39mlambda\u001b[39;00m x: \u001b[39mint\u001b[39m(x, \u001b[39m16\u001b[39m)\n\u001b[1;32m---> 10\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mlist\u001b[39m(\u001b[39mmap\u001b[39m(func_trans, data\u001b[39m.\u001b[39;49mstrip()\u001b[39m.\u001b[39;49msplit(\u001b[39m\"\u001b[39;49m\u001b[39m \u001b[39;49m\u001b[39m\"\u001b[39;49m)))\n", + "\u001b[1;31mTypeError\u001b[0m: a bytes-like object is required, not 'str'" + ] + } + ], + "source": [ + "import time\n", + "ret = com.write(frames[0x400][0])\n", + "print(ret)\n", + "time.sleep(0.2)\n", + "frame_recv = com.read_all()\n", + "print(device.tools.ByteConv.trans_list_to_str(frame_recv))\n", + "print(device.tools.ByteConv.trans_str_to_list(frame_recv)[3:-2])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "8\n", + "00 03 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 84 5D\n", + "b'\\x11\\x10\\x13\\x12\\x15\\x14\\x17\\x16\\x19\\x18\\x1b\\x1a\\x1d\\x1c\\x1f\\x1e! #\"%$\\'&)(+*-,/.'\n" + ] + } + ], + "source": [ + "import time\n", + "ret = com.write(frames[0x400][0])\n", + "print(ret)\n", + "time.sleep(0.2)\n", + "frame_recv = com.read_all()\n", + "print(device.tools.ByteConv.trans_list_to_str(frame_recv))\n", + "print(frame_recv[3:-2])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47]\n", + "True\n" + ] + } + ], + "source": [ + "data_recv = []\n", + "for i in range(3, (len(frame_recv) - 2), 2):\n", + " data_recv.append(frame_recv[i+1])\n", + " data_recv.append(frame_recv[i])\n", + "print(data_recv)\n", + "print(list(range(0x10, 0x10 + 2 * 16)) == data_recv)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Read 0x400: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "Write 0x400, Result: \n", + "\t00 10 04 00 00 10 C1 24\n", + "Read 0x400: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "Read 0x410: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "Write 0x410, Result: \n", + "\t00 10 04 10 00 10 C0 E1\n", + "Read 0x410: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "Read 0x420: \n", + "\t31 32 33 34 35 36 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\n", + "Write 0x420, Result: \n", + "\t00 10 04 20 00 20 C0 FA\n", + "Read 0x420: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F\n", + "Read 0x440: \n", + "\t30 31 30 30 30 30 30 30 30 36 30 30 34 33 41 38 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\n", + "Write 0x440, Result: \n", + "\t00 10 04 40 00 20 C0 E4\n", + "Read 0x440: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F\n", + "Read 0x460: \n", + "\tFF FF FF FF\n", + "Write 0x460, Result: \n", + "\t00 10 04 60 00 02 41 37\n", + "Read 0x460: \n", + "\t10 11 12 13\n", + "Read 0x462: \n", + "\t00 00 00 00 00 00 00 00 00 00\n", + "Write 0x462, Result: \n", + "\t00 10 04 62 00 05 A1 35\n", + "Read 0x462: \n", + "\t10 11 12 13 14 15 16 17 18 19\n", + "Read 0x467: \n", + "\t00 00 00 00 00 00 00 00\n", + "Write 0x467, Result: \n", + "\t00 10 04 67 00 04 70 F4\n", + "Read 0x467: \n", + "\t10 11 12 13 14 15 16 17\n", + "Read 0x46b: \n", + "\t00 00 00 00 00 00\n", + "Write 0x46b, Result: \n", + "\t00 10 04 6B 00 03 F1 35\n", + "Read 0x46b: \n", + "\t10 11 12 13 14 15\n", + "Read 0x46e: \n", + "\t00 00\n", + "Write 0x46e, Result: \n", + "\t00 10 04 6E 00 01 60 F5\n", + "Read 0x46e: \n", + "\t10 11\n", + "Read 0x46f: \n", + "\t00 00\n", + "Write 0x46f, Result: \n", + "\t00 10 04 6F 00 01 31 35\n", + "Read 0x46f: \n", + "\t10 11\n", + "Read 0x470: \n", + "\t00 00 00 00\n", + "Write 0x470, Result: \n", + "\t00 10 04 70 00 02 40 F2\n", + "Read 0x470: \n", + "\t10 11 12 13\n", + "Read 0x472: \n", + "\t78 78 78 78 50 5F 6F 72 6F 74 6F 63 43 6C 76 6F 72 65 65 74 00 72 00 00 00 00 00 00 00 00 00 00\n", + "Write 0x472, Result: \n", + "\t00 10 04 72 00 10 61 3F\n", + "Read 0x472: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "Read 0x482: \n", + "\t72 50 74 6F 63 6F 6C 6F 6F 43 65 76 74 72 72 65 00 00 00 00 00 00 00 00\n", + "Write 0x482, Result: \n", + "\t00 10 04 82 00 0C 60 C5\n", + "Read 0x482: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27\n", + "Read 0x48e: \n", + "\t00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\n", + "Write 0x48e, Result: \n", + "\t00 10 04 8E 00 0C A0 C6\n", + "Read 0x48e: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27\n", + "Read 0x49a: \n", + "\t00 00 00 00 00 00 00 00 00 00\n", + "Write 0x49a, Result: \n", + "\t00 10 04 9A 00 05 20 C4\n", + "Read 0x49a: \n", + "\t10 11 12 13 14 15 16 17 18 19\n", + "Read 0x49f: \n", + "\t56 53 31 30 30 2E 00 31 00 00\n", + "Write 0x49f, Result: \n", + "\t00 10 04 9F 00 05 30 C5\n", + "Read 0x49f: \n", + "\t10 11 12 13 14 15 16 17 18 19\n", + "Read 0x4a4: \n", + "\t56 48 31 30 30 2E 00 31 00 00\n", + "Write 0x4a4, Result: \n", + "\t00 10 04 A4 00 05 41 08\n", + "Read 0x4a4: \n", + "\t10 11 12 13 14 15 16 17 18 19\n", + "Read 0x4a9: \n", + "\t00 00 00 00\n", + "Write 0x4a9, Result: \n", + "\t00 90 EB 5D 8F\n", + "Read 0x4a9: \n", + "\t00 00 00 00\n", + "Read 0x4ab: \n", + "\t00 00\n", + "Write 0x4ab, Result: \n", + "\t00 90 EB 5D 8F\n", + "Read 0x4ab: \n", + "\t00 00\n", + "Read 0x4ac: \n", + "\t03 02 00 05 93 04 12 E0 F6 09 09 12 00 60 00 00 00 00\n", + "Write 0x4ac, Result: \n", + "\t00 10 04 AC 00 09 C0 CF\n", + "Read 0x4ac: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 00 21\n" + ] + }, + { + "ename": "KeyError", + "evalue": "1205", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[35], line 20\u001b[0m\n\u001b[0;32m 18\u001b[0m \u001b[39mfor\u001b[39;00m daddr, dlen \u001b[39min\u001b[39;00m list_param:\n\u001b[0;32m 19\u001b[0m time\u001b[39m.\u001b[39msleep(\u001b[39m0.2\u001b[39m)\n\u001b[1;32m---> 20\u001b[0m read_data(daddr)\n\u001b[0;32m 21\u001b[0m time\u001b[39m.\u001b[39msleep(\u001b[39m0.2\u001b[39m)\n\u001b[0;32m 22\u001b[0m write_data(daddr)\n", + "Cell \u001b[1;32mIn[35], line 3\u001b[0m, in \u001b[0;36mread_data\u001b[1;34m(addr)\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mread_data\u001b[39m(addr):\n\u001b[0;32m 2\u001b[0m \u001b[39m \u001b[39m\u001b[39m\"\"\" 读取数据 \"\"\"\u001b[39;00m\n\u001b[1;32m----> 3\u001b[0m ret \u001b[39m=\u001b[39m com\u001b[39m.\u001b[39mwrite(frames[daddr][\u001b[39m0\u001b[39m])\n\u001b[0;32m 4\u001b[0m time\u001b[39m.\u001b[39msleep(\u001b[39m0.2\u001b[39m)\n\u001b[0;32m 5\u001b[0m frame_recv \u001b[39m=\u001b[39m com\u001b[39m.\u001b[39mread_all()\n", + "\u001b[1;31mKeyError\u001b[0m: 1205" + ] + } + ], + "source": [ + "def read_data(addr):\n", + " \"\"\" 读取数据 \"\"\"\n", + " ret = com.write(frames[daddr][0])\n", + " time.sleep(0.2)\n", + " frame_recv = com.read_all()\n", + " data_recv = []\n", + " for i in range(3, (len(frame_recv) - 2), 2):\n", + " data_recv.append(frame_recv[i+1])\n", + " data_recv.append(frame_recv[i])\n", + " print(f\"Read {hex(daddr)}: \\n\\t{device.tools.ByteConv.trans_list_to_str(data_recv)}\")\n", + "def write_data(addr):\n", + " \"\"\" 写入数据 \"\"\"\n", + " ret = com.write(frames[daddr][1])\n", + " time.sleep(0.2)\n", + " frame_recv = com.read_all()\n", + " print(f\"Write {hex(daddr)}, Result: \\n\\t{device.tools.ByteConv.trans_list_to_str(frame_recv)}\")\n", + "\n", + "for daddr, dlen in list_param:\n", + " time.sleep(0.2)\n", + " read_data(daddr)\n", + " time.sleep(0.2)\n", + " write_data(daddr)\n", + " time.sleep(0.2)\n", + " read_data(daddr)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1205" + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "daddr" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'0x4b5'" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "hex(daddr)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Read 0x400: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "Write 0x400, Result: \n", + "\t00 10 04 00 00 10 C1 24\n", + "Read 0x400: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "Read 0x410: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "Write 0x410, Result: \n", + "\t00 10 04 10 00 10 C0 E1\n", + "Read 0x410: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "Read 0x420: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F\n", + "Write 0x420, Result: \n", + "\t00 10 04 20 00 20 C0 FA\n", + "Read 0x420: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F\n", + "Read 0x440: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F\n", + "Write 0x440, Result: \n", + "\t00 10 04 40 00 20 C0 E4\n", + "Read 0x440: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F\n", + "Read 0x460: \n", + "\t10 11 12 13\n", + "Write 0x460, Result: \n", + "\t00 10 04 60 00 02 41 37\n", + "Read 0x460: \n", + "\t10 11 12 13\n", + "Read 0x462: \n", + "\t10 11 12 13 14 15 16 17 18 19\n", + "Write 0x462, Result: \n", + "\t00 10 04 62 00 05 A1 35\n", + "Read 0x462: \n", + "\t10 11 12 13 14 15 16 17 18 19\n", + "Read 0x467: \n", + "\t10 11 12 13 14 15 16 17\n", + "Write 0x467, Result: \n", + "\t00 10 04 67 00 04 70 F4\n", + "Read 0x467: \n", + "\t10 11 12 13 14 15 16 17\n", + "Read 0x46b: \n", + "\t10 11 12 13 14 15\n", + "Write 0x46b, Result: \n", + "\t00 10 04 6B 00 03 F1 35\n", + "Read 0x46b: \n", + "\t10 11 12 13 14 15\n", + "Read 0x46e: \n", + "\t10 11\n", + "Write 0x46e, Result: \n", + "\t00 10 04 6E 00 01 60 F5\n", + "Read 0x46e: \n", + "\t10 11\n", + "Read 0x46f: \n", + "\t10 11\n", + "Write 0x46f, Result: \n", + "\t00 10 04 6F 00 01 31 35\n", + "Read 0x46f: \n", + "\t10 11\n", + "Read 0x470: \n", + "\t10 11 12 13\n", + "Write 0x470, Result: \n", + "\t00 10 04 70 00 02 40 F2\n", + "Read 0x470: \n", + "\t10 11 12 13\n", + "Read 0x472: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "Write 0x472, Result: \n", + "\t00 10 04 72 00 10 61 3F\n", + "Read 0x472: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "Read 0x482: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27\n", + "Write 0x482, Result: \n", + "\t00 10 04 82 00 0C 60 C5\n", + "Read 0x482: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27\n", + "Read 0x48e: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27\n", + "Write 0x48e, Result: \n", + "\t00 10 04 8E 00 0C A0 C6\n", + "Read 0x48e: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27\n", + "Read 0x49a: \n", + "\t10 11 12 13 14 15 16 17 18 19\n", + "Write 0x49a, Result: \n", + "\t00 10 04 9A 00 05 20 C4\n", + "Read 0x49a: \n", + "\t10 11 12 13 14 15 16 17 18 19\n", + "Read 0x49f: \n", + "\t10 11 12 13 14 15 16 17 18 19\n", + "Write 0x49f, Result: \n", + "\t00 10 04 9F 00 05 30 C5\n", + "Read 0x49f: \n", + "\t10 11 12 13 14 15 16 17 18 19\n", + "Read 0x4a4: \n", + "\t10 11 12 13 14 15 16 17 18 19\n", + "Write 0x4a4, Result: \n", + "\t00 10 04 A4 00 05 41 08\n", + "Read 0x4a4: \n", + "\t10 11 12 13 14 15 16 17 18 19\n", + "Read 0x4a9: \n", + "\t00 00 00 00\n", + "Write 0x4a9, Result: \n", + "\t00 90 EB 5D 8F\n", + "Read 0x4a9: \n", + "\t00 00 00 00\n", + "Read 0x4ab: \n", + "\t00 00\n", + "Write 0x4ab, Result: \n", + "\t00 90 EB 5D 8F\n", + "Read 0x4ab: \n", + "\t00 00\n", + "Read 0x4ac: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 00 21\n", + "Write 0x4ac, Result: \n", + "\t00 10 04 AC 00 09 C0 CF\n", + "Read 0x4ac: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 00 21\n", + "Read 0x564: \n", + "\t00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\n", + "Write 0x564, Result: \n", + "\t00 10 05 64 00 10 81 07\n", + "Read 0x564: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "Read 0x574: \n", + "\t00 00 00 00\n", + "Write 0x574, Result: \n", + "\t00 10 05 74 00 02 00 CF\n", + "Read 0x574: \n", + "\t10 11 12 13\n", + "Read 0x576: \n", + "\t00 00 00 00\n", + "Write 0x576, Result: \n", + "\t00 10 05 76 00 02 A1 0F\n", + "Read 0x576: \n", + "\t10 11 12 13\n", + "Read 0x578: \n", + "\t01 00 02 00 03 00 04 00 05 00 06 00 07 00 08 00 09 00 0A 00 0B 00 0C 00 0D 00 0E 00 0F 00 10 00\n", + "Write 0x578, Result: \n", + "\t00 10 05 78 00 10 40 C1\n", + "Read 0x578: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n" + ] + } + ], + "source": [ + "def read_data(addr):\n", + " \"\"\" 读取数据 \"\"\"\n", + " ret = com.write(frames[daddr][0])\n", + " time.sleep(0.2)\n", + " frame_recv = com.read_all()\n", + " data_recv = []\n", + " for i in range(3, (len(frame_recv) - 2), 2):\n", + " data_recv.append(frame_recv[i+1])\n", + " data_recv.append(frame_recv[i])\n", + " print(f\"Read {hex(daddr)}: \\n\\t{device.tools.ByteConv.trans_list_to_str(data_recv)}\")\n", + "def write_data(addr):\n", + " \"\"\" 写入数据 \"\"\"\n", + " ret = com.write(frames[daddr][1])\n", + " time.sleep(0.2)\n", + " frame_recv = com.read_all()\n", + " print(f\"Write {hex(daddr)}, Result: \\n\\t{device.tools.ByteConv.trans_list_to_str(frame_recv)}\")\n", + "\n", + "for daddr, dlen in list_param:\n", + " if daddr == 0x4B5:\n", + " continue\n", + " time.sleep(0.2)\n", + " read_data(daddr)\n", + " time.sleep(0.2)\n", + " write_data(daddr)\n", + " time.sleep(0.2)\n", + " read_data(daddr)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Read 0x400: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "Write 0x400, Result:\t00 10 04 00 00 10 C1 24\n", + "Read 0x400: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "\n", + "\n", + "Read 0x410: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "Write 0x410, Result:\t00 10 04 10 00 10 C0 E1\n", + "Read 0x410: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "\n", + "\n", + "Read 0x420: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F\n", + "Write 0x420, Result:\t00 10 04 20 00 20 C0 FA\n", + "Read 0x420: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F\n", + "\n", + "\n", + "Read 0x440: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F\n", + "Write 0x440, Result:\t00 10 04 40 00 20 C0 E4\n", + "Read 0x440: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F\n", + "\n", + "\n", + "Read 0x460: \n", + "\t10 11 12 13\n", + "Write 0x460, Result:\t00 10 04 60 00 02 41 37\n", + "Read 0x460: \n", + "\t10 11 12 13\n", + "\n", + "\n", + "Read 0x462: \n", + "\t10 11 12 13 14 15 16 17 18 19\n", + "Write 0x462, Result:\t00 10 04 62 00 05 A1 35\n", + "Read 0x462: \n", + "\t10 11 12 13 14 15 16 17 18 19\n", + "\n", + "\n", + "Read 0x467: \n", + "\t10 11 12 13 14 15 16 17\n", + "Write 0x467, Result:\t00 10 04 67 00 04 70 F4\n", + "Read 0x467: \n", + "\t10 11 12 13 14 15 16 17\n", + "\n", + "\n", + "Read 0x46b: \n", + "\t10 11 12 13 14 15\n", + "Write 0x46b, Result:\t00 10 04 6B 00 03 F1 35\n", + "Read 0x46b: \n", + "\t10 11 12 13 14 15\n", + "\n", + "\n", + "Read 0x46e: \n", + "\t10 11\n", + "Write 0x46e, Result:\t00 10 04 6E 00 01 60 F5\n", + "Read 0x46e: \n", + "\t10 11\n", + "\n", + "\n", + "Read 0x46f: \n", + "\t10 11\n", + "Write 0x46f, Result:\t00 10 04 6F 00 01 31 35\n", + "Read 0x46f: \n", + "\t10 11\n", + "\n", + "\n", + "Read 0x470: \n", + "\t10 11 12 13\n", + "Write 0x470, Result:\t00 10 04 70 00 02 40 F2\n", + "Read 0x470: \n", + "\t10 11 12 13\n", + "\n", + "\n", + "Read 0x472: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "Write 0x472, Result:\t00 10 04 72 00 10 61 3F\n", + "Read 0x472: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "\n", + "\n", + "Read 0x482: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27\n", + "Write 0x482, Result:\t00 10 04 82 00 0C 60 C5\n", + "Read 0x482: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27\n", + "\n", + "\n", + "Read 0x48e: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27\n", + "Write 0x48e, Result:\t00 10 04 8E 00 0C A0 C6\n", + "Read 0x48e: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27\n", + "\n", + "\n", + "Read 0x49a: \n", + "\t10 11 12 13 14 15 16 17 18 19\n", + "Write 0x49a, Result:\t00 10 04 9A 00 05 20 C4\n", + "Read 0x49a: \n", + "\t10 11 12 13 14 15 16 17 18 19\n", + "\n", + "\n", + "Read 0x49f: \n", + "\t10 11 12 13 14 15 16 17 18 19\n", + "Write 0x49f, Result:\t00 10 04 9F 00 05 30 C5\n", + "Read 0x49f: \n", + "\t10 11 12 13 14 15 16 17 18 19\n", + "\n", + "\n", + "Read 0x4a4: \n", + "\t10 11 12 13 14 15 16 17 18 19\n", + "Write 0x4a4, Result:\t00 10 04 A4 00 05 41 08\n", + "Read 0x4a4: \n", + "\t10 11 12 13 14 15 16 17 18 19\n", + "\n", + "\n", + "Read 0x4a9: \n", + "\t00 00 00 00\n", + "Write 0x4a9, Result:\t00 90 EB 5D 8F\n", + "Read 0x4a9: \n", + "\t00 00 00 00\n", + "\n", + "\n", + "Read 0x4ab: \n", + "\t00 00\n", + "Write 0x4ab, Result:\t00 90 EB 5D 8F\n", + "Read 0x4ab: \n", + "\t00 00\n", + "\n", + "\n", + "Read 0x4ac: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 00 21\n", + "Write 0x4ac, Result:\t00 10 04 AC 00 09 C0 CF\n", + "Read 0x4ac: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 00 21\n", + "\n", + "\n", + "Read 0x564: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "Write 0x564, Result:\t00 10 05 64 00 10 81 07\n", + "Read 0x564: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "\n", + "\n", + "Read 0x574: \n", + "\t10 11 12 13\n", + "Write 0x574, Result:\t00 10 05 74 00 02 00 CF\n", + "Read 0x574: \n", + "\t10 11 12 13\n", + "\n", + "\n", + "Read 0x576: \n", + "\t10 11 12 13\n", + "Write 0x576, Result:\t00 10 05 76 00 02 A1 0F\n", + "Read 0x576: \n", + "\t10 11 12 13\n", + "\n", + "\n", + "Read 0x578: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "Write 0x578, Result:\t00 10 05 78 00 10 40 C1\n", + "Read 0x578: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "\n", + "\n" + ] + } + ], + "source": [ + "def read_data(addr):\n", + " \"\"\" 读取数据 \"\"\"\n", + " ret = com.write(frames[daddr][0])\n", + " time.sleep(0.2)\n", + " frame_recv = com.read_all()\n", + " data_recv = []\n", + " for i in range(3, (len(frame_recv) - 2), 2):\n", + " data_recv.append(frame_recv[i+1])\n", + " data_recv.append(frame_recv[i])\n", + " print(f\"Read {hex(daddr)}: \\n\\t{device.tools.ByteConv.trans_list_to_str(data_recv)}\")\n", + "def write_data(addr):\n", + " \"\"\" 写入数据 \"\"\"\n", + " ret = com.write(frames[daddr][1])\n", + " time.sleep(0.2)\n", + " frame_recv = com.read_all()\n", + " print(f\"Write {hex(daddr)}, Result:\\t{device.tools.ByteConv.trans_list_to_str(frame_recv)}\")\n", + "\n", + "for daddr, dlen in list_param:\n", + " if daddr == 0x4B5:\n", + " continue\n", + " time.sleep(0.2)\n", + " read_data(daddr)\n", + " time.sleep(0.2)\n", + " write_data(daddr)\n", + " time.sleep(0.2)\n", + " read_data(daddr)\n", + " print('\\n')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "com.close()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "com.open()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Read 0x400: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "\n", + "\n", + "Read 0x410: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "\n", + "\n", + "Read 0x420: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F\n", + "\n", + "\n", + "Read 0x440: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F\n", + "\n", + "\n", + "Read 0x460: \n", + "\tFF FF FF FF\n", + "\n", + "\n", + "Read 0x462: \n", + "\t00 00 00 00 00 00 00 00 00 00\n", + "\n", + "\n", + "Read 0x467: \n", + "\t00 00 00 00 00 00 00 00\n", + "\n", + "\n", + "Read 0x46b: \n", + "\t00 00 00 00 00 00\n", + "\n", + "\n", + "Read 0x46e: \n", + "\t10 11\n", + "\n", + "\n", + "Read 0x46f: \n", + "\t10 11\n", + "\n", + "\n", + "Read 0x470: \n", + "\t10 11 12 13\n", + "\n", + "\n", + "Read 0x472: \n", + "\t78 78 78 78 50 5F 6F 72 6F 74 6F 63 43 6C 76 6F 72 65 65 74 00 72 00 00 00 00 00 00 00 00 00 00\n", + "\n", + "\n", + "Read 0x482: \n", + "\t72 50 74 6F 63 6F 6C 6F 6F 43 65 76 74 72 72 65 00 00 00 00 00 00 00 00\n", + "\n", + "\n", + "Read 0x48e: \n", + "\t00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\n", + "\n", + "\n", + "Read 0x49a: \n", + "\t00 00 00 00 00 00 00 00 00 00\n", + "\n", + "\n", + "Read 0x49f: \n", + "\t56 53 31 30 30 2E 00 31 00 00\n", + "\n", + "\n", + "Read 0x4a4: \n", + "\t56 48 31 30 30 2E 00 31 00 00\n", + "\n", + "\n", + "Read 0x4a9: \n", + "\t00 00 00 00\n", + "\n", + "\n", + "Read 0x4ab: \n", + "\t00 00\n", + "\n", + "\n", + "Read 0x4ac: \n", + "\t03 02 00 05 93 04 12 E0 F6 09 09 12 00 60 00 00 00 00\n", + "\n", + "\n", + "Read 0x564: \n", + "\t00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\n", + "\n", + "\n", + "Read 0x574: \n", + "\t00 00 00 00\n", + "\n", + "\n", + "Read 0x576: \n", + "\t00 00 00 00\n", + "\n", + "\n", + "Read 0x578: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "\n", + "\n" + ] + } + ], + "source": [ + "for daddr, dlen in list_param:\n", + " if daddr == 0x4B5:\n", + " continue\n", + " time.sleep(0.2)\n", + " read_data(daddr)\n", + " print('\\n')" + ] + } + ], + "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/data_analysis.py b/source/data_analysis.py index 6569e33..5053c4b 100644 --- a/source/data_analysis.py +++ b/source/data_analysis.py @@ -547,8 +547,8 @@ if __name__=='__main__': if not (file_db:= Path(path_db)).exists(): file_db.touch() - API_HEADER['Cookie'] = "HWWAFSESID=ac80388ba903b6ae67; HWWAFSESTIME=1735517672864; dc04ed2361044be8a9355f6efb378cf2=WyIzNTI0NjE3OTgzIl0" - API_HEADER['authorization'] = 'Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiIl0sInVzZXJfbmFtZSI6IndlYl9tYW5hZ2V8d2FuZ2xlaTQiLCJzY29wZSI6WyJhbGwiXSwiYXRpIjoiMzkzMTUzZGYtZDBkYS00YmM1LWJiZmMtZjdjMTQxYTEzOTU0IiwiZXhwIjoxNzM1OTcyNTA0LCJ1c2VySWQiOjI0Mjg1LCJqdGkiOiIwMTY1NDg1MC1mZjIwLTRkMzQtYTQ4ZC03NmRiZTk3MmQ3YWQiLCJjbGllbnRfaWQiOiJ3ZWJfbWFuYWdlIn0.diNffgdMwBp7_IsjTAwN-YYp8_zpRp5pGn7HJAar51R3jpJyeROFV1g8T6jC_d-bfqS59N649llL3kJPguFfTrwJSu7NS4oeD2YNPwuhpQIeMbszp48NZ3zKyct6COpMPTWRVMVygcfsKfkYnDJQSMyanfQCtLinfDhNq3ektLtPFxLsf54noBu8R_MJ-Pkdjiip3koA8Jhl2eL2Af4U-nd9UAjNaMT5HI0scC9ViEJshzgyxvOi4Pabzw-JI5ZRYzWd1rNZo7b1_s7OAYcqj2hteW1JdC7_6hTHZxpEjzRBvhuvpwHDtsBvAgGUI6hPoYkOpGNPG2QfW7Hyc7TWtA' + API_HEADER['Cookie'] = "HWWAFSESID=7e7df7972959068f88; HWWAFSESTIME=1736230263315; dc04ed2361044be8a9355f6efb378cf2=WyIzNTI0NjE3OTgzIl0" + API_HEADER['authorization'] = 'Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiIl0sInVzZXJfbmFtZSI6IndlYl9tYW5hZ2V8d2FuZ2xlaTQiLCJzY29wZSI6WyJhbGwiXSwiZXhwIjoxNzM2MjM3NTMxLCJ1c2VySWQiOjI0Mjg1LCJqdGkiOiIzMWRlNDRiMy05ZTNjLTQwOTEtOWUzMS0wYWFjNTYzZDljZWIiLCJjbGllbnRfaWQiOiJ3ZWJfbWFuYWdlIn0.INV4DumSZkZZ68TW0DTF1XlIIFuoHD90_JefmmOBxcHPDxHAZPzG4JX9BEcEPrRLfSENtfYW7XNCluzB9nxs_pBTT9iu--tPZwlLAiPD7LZ552VdoAFEsYaigFmwxtedTLTzzm2GVbUReInd1dARjgaK0mKxljkKfGkTJURobpHC9Aw5mu25fSWjv7U9sZ0gOmpCuFr_OukEssi0hV8lvztfN5Ax_E1NObbteY2e8tUh6xVj49pHwDPnQScofGTaSviuMO46zmim6X3AKUJ-jDa95dOygKhk704AiA2nVCHXrlVkJI7zYLZB_zZTw3EhyonpksYS8NPp9wLlearWqg' data_lamina = Lamina_Data('sqlite:///' + path_db) # 依据站点内设备爬取整个站点的实时与历史数据 @@ -561,8 +561,8 @@ if __name__=='__main__': # data = data_lamina.spider_station('TTE0102DX2410091439', yesterday_midnight_timestamp, today_midnight_timestamp) # 读取站点历史数据 - save_station_by_file1(data_lamina) - # save_station_by_file2(data_lamina, "result\station_Q0103.xlsx") + # save_station_by_file1(data_lamina) + save_station_by_file2(data_lamina, "result\station_Q0107.xlsx") # 网站令牌更新 body = { diff --git a/source/dev_LaminaAdapter.py b/source/dev_LaminaAdapter.py index 820bb52..ffd8d23 100644 --- a/source/dev_LaminaAdapter.py +++ b/source/dev_LaminaAdapter.py @@ -130,6 +130,67 @@ def test(): time.sleep(2) dev_lamina.frame_read(0x0170, 0x30) + if 0: + dev_lamina.flag_print = False + dev_lamina.frame_write_one(0x52, 0x01) + time.sleep(6) + dev_lamina.frame_read(0x69, 0x02) + for value in [40, 41.9, 42, 42.1, 56.5, 57, 57.5, 57.9, 58, 58.1, 59]: + time.sleep(0.5) + result = dev_lamina.frame_write_one(0x21, int(value * 10)) + print(f"Write Value: {value}, result: {'Seccusss' if result else 'Fail'}.") + time.sleep(0.5) + dev_lamina.frame_read(0x21,1) + time.sleep(0.5) + value = 46 + result = dev_lamina.frame_write_one(0x69, int(value * 10)) + print(f"Write Value: {value} in Addr: {0x69}, result: {'Seccusss' if result else 'Fail'}.") + time.sleep(0.5) + value = 60 + result = dev_lamina.frame_write_one(0x6A, int(value * 10)) + print(f"Write Value: {value} in Addr: {0x6A}, result: {'Seccusss' if result else 'Fail'}.") + for value in [45, 45.9, 46, 46.1, 56.5, 57, 57.5, 58, 59.9, 60, 60.1, 61]: + time.sleep(0.5) + result = dev_lamina.frame_write_one(0x21, int(value * 10)) + print(f"Write Value: {value}, result: {'Seccusss' if result else 'Fail'}.") + time.sleep(0.5) + dev_lamina.frame_read(0x21,1) + time.sleep(0.5) + dev_lamina.frame_write_one(0x53, 0x01) + time.sleep(4.5) + dev_lamina.frame_read(0x21, 1) + time.sleep(0.5) + dev_lamina.frame_read(0x69, 2) + dev_lamina.flag_print = True + + if 0: # 并机功率限值测试 + dev_lamina.flag_print = False + step = 0 + time_start = time.time() + time_interval = 120 + list_power_limit = [650, 300, 200, 150, 120, 100, 80, 70, 50, 25, 10, 5, 1, 0.1, 0, 650] + while True: + time.sleep(1) + print(time.ctime()) + dev_lamina.frame_read(0x0E, 0x20) + if time.time() - time_start > time_interval: + if step >= len(list_power_limit): + break + time.sleep(0.5) + time_start = time.time() + value = list_power_limit[step] + result = dev_lamina.frame_write_dual(0x1F, int(value * 1000)) + print(f"Write Value: {value} in Addr: 0x1F by Time: {time.ctime(time_start)}. \n\tresult: {'Seccusss' if result else 'Fail'}.") + step += 1 + dev_lamina.flag_print = True + if 0: # 启停机条件测试 + dev_lamina.flag_print = False + dev_lamina.frame_read(0x60, 0x0B) + while True: + time.sleep(1) + print(time.ctime()) + dev_lamina.frame_read(0x0E, 0x20) + dev_lamina.flag_print = True if __name__=='__main__': mode_config = { @@ -146,7 +207,7 @@ if __name__=='__main__': 'time_out': 3, 'time_gap': 0.1, 'retry': 3, 'retry_sub': 10}, } - dev_lamina = LaminaAdapter(type_dev="SLCP001", **mode_config['Debug']) + dev_lamina = LaminaAdapter(type_dev="SLCP101", **mode_config['Debug']) dev_lamina.frame_read(0x0100, 0x20) # dev_lamina.frame_write_one(0x51, 0x01) diff --git a/source/dev_inverter.ipynb b/source/dev_inverter.ipynb new file mode 100644 index 0000000..de2efbb --- /dev/null +++ b/source/dev_inverter.ipynb @@ -0,0 +1,1280 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "ename": "ModuleNotFoundError", + "evalue": "No module named 'device'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[1], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mdevice\u001b[39;00m\n", + "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'device'" + ] + } + ], + "source": [ + "import device" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'d:\\\\WorkSpace\\\\UserTool\\\\SelfTool\\\\FrameParser'" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "%pwd" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import source.device as device" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "my_block = {\n", + " 'addr_dev' : 0x00,\n", + " 'data_define': None,\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bfda458c-1c82-43cc-bc0e-8eed6f1c53f7", + "metadata": {}, + "outputs": [], + "source": [ + "list_param = [\n", + "(0x0400, 16),\n", + "(0x0410, 16),\n", + "(0x0420, 32),\n", + "(0x0440, 32),\n", + "(0x0460, 2),\n", + "(0x0462, 5),\n", + "(0x0467, 4),\n", + "(0x046B, 3),\n", + "(0x046E, 1),\n", + "(0x046F, 1),\n", + "(0x0470, 2),\n", + "(0x0472, 16),\n", + "(0x0482, 12),\n", + "(0x048E, 12),\n", + "(0x049A, 5),\n", + "(0x049F, 5),\n", + "(0x04A4, 5),\n", + "(0x04A9, 2),\n", + "(0x04AB, 1),\n", + "(0x04AC, 9),\n", + "(0x04B5, 175),\n", + "(0x0564, 16),\n", + "(0x0574, 2),\n", + "(0x0576, 2),\n", + "(0x0578, 16),\n", + "]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "00 03 04 00 00 10 44 E7\n", + "00 03 04 10 00 10 45 22\n", + "00 03 04 20 00 20 45 39\n", + "00 03 04 40 00 20 45 27\n", + "00 03 04 60 00 02 C4 F4\n", + "00 03 04 62 00 05 24 F6\n", + "00 03 04 67 00 04 F5 37\n", + "00 03 04 6B 00 03 74 F6\n", + "00 03 04 6E 00 01 E5 36\n", + "00 03 04 6F 00 01 B4 F6\n", + "00 03 04 70 00 02 C5 31\n", + "00 03 04 72 00 10 E4 FC\n", + "00 03 04 82 00 0C E5 06\n", + "00 03 04 8E 00 0C 25 05\n", + "00 03 04 9A 00 05 A5 07\n", + "00 03 04 9F 00 05 B5 06\n", + "00 03 04 A4 00 05 C4 CB\n", + "00 03 04 A9 00 02 14 CA\n", + "00 03 04 AB 00 01 F5 0B\n", + "00 03 04 AC 00 09 45 0C\n", + "00 03 04 B5 00 AF 14 B1\n", + "00 03 05 64 00 10 04 C4\n", + "00 03 05 74 00 02 85 0C\n", + "00 03 05 76 00 02 24 CC\n", + "00 03 05 78 00 10 C5 02\n" + ] + } + ], + "source": [ + "my_block = {\n", + " 'addr_dev' : 0x00,\n", + " 'type': 'read',\n", + " 'data_addr': 0x00,\n", + " 'data_len': 0x00,\n", + " 'data_define': {},\n", + "}\n", + "\n", + "for addr, len in list_param:\n", + " my_block['data_addr'] = addr\n", + " my_block['data_len'] = len\n", + " frame = device.function.protocols.make_frame_modbus(my_block)\n", + " print(device.tools.ByteConv.trans_list_to_str(frame))\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import source.device as device" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "63803d7f-4b39-4990-9417-e8b5fcdca397", + "metadata": {}, + "outputs": [], + "source": [ + "list_param = [\n", + "(0x0400, 16),\n", + "(0x0410, 16),\n", + "(0x0420, 32),\n", + "(0x0440, 32),\n", + "(0x0460, 2),\n", + "(0x0462, 5),\n", + "(0x0467, 4),\n", + "(0x046B, 3),\n", + "(0x046E, 1),\n", + "(0x046F, 1),\n", + "(0x0470, 2),\n", + "(0x0472, 16),\n", + "(0x0482, 12),\n", + "(0x048E, 12),\n", + "(0x049A, 5),\n", + "(0x049F, 5),\n", + "(0x04A4, 5),\n", + "(0x04A9, 2),\n", + "(0x04AB, 1),\n", + "(0x04AC, 9),\n", + "(0x04B5, 175),\n", + "(0x0564, 16),\n", + "(0x0574, 2),\n", + "(0x0576, 2),\n", + "(0x0578, 16),\n", + "]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'frame' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[3], line 13\u001b[0m\n\u001b[0;32m 11\u001b[0m my_block[\u001b[39m'\u001b[39m\u001b[39mdata_len\u001b[39m\u001b[39m'\u001b[39m] \u001b[39m=\u001b[39m \u001b[39mlen\u001b[39m\n\u001b[0;32m 12\u001b[0m frame_read \u001b[39m=\u001b[39m device\u001b[39m.\u001b[39mfunction\u001b[39m.\u001b[39mprotocols\u001b[39m.\u001b[39mmake_frame_modbus(my_block)\n\u001b[1;32m---> 13\u001b[0m \u001b[39mprint\u001b[39m(device\u001b[39m.\u001b[39mtools\u001b[39m.\u001b[39mByteConv\u001b[39m.\u001b[39mtrans_list_to_str(frame))\n\u001b[0;32m 14\u001b[0m my_block[\u001b[39m'\u001b[39m\u001b[39mtype\u001b[39m\u001b[39m'\u001b[39m] \u001b[39m=\u001b[39m \u001b[39m'\u001b[39m\u001b[39mwrite_str\u001b[39m\u001b[39m'\u001b[39m\n\u001b[0;32m 15\u001b[0m my_block[\u001b[39m'\u001b[39m\u001b[39mdata_val\u001b[39m\u001b[39m'\u001b[39m] \u001b[39m=\u001b[39m \u001b[39mlist\u001b[39m(\u001b[39mrange\u001b[39m(\u001b[39m0x10\u001b[39m, \u001b[39m0x10\u001b[39m \u001b[39m+\u001b[39m \u001b[39mlen\u001b[39m))\n", + "\u001b[1;31mNameError\u001b[0m: name 'frame' is not defined" + ] + } + ], + "source": [ + "my_block = {\n", + " 'addr_dev' : 0x00,\n", + " 'type': 'read',\n", + " 'data_addr': 0x00,\n", + " 'data_len': 0x00,\n", + " 'data_define': {},\n", + "}\n", + "\n", + "for addr, len in list_param:\n", + " my_block['data_addr'] = addr\n", + " my_block['data_len'] = len\n", + " frame_read = device.function.protocols.make_frame_modbus(my_block)\n", + " print(device.tools.ByteConv.trans_list_to_str(frame))\n", + " my_block['type'] = 'write_str'\n", + " my_block['data_val'] = list(range(0x10, 0x10 + len))\n", + " frame_write = device.function.protocols.make_frame_modbus(my_block)\n", + " print(device.tools.ByteConv.trans_list_to_str(frame))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "00 03 04 00 00 10 44 E7\n", + "00 10 04 00 00 08 10 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E F0 74\n", + "00 10 04 10 00 08 10 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 32 E7\n", + "00 10 04 10 00 08 10 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 32 E7\n", + "00 10 04 20 00 08 10 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 77 13\n", + "00 10 04 20 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E C3 8F\n", + "00 10 04 40 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E CC 07\n", + "00 10 04 40 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E CC 07\n", + "00 10 04 60 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E C8 BF\n", + "00 10 04 60 00 01 02 11 10 EA 3C\n", + "00 10 04 62 00 01 02 11 10 EB DE\n", + "00 10 04 62 00 02 05 11 10 13 12 F6 66\n", + "00 10 04 67 00 02 05 11 10 13 12 36 59\n", + "00 10 04 67 00 02 04 11 10 13 12 0B 99\n", + "00 10 04 6B 00 02 04 11 10 13 12 0B CC\n", + "00 10 04 6B 00 01 03 11 10 BA 87\n", + "00 10 04 6E 00 01 03 11 10 BA D2\n", + "00 10 04 6E 00 00 01 35 78\n", + "00 10 04 6F 00 00 01 34 84\n", + "00 10 04 6F 00 00 01 34 84\n", + "00 10 04 70 00 00 01 33 50\n", + "00 10 04 70 00 01 02 11 10 E8 AC\n", + "00 10 04 72 00 01 02 11 10 E9 4E\n", + "00 10 04 72 00 08 10 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E C2 AD\n", + "00 10 04 82 00 08 10 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 96 48\n", + "00 10 04 82 00 06 0C 11 10 13 12 15 14 17 16 19 18 1B 1A 0B 5B\n", + "00 10 04 8E 00 06 0C 11 10 13 12 15 14 17 16 19 18 1B 1A 0E 5E\n", + "00 10 04 8E 00 06 0C 11 10 13 12 15 14 17 16 19 18 1B 1A 0E 5E\n", + "00 10 04 9A 00 06 0C 11 10 13 12 15 14 17 16 19 18 1B 1A 01 51\n", + "00 10 04 9A 00 02 05 11 10 13 12 F8 84\n", + "00 10 04 9F 00 02 05 11 10 13 12 38 BB\n", + "00 10 04 9F 00 02 05 11 10 13 12 38 BB\n", + "00 10 04 A4 00 02 05 11 10 13 12 7A 1C\n", + "00 10 04 A4 00 02 05 11 10 13 12 7A 1C\n", + "00 10 04 A9 00 02 05 11 10 13 12 BB 85\n", + "00 10 04 A9 00 01 02 11 10 FB A5\n", + "00 10 04 AB 00 01 02 11 10 FA 47\n", + "00 10 04 AB 00 00 01 09 B4\n", + "00 10 04 AC 00 00 01 08 C0\n", + "00 10 04 AC 00 04 09 11 10 13 12 15 14 17 16 46 28\n", + "00 10 04 B5 00 04 09 11 10 13 12 15 14 17 16 9B CB\n", + "00 10 04 B5 00 57 AF 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 31 30 33 32 35 34 37 36 39 38 3B 3A 3D 3C 3F 3E 41 40 43 42 45 44 47 46 49 48 4B 4A 4D 4C 4F 4E 51 50 53 52 55 54 57 56 59 58 5B 5A 5D 5C 5F 5E 61 60 63 62 65 64 67 66 69 68 6B 6A 6D 6C 6F 6E 71 70 73 72 75 74 77 76 79 78 7B 7A 7D 7C 7F 7E 81 80 83 82 85 84 87 86 89 88 8B 8A 8D 8C 8F 8E 91 90 93 92 95 94 97 96 99 98 9B 9A 9D 9C 9F 9E A1 A0 A3 A2 A5 A4 A7 A6 A9 A8 AB AA AD AC AF AE B1 B0 B3 B2 B5 B4 B7 B6 B9 B8 BB BA BD BC 72 BF\n", + "00 10 05 64 00 57 AF 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 31 30 33 32 35 34 37 36 39 38 3B 3A 3D 3C 3F 3E 41 40 43 42 45 44 47 46 49 48 4B 4A 4D 4C 4F 4E 51 50 53 52 55 54 57 56 59 58 5B 5A 5D 5C 5F 5E 61 60 63 62 65 64 67 66 69 68 6B 6A 6D 6C 6F 6E 71 70 73 72 75 74 77 76 79 78 7B 7A 7D 7C 7F 7E 81 80 83 82 85 84 87 86 89 88 8B 8A 8D 8C 8F 8E 91 90 93 92 95 94 97 96 99 98 9B 9A 9D 9C 9F 9E A1 A0 A3 A2 A5 A4 A7 A6 A9 A8 AB AA AD AC AF AE B1 B0 B3 B2 B5 B4 B7 B6 B9 B8 BB BA BD BC 10 3E\n", + "00 10 05 64 00 08 10 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 98 89\n", + "00 10 05 74 00 08 10 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 5A 1A\n", + "00 10 05 74 00 01 02 11 10 F9 E8\n", + "00 10 05 76 00 01 02 11 10 F8 0A\n", + "00 10 05 76 00 01 02 11 10 F8 0A\n", + "00 10 05 78 00 01 02 11 10 F9 24\n", + "00 10 05 78 00 08 10 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 4A D7\n" + ] + } + ], + "source": [ + "my_block = {\n", + " 'addr_dev' : 0x00,\n", + " 'type': 'read',\n", + " 'data_addr': 0x00,\n", + " 'data_len': 0x00,\n", + " 'data_define': {},\n", + "}\n", + "\n", + "for addr, len in list_param:\n", + " my_block['data_addr'] = addr\n", + " my_block['data_len'] = len\n", + " frame_read = device.function.protocols.make_frame_modbus(my_block)\n", + " print(device.tools.ByteConv.trans_list_to_str(frame_read))\n", + " my_block['type'] = 'write_str'\n", + " my_block['data_val'] = list(range(0x10, 0x10 + len))\n", + " frame_write = device.function.protocols.make_frame_modbus(my_block)\n", + " print(device.tools.ByteConv.trans_list_to_str(frame_write))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "00 03 04 00 00 10 44 E7\n", + "00 10 04 00 00 08 10 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E F0 74\n", + "00 03 04 10 00 10 45 22\n", + "00 10 04 10 00 08 10 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 32 E7\n", + "00 03 04 20 00 20 45 39\n", + "00 10 04 20 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E C3 8F\n", + "00 03 04 40 00 20 45 27\n", + "00 10 04 40 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E CC 07\n", + "00 03 04 60 00 02 C4 F4\n", + "00 10 04 60 00 01 02 11 10 EA 3C\n", + "00 03 04 62 00 05 24 F6\n", + "00 10 04 62 00 02 05 11 10 13 12 F6 66\n", + "00 03 04 67 00 04 F5 37\n", + "00 10 04 67 00 02 04 11 10 13 12 0B 99\n", + "00 03 04 6B 00 03 74 F6\n", + "00 10 04 6B 00 01 03 11 10 BA 87\n", + "00 03 04 6E 00 01 E5 36\n", + "00 10 04 6E 00 00 01 35 78\n", + "00 03 04 6F 00 01 B4 F6\n", + "00 10 04 6F 00 00 01 34 84\n", + "00 03 04 70 00 02 C5 31\n", + "00 10 04 70 00 01 02 11 10 E8 AC\n", + "00 03 04 72 00 10 E4 FC\n", + "00 10 04 72 00 08 10 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E C2 AD\n", + "00 03 04 82 00 0C E5 06\n", + "00 10 04 82 00 06 0C 11 10 13 12 15 14 17 16 19 18 1B 1A 0B 5B\n", + "00 03 04 8E 00 0C 25 05\n", + "00 10 04 8E 00 06 0C 11 10 13 12 15 14 17 16 19 18 1B 1A 0E 5E\n", + "00 03 04 9A 00 05 A5 07\n", + "00 10 04 9A 00 02 05 11 10 13 12 F8 84\n", + "00 03 04 9F 00 05 B5 06\n", + "00 10 04 9F 00 02 05 11 10 13 12 38 BB\n", + "00 03 04 A4 00 05 C4 CB\n", + "00 10 04 A4 00 02 05 11 10 13 12 7A 1C\n", + "00 03 04 A9 00 02 14 CA\n", + "00 10 04 A9 00 01 02 11 10 FB A5\n", + "00 03 04 AB 00 01 F5 0B\n", + "00 10 04 AB 00 00 01 09 B4\n", + "00 03 04 AC 00 09 45 0C\n", + "00 10 04 AC 00 04 09 11 10 13 12 15 14 17 16 46 28\n", + "00 03 04 B5 00 AF 14 B1\n", + "00 10 04 B5 00 57 AF 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 31 30 33 32 35 34 37 36 39 38 3B 3A 3D 3C 3F 3E 41 40 43 42 45 44 47 46 49 48 4B 4A 4D 4C 4F 4E 51 50 53 52 55 54 57 56 59 58 5B 5A 5D 5C 5F 5E 61 60 63 62 65 64 67 66 69 68 6B 6A 6D 6C 6F 6E 71 70 73 72 75 74 77 76 79 78 7B 7A 7D 7C 7F 7E 81 80 83 82 85 84 87 86 89 88 8B 8A 8D 8C 8F 8E 91 90 93 92 95 94 97 96 99 98 9B 9A 9D 9C 9F 9E A1 A0 A3 A2 A5 A4 A7 A6 A9 A8 AB AA AD AC AF AE B1 B0 B3 B2 B5 B4 B7 B6 B9 B8 BB BA BD BC 72 BF\n", + "00 03 05 64 00 10 04 C4\n", + "00 10 05 64 00 08 10 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 98 89\n", + "00 03 05 74 00 02 85 0C\n", + "00 10 05 74 00 01 02 11 10 F9 E8\n", + "00 03 05 76 00 02 24 CC\n", + "00 10 05 76 00 01 02 11 10 F8 0A\n", + "00 03 05 78 00 10 C5 02\n", + "00 10 05 78 00 08 10 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 4A D7\n" + ] + } + ], + "source": [ + "my_block = {\n", + " 'addr_dev' : 0x00,\n", + " 'data_define': {},\n", + "}\n", + "\n", + "for addr, len in list_param:\n", + " my_block['type'] = 'read'\n", + " my_block['data_addr'] = addr\n", + " my_block['data_len'] = len\n", + " frame_read = device.function.protocols.make_frame_modbus(my_block)\n", + " print(device.tools.ByteConv.trans_list_to_str(frame_read))\n", + " my_block['type'] = 'write_str'\n", + " my_block['data_val'] = list(range(0x10, 0x10 + len))\n", + " frame_write = device.function.protocols.make_frame_modbus(my_block)\n", + " print(device.tools.ByteConv.trans_list_to_str(frame_write))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "00 03 04 00 00 10 44 E7\n", + "00 10 04 00 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E C7 37\n", + "00 03 04 10 00 10 45 22\n", + "00 10 04 10 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E C5 6B\n", + "00 03 04 20 00 20 45 39\n", + "00 10 04 20 00 20 40 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 31 30 33 32 35 34 37 36 39 38 3B 3A 3D 3C 3F 3E 41 40 43 42 45 44 47 46 49 48 4B 4A 4D 4C 4F 4E BD 9E\n", + "00 03 04 40 00 20 45 27\n", + "00 10 04 40 00 20 40 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 31 30 33 32 35 34 37 36 39 38 3B 3A 3D 3C 3F 3E 41 40 43 42 45 44 47 46 49 48 4B 4A 4D 4C 4F 4E 3B 36\n", + "00 03 04 60 00 02 C4 F4\n", + "00 10 04 60 00 02 04 11 10 13 12 4A 7F\n", + "00 03 04 62 00 05 24 F6\n", + "00 10 04 62 00 05 0A 11 10 13 12 15 14 17 16 19 18 04 6D\n", + "00 03 04 67 00 04 F5 37\n", + "00 10 04 67 00 04 08 11 10 13 12 15 14 17 16 AD 22\n", + "00 03 04 6B 00 03 74 F6\n", + "00 10 04 6B 00 03 06 11 10 13 12 15 14 EB F6\n", + "00 03 04 6E 00 01 E5 36\n", + "00 10 04 6E 00 01 02 11 10 EB 12\n", + "00 03 04 6F 00 01 B4 F6\n", + "00 10 04 6F 00 01 02 11 10 EA C3\n", + "00 03 04 70 00 02 C5 31\n", + "00 10 04 70 00 02 04 11 10 13 12 4B 73\n", + "00 03 04 72 00 10 E4 FC\n", + "00 10 04 72 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 4B 18\n", + "00 03 04 82 00 0C E5 06\n", + "00 10 04 82 00 0C 18 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 C2 58\n", + "00 03 04 8E 00 0C 25 05\n", + "00 10 04 8E 00 0C 18 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 DF 98\n", + "00 03 04 9A 00 05 A5 07\n", + "00 10 04 9A 00 05 0A 11 10 13 12 15 14 17 16 19 18 FD 55\n", + "00 03 04 9F 00 05 B5 06\n", + "00 10 04 9F 00 05 0A 11 10 13 12 15 14 17 16 19 18 F8 50\n", + "00 03 04 A4 00 05 C4 CB\n", + "00 10 04 A4 00 05 0A 11 10 13 12 15 14 17 16 19 18 C2 AB\n", + "00 03 04 A9 00 02 14 CA\n", + "00 10 04 A9 00 02 04 11 10 13 12 86 45\n", + "00 03 04 AB 00 01 F5 0B\n", + "00 10 04 AB 00 01 02 11 10 FA 47\n", + "00 03 04 AC 00 09 45 0C\n", + "00 10 04 AC 00 09 12 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 7F E1\n", + "00 03 04 B5 00 AF 14 B1\n" + ] + }, + { + "ename": "ValueError", + "evalue": "byte must be in range(0, 256)", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[1], line 25\u001b[0m, in \u001b[0;36m__VSCODE_wrap_run_cell..wrapper\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 24\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[1;32m---> 25\u001b[0m store_history \u001b[39m=\u001b[39m args[\u001b[39m2\u001b[39m] \u001b[39mif\u001b[39;00m \u001b[39mlen\u001b[39;49m(args) \u001b[39m>\u001b[39m \u001b[39m2\u001b[39m \u001b[39melse\u001b[39;00m kwargs[\u001b[39m\"\u001b[39m\u001b[39mstore_history\u001b[39m\u001b[39m\"\u001b[39m]\n\u001b[0;32m 26\u001b[0m \u001b[39mif\u001b[39;00m store_history:\n", + "\u001b[1;31mTypeError\u001b[0m: 'int' object is not callable", + "\nDuring handling of the above exception, another exception occurred:\n", + "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[6], line 14\u001b[0m\n\u001b[0;32m 12\u001b[0m my_block[\u001b[39m'\u001b[39m\u001b[39mtype\u001b[39m\u001b[39m'\u001b[39m] \u001b[39m=\u001b[39m \u001b[39m'\u001b[39m\u001b[39mwrite_str\u001b[39m\u001b[39m'\u001b[39m\n\u001b[0;32m 13\u001b[0m my_block[\u001b[39m'\u001b[39m\u001b[39mdata_val\u001b[39m\u001b[39m'\u001b[39m] \u001b[39m=\u001b[39m \u001b[39mlist\u001b[39m(\u001b[39mrange\u001b[39m(\u001b[39m0x10\u001b[39m, \u001b[39m0x10\u001b[39m \u001b[39m+\u001b[39m \u001b[39m2\u001b[39m \u001b[39m*\u001b[39m \u001b[39mlen\u001b[39m))\n\u001b[1;32m---> 14\u001b[0m frame_write \u001b[39m=\u001b[39m device\u001b[39m.\u001b[39;49mfunction\u001b[39m.\u001b[39;49mprotocols\u001b[39m.\u001b[39;49mmake_frame_modbus(my_block)\n\u001b[0;32m 15\u001b[0m \u001b[39mprint\u001b[39m(device\u001b[39m.\u001b[39mtools\u001b[39m.\u001b[39mByteConv\u001b[39m.\u001b[39mtrans_list_to_str(frame_write))\n", + "File \u001b[1;32md:\\WorkSpace\\UserTool\\SelfTool\\FrameParser\\source\\device\\function\\protocols.py:169\u001b[0m, in \u001b[0;36mmake_frame_modbus\u001b[1;34m(block)\u001b[0m\n\u001b[0;32m 166\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[0;32m 167\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mException\u001b[39;00m(\u001b[39m\"\u001b[39m\u001b[39mModbus Frame Type Error.\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[1;32m--> 169\u001b[0m crc \u001b[39m=\u001b[39m calculator\u001b[39m.\u001b[39mchecksum(\u001b[39mbytearray\u001b[39;49m(frame))\n\u001b[0;32m 170\u001b[0m frame\u001b[39m.\u001b[39mappend(crc \u001b[39m%\u001b[39m \u001b[39m256\u001b[39m)\n\u001b[0;32m 171\u001b[0m frame\u001b[39m.\u001b[39mappend(crc \u001b[39m/\u001b[39m\u001b[39m/\u001b[39m \u001b[39m256\u001b[39m)\n", + "\u001b[1;31mValueError\u001b[0m: byte must be in range(0, 256)" + ] + } + ], + "source": [ + "my_block = {\n", + " 'addr_dev' : 0x00,\n", + " 'data_define': {},\n", + "}\n", + "\n", + "for addr, len in list_param:\n", + " my_block['type'] = 'read'\n", + " my_block['data_addr'] = addr\n", + " my_block['data_len'] = len\n", + " frame_read = device.function.protocols.make_frame_modbus(my_block)\n", + " print(device.tools.ByteConv.trans_list_to_str(frame_read))\n", + " my_block['type'] = 'write_str'\n", + " my_block['data_val'] = list(range(0x10, 0x10 + 2 * len))\n", + " frame_write = device.function.protocols.make_frame_modbus(my_block)\n", + " print(device.tools.ByteConv.trans_list_to_str(frame_write))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "00 03 04 00 00 10 44 E7\n", + "00 10 04 00 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E C7 37\n", + "00 03 04 10 00 10 45 22\n", + "00 10 04 10 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E C5 6B\n", + "00 03 04 20 00 20 45 39\n", + "00 10 04 20 00 20 40 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 31 30 33 32 35 34 37 36 39 38 3B 3A 3D 3C 3F 3E 41 40 43 42 45 44 47 46 49 48 4B 4A 4D 4C 4F 4E BD 9E\n", + "00 03 04 40 00 20 45 27\n", + "00 10 04 40 00 20 40 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 31 30 33 32 35 34 37 36 39 38 3B 3A 3D 3C 3F 3E 41 40 43 42 45 44 47 46 49 48 4B 4A 4D 4C 4F 4E 3B 36\n", + "00 03 04 60 00 02 C4 F4\n", + "00 10 04 60 00 02 04 11 10 13 12 4A 7F\n", + "00 03 04 62 00 05 24 F6\n", + "00 10 04 62 00 05 0A 11 10 13 12 15 14 17 16 19 18 04 6D\n", + "00 03 04 67 00 04 F5 37\n", + "00 10 04 67 00 04 08 11 10 13 12 15 14 17 16 AD 22\n", + "00 03 04 6B 00 03 74 F6\n", + "00 10 04 6B 00 03 06 11 10 13 12 15 14 EB F6\n", + "00 03 04 6E 00 01 E5 36\n", + "00 10 04 6E 00 01 02 11 10 EB 12\n", + "00 03 04 6F 00 01 B4 F6\n", + "00 10 04 6F 00 01 02 11 10 EA C3\n", + "00 03 04 70 00 02 C5 31\n", + "00 10 04 70 00 02 04 11 10 13 12 4B 73\n", + "00 03 04 72 00 10 E4 FC\n", + "00 10 04 72 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 4B 18\n", + "00 03 04 82 00 0C E5 06\n", + "00 10 04 82 00 0C 18 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 C2 58\n", + "00 03 04 8E 00 0C 25 05\n", + "00 10 04 8E 00 0C 18 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 DF 98\n", + "00 03 04 9A 00 05 A5 07\n", + "00 10 04 9A 00 05 0A 11 10 13 12 15 14 17 16 19 18 FD 55\n", + "00 03 04 9F 00 05 B5 06\n", + "00 10 04 9F 00 05 0A 11 10 13 12 15 14 17 16 19 18 F8 50\n", + "00 03 04 A4 00 05 C4 CB\n", + "00 10 04 A4 00 05 0A 11 10 13 12 15 14 17 16 19 18 C2 AB\n", + "00 03 04 A9 00 02 14 CA\n", + "00 10 04 A9 00 02 04 11 10 13 12 86 45\n", + "00 03 04 AB 00 01 F5 0B\n", + "00 10 04 AB 00 01 02 11 10 FA 47\n", + "00 03 04 AC 00 09 45 0C\n", + "00 10 04 AC 00 09 12 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 7F E1\n", + "00 03 04 B5 00 AF 14 B1\n" + ] + }, + { + "ename": "ValueError", + "evalue": "byte must be in range(0, 256)", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[1], line 25\u001b[0m, in \u001b[0;36m__VSCODE_wrap_run_cell..wrapper\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 24\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[1;32m---> 25\u001b[0m store_history \u001b[39m=\u001b[39m args[\u001b[39m2\u001b[39m] \u001b[39mif\u001b[39;00m \u001b[39mlen\u001b[39;49m(args) \u001b[39m>\u001b[39m \u001b[39m2\u001b[39m \u001b[39melse\u001b[39;00m kwargs[\u001b[39m\"\u001b[39m\u001b[39mstore_history\u001b[39m\u001b[39m\"\u001b[39m]\n\u001b[0;32m 26\u001b[0m \u001b[39mif\u001b[39;00m store_history:\n", + "\u001b[1;31mTypeError\u001b[0m: 'int' object is not callable", + "\nDuring handling of the above exception, another exception occurred:\n", + "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[7], line 16\u001b[0m\n\u001b[0;32m 14\u001b[0m \u001b[39mcontinue\u001b[39;00m\n\u001b[0;32m 15\u001b[0m my_block[\u001b[39m'\u001b[39m\u001b[39mdata_val\u001b[39m\u001b[39m'\u001b[39m] \u001b[39m=\u001b[39m \u001b[39mlist\u001b[39m(\u001b[39mrange\u001b[39m(\u001b[39m0x10\u001b[39m, \u001b[39m0x10\u001b[39m \u001b[39m+\u001b[39m \u001b[39m2\u001b[39m \u001b[39m*\u001b[39m \u001b[39mlen\u001b[39m))\n\u001b[1;32m---> 16\u001b[0m frame_write \u001b[39m=\u001b[39m device\u001b[39m.\u001b[39;49mfunction\u001b[39m.\u001b[39;49mprotocols\u001b[39m.\u001b[39;49mmake_frame_modbus(my_block)\n\u001b[0;32m 17\u001b[0m \u001b[39mprint\u001b[39m(device\u001b[39m.\u001b[39mtools\u001b[39m.\u001b[39mByteConv\u001b[39m.\u001b[39mtrans_list_to_str(frame_write))\n", + "File \u001b[1;32md:\\WorkSpace\\UserTool\\SelfTool\\FrameParser\\source\\device\\function\\protocols.py:169\u001b[0m, in \u001b[0;36mmake_frame_modbus\u001b[1;34m(block)\u001b[0m\n\u001b[0;32m 166\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[0;32m 167\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mException\u001b[39;00m(\u001b[39m\"\u001b[39m\u001b[39mModbus Frame Type Error.\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[1;32m--> 169\u001b[0m crc \u001b[39m=\u001b[39m calculator\u001b[39m.\u001b[39mchecksum(\u001b[39mbytearray\u001b[39;49m(frame))\n\u001b[0;32m 170\u001b[0m frame\u001b[39m.\u001b[39mappend(crc \u001b[39m%\u001b[39m \u001b[39m256\u001b[39m)\n\u001b[0;32m 171\u001b[0m frame\u001b[39m.\u001b[39mappend(crc \u001b[39m/\u001b[39m\u001b[39m/\u001b[39m \u001b[39m256\u001b[39m)\n", + "\u001b[1;31mValueError\u001b[0m: byte must be in range(0, 256)" + ] + } + ], + "source": [ + "my_block = {\n", + " 'addr_dev' : 0x00,\n", + " 'data_define': {},\n", + "}\n", + "\n", + "for addr, len in list_param:\n", + " my_block['type'] = 'read'\n", + " my_block['data_addr'] = addr\n", + " my_block['data_len'] = len\n", + " frame_read = device.function.protocols.make_frame_modbus(my_block)\n", + " print(device.tools.ByteConv.trans_list_to_str(frame_read))\n", + " my_block['type'] = 'write_str'\n", + " if len >= 0x100:\n", + " continue\n", + " my_block['data_val'] = list(range(0x10, 0x10 + 2 * len))\n", + " frame_write = device.function.protocols.make_frame_modbus(my_block)\n", + " print(device.tools.ByteConv.trans_list_to_str(frame_write))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "00 03 04 00 00 10 44 E7\n", + "00 10 04 00 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E C7 37\n", + "00 03 04 10 00 10 45 22\n", + "00 10 04 10 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E C5 6B\n", + "00 03 04 20 00 20 45 39\n", + "00 10 04 20 00 20 40 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 31 30 33 32 35 34 37 36 39 38 3B 3A 3D 3C 3F 3E 41 40 43 42 45 44 47 46 49 48 4B 4A 4D 4C 4F 4E BD 9E\n", + "00 03 04 40 00 20 45 27\n", + "00 10 04 40 00 20 40 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 31 30 33 32 35 34 37 36 39 38 3B 3A 3D 3C 3F 3E 41 40 43 42 45 44 47 46 49 48 4B 4A 4D 4C 4F 4E 3B 36\n", + "00 03 04 60 00 02 C4 F4\n", + "00 10 04 60 00 02 04 11 10 13 12 4A 7F\n", + "00 03 04 62 00 05 24 F6\n", + "00 10 04 62 00 05 0A 11 10 13 12 15 14 17 16 19 18 04 6D\n", + "00 03 04 67 00 04 F5 37\n", + "00 10 04 67 00 04 08 11 10 13 12 15 14 17 16 AD 22\n", + "00 03 04 6B 00 03 74 F6\n", + "00 10 04 6B 00 03 06 11 10 13 12 15 14 EB F6\n", + "00 03 04 6E 00 01 E5 36\n", + "00 10 04 6E 00 01 02 11 10 EB 12\n", + "00 03 04 6F 00 01 B4 F6\n", + "00 10 04 6F 00 01 02 11 10 EA C3\n", + "00 03 04 70 00 02 C5 31\n", + "00 10 04 70 00 02 04 11 10 13 12 4B 73\n", + "00 03 04 72 00 10 E4 FC\n", + "00 10 04 72 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 4B 18\n", + "00 03 04 82 00 0C E5 06\n", + "00 10 04 82 00 0C 18 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 C2 58\n", + "00 03 04 8E 00 0C 25 05\n", + "00 10 04 8E 00 0C 18 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 DF 98\n", + "00 03 04 9A 00 05 A5 07\n", + "00 10 04 9A 00 05 0A 11 10 13 12 15 14 17 16 19 18 FD 55\n", + "00 03 04 9F 00 05 B5 06\n", + "00 10 04 9F 00 05 0A 11 10 13 12 15 14 17 16 19 18 F8 50\n", + "00 03 04 A4 00 05 C4 CB\n", + "00 10 04 A4 00 05 0A 11 10 13 12 15 14 17 16 19 18 C2 AB\n", + "00 03 04 A9 00 02 14 CA\n", + "00 10 04 A9 00 02 04 11 10 13 12 86 45\n", + "00 03 04 AB 00 01 F5 0B\n", + "00 10 04 AB 00 01 02 11 10 FA 47\n", + "00 03 04 AC 00 09 45 0C\n", + "00 10 04 AC 00 09 12 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 7F E1\n", + "00 03 04 B5 00 AF 14 B1\n", + "00 03 05 64 00 10 04 C4\n", + "00 10 05 64 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E D5 98\n", + "00 03 05 74 00 02 85 0C\n", + "00 10 05 74 00 02 04 11 10 13 12 47 10\n", + "00 03 05 76 00 02 24 CC\n", + "00 10 05 76 00 02 04 11 10 13 12 C6 C9\n", + "00 03 05 78 00 10 C5 02\n", + "00 10 05 78 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E D7 5D\n" + ] + } + ], + "source": [ + "my_block = {\n", + " 'addr_dev' : 0x00,\n", + " 'data_define': {},\n", + "}\n", + "\n", + "for addr, len in list_param:\n", + " my_block['type'] = 'read'\n", + " my_block['data_addr'] = addr\n", + " my_block['data_len'] = len\n", + " frame_read = device.function.protocols.make_frame_modbus(my_block)\n", + " print(device.tools.ByteConv.trans_list_to_str(frame_read))\n", + " my_block['type'] = 'write_str'\n", + " if len >= 0x80:\n", + " continue\n", + " my_block['data_val'] = list(range(0x10, 0x10 + 2 * len))\n", + " frame_write = device.function.protocols.make_frame_modbus(my_block)\n", + " print(device.tools.ByteConv.trans_list_to_str(frame_write))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import serial" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "com = serial.Serial('COM8', 115200, 8,'E', 1, 1)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "00 03 04 00 00 10 44 E7\n", + "00 10 04 00 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E C7 37\n", + "00 03 04 10 00 10 45 22\n", + "00 10 04 10 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E C5 6B\n", + "00 03 04 20 00 20 45 39\n", + "00 10 04 20 00 20 40 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 31 30 33 32 35 34 37 36 39 38 3B 3A 3D 3C 3F 3E 41 40 43 42 45 44 47 46 49 48 4B 4A 4D 4C 4F 4E BD 9E\n", + "00 03 04 40 00 20 45 27\n", + "00 10 04 40 00 20 40 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 31 30 33 32 35 34 37 36 39 38 3B 3A 3D 3C 3F 3E 41 40 43 42 45 44 47 46 49 48 4B 4A 4D 4C 4F 4E 3B 36\n", + "00 03 04 60 00 02 C4 F4\n", + "00 10 04 60 00 02 04 11 10 13 12 4A 7F\n", + "00 03 04 62 00 05 24 F6\n", + "00 10 04 62 00 05 0A 11 10 13 12 15 14 17 16 19 18 04 6D\n", + "00 03 04 67 00 04 F5 37\n", + "00 10 04 67 00 04 08 11 10 13 12 15 14 17 16 AD 22\n", + "00 03 04 6B 00 03 74 F6\n", + "00 10 04 6B 00 03 06 11 10 13 12 15 14 EB F6\n", + "00 03 04 6E 00 01 E5 36\n", + "00 10 04 6E 00 01 02 11 10 EB 12\n", + "00 03 04 6F 00 01 B4 F6\n", + "00 10 04 6F 00 01 02 11 10 EA C3\n", + "00 03 04 70 00 02 C5 31\n", + "00 10 04 70 00 02 04 11 10 13 12 4B 73\n", + "00 03 04 72 00 10 E4 FC\n", + "00 10 04 72 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 4B 18\n", + "00 03 04 82 00 0C E5 06\n", + "00 10 04 82 00 0C 18 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 C2 58\n", + "00 03 04 8E 00 0C 25 05\n", + "00 10 04 8E 00 0C 18 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 DF 98\n", + "00 03 04 9A 00 05 A5 07\n", + "00 10 04 9A 00 05 0A 11 10 13 12 15 14 17 16 19 18 FD 55\n", + "00 03 04 9F 00 05 B5 06\n", + "00 10 04 9F 00 05 0A 11 10 13 12 15 14 17 16 19 18 F8 50\n", + "00 03 04 A4 00 05 C4 CB\n", + "00 10 04 A4 00 05 0A 11 10 13 12 15 14 17 16 19 18 C2 AB\n", + "00 03 04 A9 00 02 14 CA\n", + "00 10 04 A9 00 02 04 11 10 13 12 86 45\n", + "00 03 04 AB 00 01 F5 0B\n", + "00 10 04 AB 00 01 02 11 10 FA 47\n", + "00 03 04 AC 00 09 45 0C\n", + "00 10 04 AC 00 09 12 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 7F E1\n", + "00 03 04 B5 00 AF 14 B1\n", + "00 03 05 64 00 10 04 C4\n", + "00 10 05 64 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E D5 98\n", + "00 03 05 74 00 02 85 0C\n", + "00 10 05 74 00 02 04 11 10 13 12 47 10\n", + "00 03 05 76 00 02 24 CC\n", + "00 10 05 76 00 02 04 11 10 13 12 C6 C9\n", + "00 03 05 78 00 10 C5 02\n", + "00 10 05 78 00 10 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E D7 5D\n" + ] + } + ], + "source": [ + "my_block = {\n", + " 'addr_dev' : 0x00,\n", + " 'data_define': {},\n", + "}\n", + "\n", + "frames = {}\n", + "for addr, len in list_param:\n", + " my_block['type'] = 'read'\n", + " my_block['data_addr'] = addr\n", + " my_block['data_len'] = len\n", + " frame_read = device.function.protocols.make_frame_modbus(my_block)\n", + " print(device.tools.ByteConv.trans_list_to_str(frame_read))\n", + " my_block['type'] = 'write_str'\n", + " if len >= 0x80:\n", + " continue\n", + " my_block['data_val'] = list(range(0x10, 0x10 + 2 * len))\n", + " frame_write = device.function.protocols.make_frame_modbus(my_block)\n", + " print(device.tools.ByteConv.trans_list_to_str(frame_write))\n", + " frames[addr] = frame_read, frame_write" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "8\n", + "00 03 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 84 5D\n" + ] + } + ], + "source": [ + "import time\n", + "ret = com.write(frames[0x400][0])\n", + "print(ret)\n", + "time.sleep(0.2)\n", + "frame_recv = com.read_all()\n", + "print(device.tools.ByteConv.trans_list_to_str(frame_recv))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "8\n", + "00 03 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 84 5D\n" + ] + }, + { + "ename": "TypeError", + "evalue": "a bytes-like object is required, not 'str'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[1], line 25\u001b[0m, in \u001b[0;36m__VSCODE_wrap_run_cell..wrapper\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 24\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[1;32m---> 25\u001b[0m store_history \u001b[39m=\u001b[39m args[\u001b[39m2\u001b[39m] \u001b[39mif\u001b[39;00m \u001b[39mlen\u001b[39;49m(args) \u001b[39m>\u001b[39m \u001b[39m2\u001b[39m \u001b[39melse\u001b[39;00m kwargs[\u001b[39m\"\u001b[39m\u001b[39mstore_history\u001b[39m\u001b[39m\"\u001b[39m]\n\u001b[0;32m 26\u001b[0m \u001b[39mif\u001b[39;00m store_history:\n", + "\u001b[1;31mTypeError\u001b[0m: 'int' object is not callable", + "\nDuring handling of the above exception, another exception occurred:\n", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[14], line 7\u001b[0m\n\u001b[0;32m 5\u001b[0m frame_recv \u001b[39m=\u001b[39m com\u001b[39m.\u001b[39mread_all()\n\u001b[0;32m 6\u001b[0m \u001b[39mprint\u001b[39m(device\u001b[39m.\u001b[39mtools\u001b[39m.\u001b[39mByteConv\u001b[39m.\u001b[39mtrans_list_to_str(frame_recv))\n\u001b[1;32m----> 7\u001b[0m \u001b[39mprint\u001b[39m(device\u001b[39m.\u001b[39;49mtools\u001b[39m.\u001b[39;49mByteConv\u001b[39m.\u001b[39;49mtrans_str_to_list(frame_recv)[\u001b[39m3\u001b[39m:\u001b[39m-\u001b[39m\u001b[39m2\u001b[39m])\n", + "File \u001b[1;32md:\\WorkSpace\\UserTool\\SelfTool\\FrameParser\\source\\device\\tools\\ByteConv.py:10\u001b[0m, in \u001b[0;36mtrans_str_to_list\u001b[1;34m(data)\u001b[0m\n\u001b[0;32m 8\u001b[0m \u001b[39m\u001b[39m\u001b[39m\"\"\" 标准串口字符串转换列表 \"\"\"\u001b[39;00m\n\u001b[0;32m 9\u001b[0m func_trans \u001b[39m=\u001b[39m \u001b[39mlambda\u001b[39;00m x: \u001b[39mint\u001b[39m(x, \u001b[39m16\u001b[39m)\n\u001b[1;32m---> 10\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mlist\u001b[39m(\u001b[39mmap\u001b[39m(func_trans, data\u001b[39m.\u001b[39;49mstrip()\u001b[39m.\u001b[39;49msplit(\u001b[39m\"\u001b[39;49m\u001b[39m \u001b[39;49m\u001b[39m\"\u001b[39;49m)))\n", + "\u001b[1;31mTypeError\u001b[0m: a bytes-like object is required, not 'str'" + ] + } + ], + "source": [ + "import time\n", + "ret = com.write(frames[0x400][0])\n", + "print(ret)\n", + "time.sleep(0.2)\n", + "frame_recv = com.read_all()\n", + "print(device.tools.ByteConv.trans_list_to_str(frame_recv))\n", + "print(device.tools.ByteConv.trans_str_to_list(frame_recv)[3:-2])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "8\n", + "00 03 20 11 10 13 12 15 14 17 16 19 18 1B 1A 1D 1C 1F 1E 21 20 23 22 25 24 27 26 29 28 2B 2A 2D 2C 2F 2E 84 5D\n", + "b'\\x11\\x10\\x13\\x12\\x15\\x14\\x17\\x16\\x19\\x18\\x1b\\x1a\\x1d\\x1c\\x1f\\x1e! #\"%$\\'&)(+*-,/.'\n" + ] + } + ], + "source": [ + "import time\n", + "ret = com.write(frames[0x400][0])\n", + "print(ret)\n", + "time.sleep(0.2)\n", + "frame_recv = com.read_all()\n", + "print(device.tools.ByteConv.trans_list_to_str(frame_recv))\n", + "print(frame_recv[3:-2])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47]\n", + "True\n" + ] + } + ], + "source": [ + "data_recv = []\n", + "for i in range(3, (len(frame_recv) - 2), 2):\n", + " data_recv.append(frame_recv[i+1])\n", + " data_recv.append(frame_recv[i])\n", + "print(data_recv)\n", + "print(list(range(0x10, 0x10 + 2 * 16)) == data_recv)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Read 0x400: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "Write 0x400, Result: \n", + "\t00 10 04 00 00 10 C1 24\n", + "Read 0x400: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "Read 0x410: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "Write 0x410, Result: \n", + "\t00 10 04 10 00 10 C0 E1\n", + "Read 0x410: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "Read 0x420: \n", + "\t31 32 33 34 35 36 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\n", + "Write 0x420, Result: \n", + "\t00 10 04 20 00 20 C0 FA\n", + "Read 0x420: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F\n", + "Read 0x440: \n", + "\t30 31 30 30 30 30 30 30 30 36 30 30 34 33 41 38 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\n", + "Write 0x440, Result: \n", + "\t00 10 04 40 00 20 C0 E4\n", + "Read 0x440: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F\n", + "Read 0x460: \n", + "\tFF FF FF FF\n", + "Write 0x460, Result: \n", + "\t00 10 04 60 00 02 41 37\n", + "Read 0x460: \n", + "\t10 11 12 13\n", + "Read 0x462: \n", + "\t00 00 00 00 00 00 00 00 00 00\n", + "Write 0x462, Result: \n", + "\t00 10 04 62 00 05 A1 35\n", + "Read 0x462: \n", + "\t10 11 12 13 14 15 16 17 18 19\n", + "Read 0x467: \n", + "\t00 00 00 00 00 00 00 00\n", + "Write 0x467, Result: \n", + "\t00 10 04 67 00 04 70 F4\n", + "Read 0x467: \n", + "\t10 11 12 13 14 15 16 17\n", + "Read 0x46b: \n", + "\t00 00 00 00 00 00\n", + "Write 0x46b, Result: \n", + "\t00 10 04 6B 00 03 F1 35\n", + "Read 0x46b: \n", + "\t10 11 12 13 14 15\n", + "Read 0x46e: \n", + "\t00 00\n", + "Write 0x46e, Result: \n", + "\t00 10 04 6E 00 01 60 F5\n", + "Read 0x46e: \n", + "\t10 11\n", + "Read 0x46f: \n", + "\t00 00\n", + "Write 0x46f, Result: \n", + "\t00 10 04 6F 00 01 31 35\n", + "Read 0x46f: \n", + "\t10 11\n", + "Read 0x470: \n", + "\t00 00 00 00\n", + "Write 0x470, Result: \n", + "\t00 10 04 70 00 02 40 F2\n", + "Read 0x470: \n", + "\t10 11 12 13\n", + "Read 0x472: \n", + "\t78 78 78 78 50 5F 6F 72 6F 74 6F 63 43 6C 76 6F 72 65 65 74 00 72 00 00 00 00 00 00 00 00 00 00\n", + "Write 0x472, Result: \n", + "\t00 10 04 72 00 10 61 3F\n", + "Read 0x472: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "Read 0x482: \n", + "\t72 50 74 6F 63 6F 6C 6F 6F 43 65 76 74 72 72 65 00 00 00 00 00 00 00 00\n", + "Write 0x482, Result: \n", + "\t00 10 04 82 00 0C 60 C5\n", + "Read 0x482: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27\n", + "Read 0x48e: \n", + "\t00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\n", + "Write 0x48e, Result: \n", + "\t00 10 04 8E 00 0C A0 C6\n", + "Read 0x48e: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27\n", + "Read 0x49a: \n", + "\t00 00 00 00 00 00 00 00 00 00\n", + "Write 0x49a, Result: \n", + "\t00 10 04 9A 00 05 20 C4\n", + "Read 0x49a: \n", + "\t10 11 12 13 14 15 16 17 18 19\n", + "Read 0x49f: \n", + "\t56 53 31 30 30 2E 00 31 00 00\n", + "Write 0x49f, Result: \n", + "\t00 10 04 9F 00 05 30 C5\n", + "Read 0x49f: \n", + "\t10 11 12 13 14 15 16 17 18 19\n", + "Read 0x4a4: \n", + "\t56 48 31 30 30 2E 00 31 00 00\n", + "Write 0x4a4, Result: \n", + "\t00 10 04 A4 00 05 41 08\n", + "Read 0x4a4: \n", + "\t10 11 12 13 14 15 16 17 18 19\n", + "Read 0x4a9: \n", + "\t00 00 00 00\n", + "Write 0x4a9, Result: \n", + "\t00 90 EB 5D 8F\n", + "Read 0x4a9: \n", + "\t00 00 00 00\n", + "Read 0x4ab: \n", + "\t00 00\n", + "Write 0x4ab, Result: \n", + "\t00 90 EB 5D 8F\n", + "Read 0x4ab: \n", + "\t00 00\n", + "Read 0x4ac: \n", + "\t03 02 00 05 93 04 12 E0 F6 09 09 12 00 60 00 00 00 00\n", + "Write 0x4ac, Result: \n", + "\t00 10 04 AC 00 09 C0 CF\n", + "Read 0x4ac: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 00 21\n" + ] + }, + { + "ename": "KeyError", + "evalue": "1205", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[35], line 20\u001b[0m\n\u001b[0;32m 18\u001b[0m \u001b[39mfor\u001b[39;00m daddr, dlen \u001b[39min\u001b[39;00m list_param:\n\u001b[0;32m 19\u001b[0m time\u001b[39m.\u001b[39msleep(\u001b[39m0.2\u001b[39m)\n\u001b[1;32m---> 20\u001b[0m read_data(daddr)\n\u001b[0;32m 21\u001b[0m time\u001b[39m.\u001b[39msleep(\u001b[39m0.2\u001b[39m)\n\u001b[0;32m 22\u001b[0m write_data(daddr)\n", + "Cell \u001b[1;32mIn[35], line 3\u001b[0m, in \u001b[0;36mread_data\u001b[1;34m(addr)\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mread_data\u001b[39m(addr):\n\u001b[0;32m 2\u001b[0m \u001b[39m \u001b[39m\u001b[39m\"\"\" 读取数据 \"\"\"\u001b[39;00m\n\u001b[1;32m----> 3\u001b[0m ret \u001b[39m=\u001b[39m com\u001b[39m.\u001b[39mwrite(frames[daddr][\u001b[39m0\u001b[39m])\n\u001b[0;32m 4\u001b[0m time\u001b[39m.\u001b[39msleep(\u001b[39m0.2\u001b[39m)\n\u001b[0;32m 5\u001b[0m frame_recv \u001b[39m=\u001b[39m com\u001b[39m.\u001b[39mread_all()\n", + "\u001b[1;31mKeyError\u001b[0m: 1205" + ] + } + ], + "source": [ + "def read_data(addr):\n", + " \"\"\" 读取数据 \"\"\"\n", + " ret = com.write(frames[daddr][0])\n", + " time.sleep(0.2)\n", + " frame_recv = com.read_all()\n", + " data_recv = []\n", + " for i in range(3, (len(frame_recv) - 2), 2):\n", + " data_recv.append(frame_recv[i+1])\n", + " data_recv.append(frame_recv[i])\n", + " print(f\"Read {hex(daddr)}: \\n\\t{device.tools.ByteConv.trans_list_to_str(data_recv)}\")\n", + "def write_data(addr):\n", + " \"\"\" 写入数据 \"\"\"\n", + " ret = com.write(frames[daddr][1])\n", + " time.sleep(0.2)\n", + " frame_recv = com.read_all()\n", + " print(f\"Write {hex(daddr)}, Result: \\n\\t{device.tools.ByteConv.trans_list_to_str(frame_recv)}\")\n", + "\n", + "for daddr, dlen in list_param:\n", + " time.sleep(0.2)\n", + " read_data(daddr)\n", + " time.sleep(0.2)\n", + " write_data(daddr)\n", + " time.sleep(0.2)\n", + " read_data(daddr)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1205" + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "daddr" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'0x4b5'" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "hex(daddr)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Read 0x400: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "Write 0x400, Result: \n", + "\t00 10 04 00 00 10 C1 24\n", + "Read 0x400: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "Read 0x410: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "Write 0x410, Result: \n", + "\t00 10 04 10 00 10 C0 E1\n", + "Read 0x410: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "Read 0x420: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F\n", + "Write 0x420, Result: \n", + "\t00 10 04 20 00 20 C0 FA\n", + "Read 0x420: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F\n", + "Read 0x440: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F\n", + "Write 0x440, Result: \n", + "\t00 10 04 40 00 20 C0 E4\n", + "Read 0x440: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F\n", + "Read 0x460: \n", + "\t10 11 12 13\n", + "Write 0x460, Result: \n", + "\t00 10 04 60 00 02 41 37\n", + "Read 0x460: \n", + "\t10 11 12 13\n", + "Read 0x462: \n", + "\t10 11 12 13 14 15 16 17 18 19\n", + "Write 0x462, Result: \n", + "\t00 10 04 62 00 05 A1 35\n", + "Read 0x462: \n", + "\t10 11 12 13 14 15 16 17 18 19\n", + "Read 0x467: \n", + "\t10 11 12 13 14 15 16 17\n", + "Write 0x467, Result: \n", + "\t00 10 04 67 00 04 70 F4\n", + "Read 0x467: \n", + "\t10 11 12 13 14 15 16 17\n", + "Read 0x46b: \n", + "\t10 11 12 13 14 15\n", + "Write 0x46b, Result: \n", + "\t00 10 04 6B 00 03 F1 35\n", + "Read 0x46b: \n", + "\t10 11 12 13 14 15\n", + "Read 0x46e: \n", + "\t10 11\n", + "Write 0x46e, Result: \n", + "\t00 10 04 6E 00 01 60 F5\n", + "Read 0x46e: \n", + "\t10 11\n", + "Read 0x46f: \n", + "\t10 11\n", + "Write 0x46f, Result: \n", + "\t00 10 04 6F 00 01 31 35\n", + "Read 0x46f: \n", + "\t10 11\n", + "Read 0x470: \n", + "\t10 11 12 13\n", + "Write 0x470, Result: \n", + "\t00 10 04 70 00 02 40 F2\n", + "Read 0x470: \n", + "\t10 11 12 13\n", + "Read 0x472: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "Write 0x472, Result: \n", + "\t00 10 04 72 00 10 61 3F\n", + "Read 0x472: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "Read 0x482: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27\n", + "Write 0x482, Result: \n", + "\t00 10 04 82 00 0C 60 C5\n", + "Read 0x482: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27\n", + "Read 0x48e: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27\n", + "Write 0x48e, Result: \n", + "\t00 10 04 8E 00 0C A0 C6\n", + "Read 0x48e: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27\n", + "Read 0x49a: \n", + "\t10 11 12 13 14 15 16 17 18 19\n", + "Write 0x49a, Result: \n", + "\t00 10 04 9A 00 05 20 C4\n", + "Read 0x49a: \n", + "\t10 11 12 13 14 15 16 17 18 19\n", + "Read 0x49f: \n", + "\t10 11 12 13 14 15 16 17 18 19\n", + "Write 0x49f, Result: \n", + "\t00 10 04 9F 00 05 30 C5\n", + "Read 0x49f: \n", + "\t10 11 12 13 14 15 16 17 18 19\n", + "Read 0x4a4: \n", + "\t10 11 12 13 14 15 16 17 18 19\n", + "Write 0x4a4, Result: \n", + "\t00 10 04 A4 00 05 41 08\n", + "Read 0x4a4: \n", + "\t10 11 12 13 14 15 16 17 18 19\n", + "Read 0x4a9: \n", + "\t00 00 00 00\n", + "Write 0x4a9, Result: \n", + "\t00 90 EB 5D 8F\n", + "Read 0x4a9: \n", + "\t00 00 00 00\n", + "Read 0x4ab: \n", + "\t00 00\n", + "Write 0x4ab, Result: \n", + "\t00 90 EB 5D 8F\n", + "Read 0x4ab: \n", + "\t00 00\n", + "Read 0x4ac: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 00 21\n", + "Write 0x4ac, Result: \n", + "\t00 10 04 AC 00 09 C0 CF\n", + "Read 0x4ac: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 00 21\n", + "Read 0x564: \n", + "\t00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\n", + "Write 0x564, Result: \n", + "\t00 10 05 64 00 10 81 07\n", + "Read 0x564: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n", + "Read 0x574: \n", + "\t00 00 00 00\n", + "Write 0x574, Result: \n", + "\t00 10 05 74 00 02 00 CF\n", + "Read 0x574: \n", + "\t10 11 12 13\n", + "Read 0x576: \n", + "\t00 00 00 00\n", + "Write 0x576, Result: \n", + "\t00 10 05 76 00 02 A1 0F\n", + "Read 0x576: \n", + "\t10 11 12 13\n", + "Read 0x578: \n", + "\t01 00 02 00 03 00 04 00 05 00 06 00 07 00 08 00 09 00 0A 00 0B 00 0C 00 0D 00 0E 00 0F 00 10 00\n", + "Write 0x578, Result: \n", + "\t00 10 05 78 00 10 40 C1\n", + "Read 0x578: \n", + "\t10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F\n" + ] + } + ], + "source": [ + "def read_data(addr):\n", + " \"\"\" 读取数据 \"\"\"\n", + " ret = com.write(frames[daddr][0])\n", + " time.sleep(0.2)\n", + " frame_recv = com.read_all()\n", + " data_recv = []\n", + " for i in range(3, (len(frame_recv) - 2), 2):\n", + " data_recv.append(frame_recv[i+1])\n", + " data_recv.append(frame_recv[i])\n", + " print(f\"Read {hex(daddr)}: \\n\\t{device.tools.ByteConv.trans_list_to_str(data_recv)}\")\n", + "def write_data(addr):\n", + " \"\"\" 写入数据 \"\"\"\n", + " ret = com.write(frames[daddr][1])\n", + " time.sleep(0.2)\n", + " frame_recv = com.read_all()\n", + " print(f\"Write {hex(daddr)}, Result: \\n\\t{device.tools.ByteConv.trans_list_to_str(frame_recv)}\")\n", + "\n", + "for daddr, dlen in list_param:\n", + " if daddr == 0x4B5:\n", + " continue\n", + " time.sleep(0.2)\n", + " read_data(daddr)\n", + " time.sleep(0.2)\n", + " write_data(daddr)\n", + " time.sleep(0.2)\n", + " read_data(daddr)" + ] + } + ], + "metadata": { + "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 + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/source/dev_station.py b/source/dev_station.py index dca696a..59cfcb1 100644 --- a/source/dev_station.py +++ b/source/dev_station.py @@ -38,6 +38,26 @@ ParamMap_LaminaCombiner = { 0x107: ["输入电流7" , 2, 100], 0x108: ["输入电流8" , 2, 100], + 0x11A: ["适配器01交互滴答", 2, 1], + 0x11B: ["适配器02交互滴答", 2, 1], + 0x11C: ["适配器03交互滴答", 2, 1], + 0x11D: ["适配器04交互滴答", 2, 1], + 0x11E: ["适配器05交互滴答", 2, 1], + 0x11F: ["适配器06交互滴答", 2, 1], + 0x120: ["适配器07交互滴答", 2, 1], + 0x121: ["适配器08交互滴答", 2, 1], + 0x122: ["适配器09交互滴答", 2, 1], + 0x123: ["适配器10交互滴答", 2, 1], + 0x124: ["适配器11交互滴答", 2, 1], + 0x125: ["适配器12交互滴答", 2, 1], + 0x126: ["适配器13交互滴答", 2, 1], + 0x127: ["适配器14交互滴答", 2, 1], + 0x128: ["适配器15交互滴答", 2, 1], + 0x129: ["适配器16交互滴答", 2, 1], + 0x12A: ["路由拓扑从节点个数", 2, 1], + 0x12B: ["路由管理状态机状态", 2, 1], + 0x12C: ["正在升级的适配器序号", 2, 1], + 0x200: ["从板温度" , 2, 10], 0x201: ["输入电流9" , 2, 100], 0x202: ["输入电流10" , 2, 100], @@ -243,8 +263,14 @@ if __name__ == '__main__': "dev20": {'device_id': 'TTE0101DX2409270062', # 内丘中张村北 'frame_print': True, 'time_out': 6, 'retry': 1}, + "dev21": {'device_id': 'TTE0101DX2407080037', # 市区临湖东吴德生 + 'frame_print': True, + 'time_out': 6, 'retry': 1}, + "dev22": {'device_id': 'TTE0101DX2406300067', # (新版限功率升级) + 'frame_print': True, + 'time_out': 6, 'retry': 1}, } - dev_lamina = LaminaStation(**mode_config["dev19"]) + dev_lamina = LaminaStation(**mode_config["dev22"]) dev_lamina.frame_read(0x0000, 0x20) time.sleep(2) diff --git a/source/device/LaminaAdapter.py b/source/device/LaminaAdapter.py index 6bfd836..2adc8c7 100644 --- a/source/device/LaminaAdapter.py +++ b/source/device/LaminaAdapter.py @@ -236,7 +236,7 @@ class LaminaAdapter(DeviceSerial): self.block['data']['step'] = step return self._transfer_data() - def frame_update(self, path_file: Path, makefile: bool = False) -> bool: + def frame_update(self, path_file: Path, makefile: bool = False, savefile: bool = False) -> bool: """ 程序升级 注意: 在使用单板升级测试时, 需要关闭低电压检测功能, 否则无法启动升级流程; @@ -249,6 +249,8 @@ class LaminaAdapter(DeviceSerial): raise Exception("工程编译目标文件不存在.") if makefile and self.make_package is not None: self.block['data']['file'] = self.make_package(path_file) + if savefile: + path_file.parent.joinpath(path_file.stem + '.dat').write_bytes(self.block['data']['file']) else: self.block['data']['file'] = path_file.read_bytes() @@ -341,6 +343,9 @@ def GeneratePackage(type_dev: str, path_hex: Path, **kwargs) -> bytearray: if 'output_bin' in kwargs.keys() and kwargs['output_bin']: (path_hex / (path_hex.stem + '.bin')).write_bytes(bin_main) + if 'output_dat' in kwargs.keys() and kwargs['output_dat']: + (path_hex / (path_hex.stem + '.dat')).write_bytes(bytearray(Image)) + return bytearray(Image) def GenerateImage(type_dev: str, path_boot: Path, path_main: Path, path_back: Path, **kwargs) ->bytearray: diff --git a/source/device/function/protocols.py b/source/device/function/protocols.py index d6febf7..77f1fdf 100644 --- a/source/device/function/protocols.py +++ b/source/device/function/protocols.py @@ -145,7 +145,7 @@ def make_frame_modbus(block:dict) -> bytearray: elif block['type'] == "write_str": frame.append(0x10) data_len = len(block['data_val']) - item_len = 2 * block['data_define'][data_addr][2] + item_len = 2 * block['data_define'][data_addr][2] if data_addr in block['data_define'].keys() else data_len data_val = block['data_val'] if data_len > item_len: raise Exception("Modbus data len oversize.") diff --git a/source/post_work.py b/source/post_work.py index 60e04ec..4454828 100644 --- a/source/post_work.py +++ b/source/post_work.py @@ -286,4 +286,4 @@ if __name__ == "__main__": # Process1_v2(path_boot2, path_main) # 适配器SLCP102 # Process2() - Process(*mode_config['SLCP101']) + Process(*mode_config['SLCP001'])