@Spoony 我一开始也发现这个问题了,但是没有仔细检查FTP过来的文件名,一致以为文件名一样,刚才看到你的回复,我又仔细看了一下,发现了问题,文件名改了。2020-12-30 01_56_11.084306.txt。哈哈哈哈哈哈哈哈哈
看来在linux下,文件名是可以带“:”的。
@Spoony 我还以为FTP过来的可以,结果一看FTP过来把”:“给替换成”_"了。谢谢。
@Spoony 没有,文件名是“当前时间.txt"--例如:2021-01-15 12:23:54.1234566.txt,文件里是采集到的电压值。
某宝搜可以测电流的A/D转换器(串口、USB、I2C、SPI)。然后通过串口、USB、I2C、SPI等连接树莓派。
@Spoony 贴出了主程序,就是在continuous_scan.py的基础上改的,采集10次,调用进程analyse进行分析,根据情况可以确定是否写硬盘txt文件。
@qoo 用continuous_scan.py进行测试,单通道可以100K,多通道,单通道的速率是100K/通道数。我测试了用a_in_scan_read,6通道每通道10K的速率采集,采集12000个点,连续采集10次,然后调用其他进程分析和写文件没问题。
def main():
"""
This function is executed automatically when the module is run directly.
"""
# ============================================================================================
try:
# Select an MCC 118 HAT device to use.
address = select_hat_device(HatIDs.MCC_118)
hat = mcc118(address)
print('\nSelected MCC 118 HAT device at address', address)
actual_scan_rate = hat.a_in_scan_actual_rate(num_channels, scan_rate)
print('\nMCC 118 continuous scan example')
print(' Functions demonstrated:')
print(' mcc118.a_in_scan_start')
print(' mcc118.a_in_scan_read')
print(' mcc118.a_in_scan_stop')
print(' Channels: ', end='')
print(', '.join([str(chan) for chan in channels]))
print(' Requested scan rate: ', scan_rate)
print(' Actual scan rate: ', actual_scan_rate)
print(' Options: ', enum_mask_to_string(OptionFlags, options))
# ============================================================================================
'''
try:
input('\nPress ENTER to continue ...')
except (NameError, SyntaxError):
pass
'''
# Configure and start the scan.
# Since the continuous option is being used, the samples_per_channel
# parameter is ignored if the value is less than the default internal
# buffer size (10000 * num_channels in this case). If a larger internal
# buffer size is desired, set the value of this parameter accordingly.
print('Starting scan ... Press Ctrl-C to stop\n')
hat.a_in_scan_start(channel_mask, samples_per_channel, scan_rate,options)
# ============================================================================================
try:
while True:
fna = str(datetime.datetime.now()) + ".txt"
for i in range(10):
read_result = hat.a_in_scan_read(read_request_size, timeout) # read channel Data
arrydata[i]=read_result.data
if read_result.hardware_overrun:
print('\n\nHardware overrun\n')
break
elif read_result.buffer_overrun:
print('\n\nBuffer overrun\n')
break
hat.a_in_scan_stop()
hat.a_in_scan_cleanup()
hat.a_in_scan_start(channel_mask, samples_per_channel, scan_rate,options)
arrydatat = arrydata
t2 = threading.Thread(target=analyse, args=(arrydatat, fna, ))
t2.start()
@qoo 我目前测试的是6通道,单通道可以达到16K,6*16k=96k,如果用17k就提示超限了。用a_in_scan_read测试的,你可以通过修改scan rate以及 channel list 来测试。
@Spoony 试了没问题,用a_in_scan_read,多通道也可以达到10k速率。
感觉这个板子还是很好用的,主程序采集,采集一部分后调用其他线程分析告警,对采集没有任何影响。
@Spoony 问题初步解决,用a_in_scan_read,采集然后多线程存储,单通道可以实现10k速率(半个交流电正弦波100个采样点)。回头再试试多通道,是不是每个通道都能到10k。
@Spoony 谢谢
@Spoony 程序如下:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
from time import sleep
from sys import stdout
from daqhats import mcc118, OptionFlags, HatIDs, HatError, AnalogInputMode, AnalogInputRange
from daqhats_utils import select_hat_device, enum_mask_to_string
import os
import threading
import numpy as np
import datetime
import random
import time
#=================================================================
fna = ''
arrya = [[0 for i in range(6)] for h in range(120000)]
#=================================================================
options = OptionFlags.DEFAULT
mcc_118_num_channels = mcc118.info().NUM_AI_CHANNELS
address = select_hat_device(HatIDs.MCC_118)
hat = mcc118(address)
#=================================================================
def writefile(arryatt, fnat):
print("write file ", datetime.datetime.now())
np.savetxt(fnat, arryatt, fmt="%f", delimiter=" ")
print("finish write ", datetime.datetime.now())
noww = datetime.datetime.now()
fileaa = open(fnat, "a")
fileaa.writelines(str(noww) + "\n")
fileaa.close()
#=================================================================
if __name__ == '__main__':
while True:
for k in range(10):
fna = 'DlogT1-' + str(k) + ".txt"
if os.path.exists(fna):
os.remove(fna)
print("当前文件存在,已删除。。。。。。")
else:
print("当前文件不存在。。。。。。")
print("sample start ", now)
for j in range(120000):
arrya[j][0] = hat.a_in_read(0, options)
#arrya[j][1] = hat.a_in_read(1, options)
#arrya[j][2] = hat.a_in_read(2, options)
#arrya[j][3] = hat.a_in_read(3, options)
#arrya[j][4] = hat.a_in_read(4, options)
#arrya[j][5] = hat.a_in_read(5, options)
arryat = arrya
t2 = threading.Thread(target=writefile, args=(arryat, fna, ))
t2.start()
# except KeyboardInterrupt:
# print("当前文件。。。。。。")
@Spoony 我就是接了1路。测试了接6路基本上就是6倍的时间120秒。
咨询一下:
value = hat.a_in_read(chan, options)
这样1路的实际输出,能达到多少的速率。
我写了一个简单的python程序,可以保存,但是感觉采样率没有那么高。
MCC118资料里写的采样率可以达到100K,可是实际用python写了个简单的采样程序,感觉单通道只有6K左右。
程序如下:
参照的single_value_read;
将120000个采样值写到一个二维数组里;
然后调用一个写文件的线程将数组写道txt文件;
120000次采样,用了20秒。
哪个专家能给详细分析一下