cpubbs论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

LabVIEW+单片机学习套件全套教程资料下载[免费]LabVIEW论坛精华列表贴USB0816数据采集卡《LabVIEW宝典》
LabWindows/CVI论坛精华贴NET0816以太网数据采集卡RC0210远程设备授权系统 关闭关停锁定打开设备 户外分布式数据采集
NET1624低速高精度以太网数据采集卡WIFI0824SD无线WIFI网络数据采集卡脱机运行 SD存储 小尺寸微型 串口采集远程采集 安卓 手持移动采集 纪录仪
查看: 1728|回复: 1

Using Variants to Pass Multiple Data Types Through a Single Queue

[复制链接]
发表于 2009-6-16 22:43:52 | 显示全部楼层 |阅读模式
http://decibel.ni.com/content/docs/DOC-4364

Functional Description
Many times when using Queues with a Producer/Consumer type architecture (or another usage), it is necessary to be able to pass multiple data types through a queue.  However, due to the limitations of the Queue in LabVIEW, only a single data type can be passed through any particular queue.  That is, each queue must be explicitly defined.  If you need to pass different types of data depending on the situation, this presents a problem.  One way to solve this would be to use a cluster, and pass all possibly relevant information through on every iteration.  This would work, however it isn't very efficient.  A preferred way of accomplishing this is to use variants.

A variant is like a universal data type.  It is simply a binary representation of data that has no specific display format, such as numeric, Boolean, string, etc.  You can convert any data type to a variant and then back from a variant and retrieve the original information.  This is exactly what we will do here.  In this example, we have one queue that is capable of passing Doubles, Strings, and Booleans.  To do this, I have made a cluster that contains an enumerated control that specifies what the data type is, and then a variant which contains the actual data.  This way, when the consumer loop is trying to read the data, it knows how to "decode" it.  In order to make the use of queues easier to understand, I have implemented an event-based producer consumer structure.  For more information on event-based producer consumer architectures, please refer to the example finder in LabVIEW.
发表于 2009-6-16 23:58:29 | 显示全部楼层
谢谢版主分享!另外我也查了些关于variant的说明,如果要传输的数据可能会有多种状态,或者要调用类似ActiveX和vi属性,那么variant是很好的选择。如果是大数据传输,而传输的数据类型又比较单一的话不建议使用。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|cpubbs论坛. ( 粤ICP备09171248号 )

GMT+8, 2024-5-20 08:24 , Processed in 0.420804 second(s), 7 queries , Gzip On, File On.

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表