问题描述
我正在通过串行通信与FPGA进行通信。 每大约1毫秒传输1字节(8位)数据(每1毫秒产生8位脉冲,间隔之间不产生脉冲)
我多次获得相同的数据,如下所示,我确定为什么会这样,您了解我获得相同数据的原因吗?
read.py:
while True:
t1 = time.process_time()
if port.inWaiting() > 0:
c = port.read() # read 1 byte
val = int.from_bytes(c,'big')
print(t1,"sec,",val)
101是来自FPGA的1字节数据
...
2.859375 sec,101
2.859375 sec,101
2.875 sec,101
2.875 sec,101
2.890625 sec,101
2.890625 sec,101
...
最诚挚的问候。
附录:2020/10/23
是的,我测试了它,但是inWaiting()似乎没有清除
读取数据后...(;´・ω・)
while True:
t1 = time.time()
bytesToRead = port.inWaiting()
if bytesToRead > 0:
c = port.read() # read 1 byte
val = int.from_bytes(c,'big')
t2 = time.time()
print("bytesToRead = ",bytesToRead," ",t2-t1,val)
赔率是...
bytesToRead =80 0.0 sec,101
....
bytesToRead =77 0.0 sec,101
bytesToRead =76 0.0009992122650 sec,101
bytesToRead =77 0.0 sec,101
bytesToRead =75 0.0 sec,101
...
解决方法
使用time.time()怎么样?
private String getSubscriberId(Context context,int networkType) {
String deviceUniqueIdentifier = null;
if (ConnectivityManager.TYPE_MOBILE == networkType) {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
return tm.getSubscriberId();
}
return "";
}