在写代码过程中,我们修改代码中寄存器的值,但是有时寄存器的数据较多,手动修改容易出现错误而且花费的时间长
这是一段寄存器的配置值:
0x00, 0x34
0x35, 0x25
0x10, 0xd4
0xf5, 0xa5
0x00, 0x34
0x3a, 0xff
0x00, 0x00
0x34, 0x25
这是要修改代码的值:
{Data, 0x21, 0x23},
{Data, 0x34, 0x23},
{Data, 0xd1, 0x2a},
{Data, 0xe1, 0xc3},
{Data, 0x00, 0xff},
{Data, 0xef, 0x23},
{Data, 0xac, 0x00},
{Data, 0x25, 0x87},
首先将要修改的代码值存在test1.txt中,寄存器的配置值存在test2.txt中
```python # Python实现的过程 # 引入必要的包 import numpy as np import pandas as pd #导入代码 data = pd.read_csv("G:/Test/test1.txt", header=None) # data # 0 1 2 3 # 0 {Data 0x21 0x23} NaN # 1 {Data 0x34 0x23} NaN # 2 {Data 0xd1 0x2a} NaN # 3 {Data 0xe1 0xc3} NaN # 4 {Data 0x00 0xff} NaN # 5 {Data 0xef 0x23} NaN # 6 {Data 0xac 0x00} NaN # 7 {Data 0x25 0x87} NaN #导入寄存器配置值 reg = pd.read_csv("G:/Test/test2.txt", header = None) # reg # 0 1 # 0 0x00 0x34 # 1 0x35 0x25 # 2 0x10 0xd4 # 3 0xf5 0xa5 # 4 0x00 0x34 # 5 0x3a 0xff # 6 0x00 0x00 # 7 0x34 0x25 # 修改代码第二列值 data[1] = reg[0] # 因为代码里面第三列除了数值还有“}” data[2] = reg[1] + "}" # 修改之后的代码数据 # data # 0 1 2 3 # 0 {Data 0x00 0x34} NaN # 1 {Data 0x35 0x25} NaN # 2 {Data 0x10 0xd4} NaN # 3 {Data 0xf5 0xa5} NaN # 4 {Data 0x00 0x34} NaN # 5 {Data 0x3a 0xff} NaN # 6 {Data 0x00 0x00} NaN # 7 {Data 0x34 0x25} NaN # 把修改之后的代码保存成txt文件 data.to_csv("G:/Test/result.txt",header = None, index = None)
原文地址:https://www.cnblogs.com/vijing/p/10409829.html
时间: 2024-10-06 11:11:55