擅长:python、mysql、java
<p>对于这种简单的测试,您不需要任何特殊的解析器。只需使用Python。一个简单的解决方案可以这样开始:</p>
<pre><code>class TestGen(object):
def __init__(self, filename):
self._filename = filename
def __enter__(self):
self._file = open(self._filename, 'w')
return self
def __exit__(self, *args):
self._file.close()
def make_standard_connection(self):
self._write('ot 11 02 00 0F FD')
self._write('in 12 ackValue')
self._write('in 13 ackValue 09 88')
def send_data(self, *data):
data_str = ' '.join(data)
self._write('ot 21 ackValue 05 %s' % (data_str,))
def _write(self, line):
self._file.write('%s\n' % line)
def script_one():
with TestGen('output1.txt') as g:
g.make_standard_connection()
g.send_data('01', '02', '03', '04', '05')
</code></pre>
<p>运行<code>script_one()</code>将生成包含以下内容的文件:</p>
^{pr2}$