使用 Python 进行长期仪器数据采集 - 使用“While"循环和线程进程 [英] Long term instrument data acquisition with Python - Using "While" loops and threaded processes

查看:47
本文介绍了使用 Python 进行长期仪器数据采集 - 使用“While"循环和线程进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将有 4 个硬件数据采集单元通过硬连线以太网 LAN 连接到单个控制 PC.此应用程序的编码将驻留在 PC 上,并且完全基于 Python.每个数据采集单元都具有相同的配置,并且将以相同的方式从 PC 进行轮询.它们连接的测试盒提供了我们寻求进行测试的可变输出.

I will have 4 hardware data acquisition units connected to a single control PC over a hard-wired Ethernet LAN. The coding for this application will reside on the PC and is entirely Python-based. Each data acquisition unit is identically configured and will be polled from the PC in identical fashion. The test boxes they are connected to provide the variable output we seek to do our testing.

这些测试是长期的(8-16 个月或更长时间),数据采集率相对较低(每分钟少于 500 个样本,可能接近 200 个).一般的流程也很简单.我将遍历每个数据采集设备并:

These tests are long-term (8-16 months or better), with relatively low data acquisition rates (less than 500 samples per minute, likely closer to 200). The general process flow is simple, too. I'll loop over each data acquisition device and:

  • 从设备读取数据;
  • 对数据进行一些计算;
  • 如果计算器说明一件事,请打开加热器;
  • 如果他们说什么,什么都不做;
  • 将数据写入磁盘和文件以供后续处理

我会等一段时间,然后再重复一遍这个过程.以下是我的问题:

I'll wait some amount of time, then repeat the process all over again. Here are my questions:

  1. 我计划使用 while TRUE: 循环来开始执行我上面概述的序列,并允许通过异常退出循环,但我欢迎任何关于我应该检查的特定异常 - 甚至,这是最好的方法吗?另一种方法可能是这样的:一旦进入 while 循环,我可以使用 try: - except: - finally: 构造退出循环.
  2. 我上面概述的过程是针对主要的数据采集内容,但考虑到采集周期的长度,我还需要能够做其他事情:检查硬件单元是否运行正常,进行测试根据需要在线和离线等.这些管理"功能与主循环不同,所以我想保持它们不同.我应该在同一个脚本中的不同线程中设置这个活动,还是有更好的方法?
  1. I plan to use a while TRUE: loop to start the execution of the sequence I outlined above, and to allow the loop to be exited via exceptions, but I'd welcome any advice on the specific exceptions I should check for -- or even, is this the best approach to take AT ALL? Another approach might be this: Once inside the while loop, I could use the try: - except: - finally: construct to exit the loop.
  2. The process I've outlined above is for the main data acquisition stuff, but given the length of the collection period, I need to be able to do other things as well: check the hardware units are running OK, take test stands on and offline as required, etc. These 'management' functions ar distinct from the main loop, so I'd like to keep them distinct. Should I set this activity up in separate threads within the same script, or are there better approaches?

提前致谢,伙计们.欢迎所有反馈!

Thanks in advance, folks. All feedback is welcome!

推荐答案

我认为使用客户端-服务器模型对您有好处

I'm thinking that it would be good for you to use client-server model

它会很好地分开,所以一个脚本不会影响另一个 - 状态检查/数据收集

It would be nicely separated, so one script would not affect the other - status check / data collecting

基本上你会做什么来运行主机上的数据收集服务器,它可以有一些用于维护的终端输入(日志记录,优雅退出等),并且数据收集 PC 将像具有 while True 循环的客户端一样(除非被杀死,否则它可以无限运行),并且在每台数据收集 PC 上将是服务器/客户端(取决于观点)进行状态检查,并将数据发送到主 PC,您将决定做什么

Basically what you would do it to run server for data collecting on the main machine, which could have some terminal input for maintenance (logging, gracefull exit etc..) and the data collecting PC would act like clients with while True loop (which can run indefinetly unless killed), and on each of data collecting PC would be server/client (depends on point of view) for status check and that would send data to MAIN pc where you would decide what to do

此外,如果您使用 unix/linux 或什至是 windows,则状态检查只需使用 ssh 到机器并检查状态(手动或通过主机的脚本)...取决于特定需求...

also if you use unix/linux or maybe even windows, for status check just use ssh to the machine and check status (manually or via script from main machine) ... depends on specific needs...

享受

这篇关于使用 Python 进行长期仪器数据采集 - 使用“While"循环和线程进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆