如何导入python';将数据循环到javascript中
我有一个python文件从arduino读取在循环中生成的串行数据如何导入python';将数据循环到javascript中,javascript,python,Javascript,Python,我有一个python文件从arduino读取在循环中生成的串行数据 #!/usr/bin/python import serial ser = serial.Serial('/dev/ttyACM0', 9600) while True: print(ser.readline()) ser.close() 如何通过Javascript导入这些数据 我使用xmlhttprequest在循环中打开python文件,但它正在重新打开python文件,而不是流式传输串行数据。。我可以循环xmlht
#!/usr/bin/python
import serial
ser = serial.Serial('/dev/ttyACM0', 9600)
while True:
print(ser.readline())
ser.close()
如何通过Javascript导入这些数据
我使用xmlhttprequest在循环中打开python文件,但它正在重新打开python文件,而不是流式传输串行数据。。我可以循环xmlhttprequest响应来检索数据吗
是否仍然可以用javascript检索python的数据?然后试试这个
这将用python编写一个文件
f = open("sensor.txt", "a")
while True:
f.write(ser.readline())
ser.close()
f.close()
我猜你在JS中使用了一些HTML,所以试着在JS中阅读它
<body>
<input type="file" name="inputfile"
id="inputfile">
<script>
document.getElementById('inputfile')
.addEventListener('change', function() {
var fr=new FileReader();
fr.onload=function(){
document.getElementById('output')
.textContent=fr.result;
}
fr.readAsText(this.files[0]);
})
</script>
</body>
document.getElementById('inputfile')
.addEventListener('change',function()){
var fr=new FileReader();
fr.onload=函数(){
document.getElementById('output')
.textContent=fr.result;
}
fr.readAsText(this.files[0]);
})
所以您是在用python获取数据,对吗?而你得到的数据你只想用JS读,对吗?@shaswat.dharaya,确切地说。。是的您是想在收到数据后读取还是想在数据流传输时读取?有,但只是为了确保javascript没有丢失任何数据更新(及时显示传感器的更新,或在收到数据后)。更简单:elm.textContent=等待此文件[0]。text()