如果我正确理解你想要的是基本的 pythontx.py
并且rx.py
在真实和模拟环境中进行通信。那么答案是肯定的。
对于模拟:
您可以运行2-node-network.groovy
fromsamples
文件夹。
//2-node-network.groovy
import org.arl.fjage.*
///////////////////////////////////////////////////////////////////////////////
// display documentation
println '''
2-node network
--------------
Node A: tcp://localhost:1101, http://localhost:8081/
Node B: tcp://localhost:1102, http://localhost:8082/
'''
///////////////////////////////////////////////////////////////////////////////
// simulator configuration
platform = RealTimePlatform // use real-time mode
// run the simulation forever
simulate {
node 'A', location: [ 0.km, 0.km, -15.m], web: 8081, api: 1101, stack: "$home/etc/setup"
node 'B', location: [ 1.km, 0.km, -15.m], web: 8082, api: 1102, stack: "$home/etc/setup"
}
现在打开 2 个单独ipython3
的终端来测试功能。
我建议rx
先打开侧面,以免错过传输。
C:\Users\jay_p>ipython3
Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 7.19.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from unetpy import UnetSocket
...: from unetpy import *
...:
...: s = UnetSocket('localhost', 1102)
...: modem = s.getGateway()
In [2]: rx = modem.receive(RxFrameNtf, 5000) # this will wait till you receive ntf
...: # print rx data, you will get this once you tx data from other side
...: print('from node', rx.from_, ':', bytearray(rx.data).decode())
Out[2] from node 204 : hello!
一边Tx
:
C:\Users\jay_p>ipython3
Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 7.19.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from unetpy import UnetSocket
...:
...: s = UnetSocket('localhost', 1101)
In [2]: s.send('hello!', 0)
Out[2]: True
In [3]: s.close()
您也可以将其作为tx.py
和运行rx.py
。借自Unet 文档- 第 2.5 节。
# tx.py
from unetpy import UnetSocket
s = UnetSocket('localhost', 1101)
s.send('hello!', 0)
s.close()
# rx.py
from unetpy import UnetSocket
from unetpy import *
s = UnetSocket('localhost', 1102)
modem = s.getGateway()
rx = modem.receive(RxFrameNtf, 5000)
print('from node', rx.from_, ':', bytearray(rx.data).decode())
s.close()
对于真正的调制解调器,您只需要IP address
在脚本中相应地更改它,它也可以在调制解调器上完美运行。