是否有可能在Windows XP中开发微秒级时间精度的实时数据采集系统?
对于我的一个项目,我需要开发一个软件,在收到应用程序的触发后,需要在 100 毫秒内从并行端口获取 2000 个数据。这意味着并行端口需要以50微秒的间隔读取。数据频率设置为 10 KHz。因此,该采集过程应该是实时的,具有微秒级的时间精度。 我正在尝试用 Java 编程。到目前为止,我已经能够从并行端口获取数据,但很难维持时间间隔。 我的问题是:在windows xp环境下真的可以做到这样的时间(以微秒为单位)精度吗?如果是,您能给我指出一些指南/资源吗?
任何帮助将不胜感激。
For one of my projects I need to develop a software which needs to acquire 2000 data in 100 millisecond from a parallel port after receiving a trigger from the application. It means the parallel port needs to be read in 50 micro second interval. Data frequency is set to 10 KHz. So, this acquisition process should be in real time with microsecond time precision.
I am trying to program in Java. So far I have been able to acquire data from the parallel port but struggling hard to maintain the time interval.
My question is: Is it really possible to do it under windows xp environment with such time (in microsecond) precision? If yes, can you please point me to some guidelines/resources?
Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这取决于您的软件是否必须可靠地工作或仅在大多数情况下工作。
对于普通的 Java VM,您无法预测垃圾收集器的行为,因此您基本上无法阻止 VM 在任意时间段内中断软件的执行。
有可能使用具有“Java 实时规范”(JSR-1) 扩展的 VM 在 Java 中实现实时软件,但据我所知,Windows 上没有实现,因为 Windows 本身没有实时功能。 Sun 的前一个参考实现(现在由 Oracle 维护)运行在 Solaris 和支持 RT 的 Linux 版本上,并且还有针对嵌入式系统的其他实现。
It depends on if your software has to work reliably or just in most cases.
With a normal Java VM, you cannot predict the garbage collector behaviour, so you basically have no means to prevent the VM from interrupting the execution of your software for any arbitrary period of time.
There are possibilities to implement real time software in Java using a VM with extensions for the "Real-Time Specification for Java" (JSR-1), but AFAIK there are no implementations for Windows, since Windows itself has no real time capabilities. The former reference implementation from Sun (now maintained by Oracle) runs on Solaris and RT enabled Linux versions and there are other implementations for embedded systems.
System.nanoTime() 甚至以纳秒时间精度返回时间,您也可以将其用于微秒。
System.nanoTime() even returns the time in nanosecond time precision, you can use it for microseconds as well.
如果您不打算只在 Windows 上执行此操作,那么添加一些额外的硬件可能会有效。尽管硬件可能像 FPGA 一样复杂,但您也可以使用像 8 位微控制器这样简单的东西来完成它,例如 Arduino 板和 IDE 中使用的 Atmega328。这样,您就可以对输入进行采样、缓冲数据并将并行端口驱动到 PC,同时微控制器充当实时数据源和接近实时的 PC 数据消耗之间的 FIFO。
Atmega328 只有 2K RAM,因此您需要确定这是否足以覆盖 PC 的死区时间。如果没有,也有具有更大 RAM 的类似微控制器。
Arduino UNO 可用于
如果您不熟悉微控制器,那么皮肤下没有任何操作系统会带来不确定性。不存在“隐形”维护的系统问题。编写代码更像是编写内核驱动程序(因为您需要注意实时性、中断处理和维护 CPU 状态的完整性),但周围的系统尽可能简单。
——卡尔
If you are not committed to doing this exclusively with Windows, it might be effective to add some additional hardware. Although the hardware could be as elaborate as an FPGA, you might be able to do it with something as simple as 8-bit microcontroller, such as the Atmega328 used in the Arduino boards and IDE. With that, you could sample the input, buffer the data, and drive the parallel port to the PC, with the microcontroller acting as a FIFO between the real-time data source and the close-to-real-time PC data consumption.
The Atmega328 has only 2K of RAM, so you would need to determine if that is enough to cover the PC's dead times. If not, there are similar microcontrollers with larger RAM.
The Arduino UNO is available for
In case you are unfamiliar with microcontrollers, there is no OS under the skin that introduces uncertainly. There are not system issues being maintained "invisibly". Writing code is more like writing a kernel driver (in that you need be aware of real-time considerations, interrupt processing, and maintaining the integrity of the CPU state), but the surrounding system is as simple as possible.
-- Carl
有适用于 Windows 的第三方实时扩展。这是一个: http://www.directinsight.co.uk/products/venturcom/ rtx.html
他们声称他们提供硬实时。现在,Java 是否适合实时编程是一个很大的难题。有垃圾收集,JIT 编译可能会妨碍...我想说 - 对于时间关键部分(信号收集)坚持使用本机代码,为漂亮的 GUI 构建一个 Java 接口。
C++在概念上与Java有很大不同,但至少语法很接近。
RTX 人员明确将自己定位为定制硬件的替代品,声称商用主板上的英特尔 CPU 可以提供实时处理。但他们的东西不是免费的。如果您想要免费的,请选择嵌入式 Linux。或者使用 QNX。
There are third party realtime extensions for Windows. Here's one: http://www.directinsight.co.uk/products/venturcom/rtx.html
They claim they deliver hard real time. Now, whether Java is appropriate for realtime programming to begin with is a big hard question. There's garbage collection, JIT compilation might get in the way... I'd say - stick to native code for the time critical parts (signal collection), build an interface to Java for the pretty GUI.
C++ is quite different from Java conceptually, but at least the syntax is close.
The RTX guys explicitly position themselves as an alternative to custom hardware, claim Intel CPUs on commodity motherboards can deliver realtime processing. Their stuff is not free though. You want free, go with an embedded flavor of Linux. Or with QNX.