入驻于 2020-12-22 / MAKE 主页
@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 谢谢