微软BizTalk RFID为RFID应用的推广提供了一个功能强大的平台。提供了基于XML标准和Web Services的开放式接口,它含有RFID器件设备的标准接入协议及管理工具,方便软硬件合作伙伴在本平台上进行开发、应用。作为微软的一个平台级软件,微软RFID开发服务平台不仅和微软的其他产品进行良好的集成,而且能和其他产品进行良好的集成。其作为BizTalk 2006的一个重要组件。希望通过俺的介绍,使大家能对BizTalk 2006 上做相关的RFID应用开发能作初步的了解。
一、DSPI 结构的介绍
图-1:微软中间件产品结构图
DSPI (设备提供程序应用接口)是微软和全球四十家RFID硬件合作伙伴制定的一套标准接口。所有支持DSPI的各种(RFID、条码、IC 卡等)设备在Microsoft Windows 上即插即用。对于软件合作伙伴,微软RFID开发服务平台提供了OM/API's(对象模型/应用程序访问接口),这是为上层的各类软件解决方案服务的。OM/API's可以使用各种Managed Code(比如C#等)来实现。
在具体实现之前,先做平台的配置工作。
下面详细介绍RFID Manager中Provider和Devices的配置过程:
1 配置Provider:
A 打开RFID Manager,选择Device Providers,右击并选择 New Provider;
B 在弹出的对话框,在Name处填写 Provider名称(可随意命名)此处为:Raifu
C 在File Name处,选择 Browse,选择对应的RFID硬件设备商提供的DLL
文件,然后点击 Register,可以看见Provider Properties 的详细信息
D 点击OK,Provider配置完成。
2 配置Devices:
A 选择Devices,右击并选择 New Devices ;
B 选择Add single Device,并点击Next;
C 选择Add Provider:此处选中在配置Provider时设置的名字并点击Next;
D 选择Conect using: 此处选择TCP 协议;
Name or IP address:填写RFID设备的IP地址,此处为:192.168.7.66;
这个IP 根据设备在网络中具体的地址来配置哦
Port:填写RFID设备的端口号,此处为:1969 并点击Next;
端口也和IP配置一样的 呵呵
E 选择组:默认(可以另建新设备组),并点击Next;
F Password:无,并点击Next;
G点击OK,Devices配置完成。
3 至此,RFID Manager配置完成。如图1 所示
(图1)
二、实现的步骤与方法
1、 建立工程
打开VS2005,并新建一个工程,同时填加一些必要的控件,最终的界面效果如图(2) 所示。
注意:只是简单的演示实现方法,具体的开发,可以根据具体应用场合来实现,本人只是介绍其具体的实现方法。
下面是工程的代码 呵呵,,简单,粗燥,您凑活看吧
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Microsoft.SensorServices.Rfid.Management;
using Microsoft.SensorServices.Rfid.Design;
using System.IO.SensorServices.Rfid.Client;
using Microsoft.SensorServices.Rfid;
using Microsoft.SensorServices.Rfid.Utilities;
using Microsoft.SensorServices.Rfid.Dspi;
namespace SynchronousCommand
{
public partial class Form1 : Form
{
DataTable dtTags;
SeekOrigin seek;
public byte[] tagId;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//init devices list
DeviceManagerProxy deviceManager = new DeviceManagerProxy();
try
{
cbDevices.Items.Clear();
DeviceDefinition[] devices = deviceManager.GetAllDevices();
if (devices != null)
{
for (int i = 0; i < devices.Length; i++)
{
cbDevices.Items.Add(devices[i].Name);
}
}
}
catch (Exception ex)
{
ShowException(ex);
}
//init datatable
InitDataTable();
}
void InitDataTable()
{
dtTags = new DataTable();
DataColumn dcTagId = new DataColumn("TagId");
DataColumn dcTagData = new DataColumn("TagData");
DataColumn dcType = new DataColumn("Type");
DataColumn dcSource = new DataColumn("Source");
DataColumn dcTime = new DataColumn("Time");
dtTags.Columns.Add(dcTagId);
dtTags.Columns.Add(dcTagData);
dtTags.Columns.Add(dcType);
dtTags.Columns.Add(dcSource);
dtTags.Columns.Add(dcTime);
}
void ShowException(Exception ex)
{
MessageBox.Show(ex.ToString());
}
private void btnGetTags_Click(object sender, EventArgs e)
{
using (DeviceConnection dc = new DeviceConnection(deviceName))
{
try
{
dc.Open();
TagDataSelector selector = new TagDataSelector();
selector.IsId = true;
selector.IsData = true;
selector.IsTime = true;
selector.IsType = true;
//curent
ICollection<TagReadEvent> c1 = dc.GetTags(selector);
foreach(TagReadEvent tag in c1)
{
DataRow row = dtTags.NewRow();
row["TagId"] = HexUtilities.HexEncode(tag.GetId());
row["TagData"] = HexUtilities.HexEncode(tag.GetData());
row["Source"] = tag.Source;
row["Time"] = tag.Time;
row["Type"] = tag.Type;
dtTags.Rows.Add(row);
}
gridTags.DataSource = dtTags;
}
catch (Exception ex)
{
ShowException(ex);
}
finally
{
dc.Close();
}
}
}
这是读到标签时的界面效果
您在具体的应用中,可以根据自己具体的要求来做地
如:
您可以把采集到的EPC号,存入数据库,作为其他系统的数据源,
或者设计成其他企业软件系统的数据采集子系统等等。
private void btnPrintTag_Click(object sender, EventArgs e)
{
}
private string deviceName
{
get
{
if (cbDevices.SelectedIndex == -1)
return "";
else
return cbDevices.Items[cbDevices.SelectedIndex].ToString();
}
}
private void btnWriteTag_Click(object sender, EventArgs e)
{
using (DeviceConnection dc = new DeviceConnection(deviceName))
{
try
{
dc.Open();
byte[] AccessPassword ={ 0x0, 0x0, 0x0, 0x0 };
byte[] tagId = HexUtilities.HexDecode(txtWriteTagID.Text);
//dc.WriteTagId(tagId, null, null);
dc.WriteTagId(tagId, AccessPassword, null);
}
catch (Exception ex)
{
ShowException(ex);
}
finally
{
dc.Close();
}
}
}
private void btnClearTags_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
using (DeviceConnection dc = new DeviceConnection(deviceName))
{
try
{
dc.Open();
txtPrintTagID.Clear();
int offset= Convert.ToInt32(txtStart.Text);
int length= Convert.ToInt32(txtLength.Text);
// byte[] tagId = HexUtilities.HexDecode(gridTags.Rows[0].Cells[0].Value.ToString());
byte[] data = dc.GetPartialTagData(tagId, seek , offset, length);
txtData.Text = HexUtilities.HexEncode(data);
}
catch (Exception ex)
{
ShowException(ex);
}
finally
{
dc.Close();
}
}
# region getTagData
/* using (DeviceConnection dc = new DeviceConnection(deviceName))
{
try
{
dc.Open();
txtPrintTagID.Clear();
byte[] AccessPassword ={ 0x0, 0x0, 0x0, 0x0 };
byte[] tagId = HexUtilities.HexDecode(gridTags.Rows[0].Cells[0].Value.ToString());
byte[] data = dc.GetTagData(tagId);
txtPrintTagID.Text = HexUtilities.HexEncode(data);
}
catch (Exception ex)
{
ShowException(ex);
}
finally
{
dc.Close();
}
}*/
# endregion getTagData
}
private void button2_Click(object sender, EventArgs e)
{
using (DeviceConnection dc = new DeviceConnection(deviceName))
{
try
{
dc.Open();
txtPrintTagID.Clear();
byte[] AccessPassword ={ 0x0, 0x0, 0x0, 0x0 };
int offset = Convert.ToInt32(WriteStart.Text );
// byte[] tagId = HexUtilities.HexDecode(gridTags.Rows[0].Cells[0].Value.ToString());
byte[] writedata = HexUtilities.HexDecode(WriteData.Text);
dc.WritePartialTagData(tagId, writedata, seek, offset);
}
catch (Exception ex)
{
ShowException(ex);
}
finally
{
dc.Close();
}
}
}
private void button3_Click(object sender, EventArgs e)
{
}
private void gridTags_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
tagId = HexUtilities.HexDecode(this.gridTags.Rows[e.RowIndex].Cells[0].FormattedValue.ToString());
}
private void button4_Click(object sender, EventArgs e)
{
PropertyProfile profile = new PropertyProfile();
//general
PropertyKey nameKey = new PropertyKey(StandardDevicePropertyGroups.General, GeneralPropertyGroup.Name);
PropertyKey location = new PropertyKey(StandardDevicePropertyGroups.General, GeneralPropertyGroup.Location);
PropertyKey discription = new PropertyKey(StandardDevicePropertyGroups.General, GeneralPropertyGroup.Description);
PropertyKey vendor = new PropertyKey(StandardDevicePropertyGroups.General, GeneralPropertyGroup.Vendor);
PropertyKey versionKey = new PropertyKey(StandardDevicePropertyGroups.General, GeneralPropertyGroup.FirmwareVersion);
PropertyKey ntpServer = new PropertyKey(StandardDevicePropertyGroups.General, GeneralPropertyGroup.NtpServer);
PropertyKey time = new PropertyKey(StandardDevicePropertyGroups.General, GeneralPropertyGroup.Time);
//RF
PropertyKey AirProtocolsSupported = new PropertyKey(StandardDevicePropertyGroups.RF, RFPropertyGroup.AirProtocolsSupported);
PropertyKey AirProtocolsInUse = new PropertyKey(StandardDevicePropertyGroups.RF, RFPropertyGroup.AirProtocolsInUse);
PropertyKey AntennaSequence = new PropertyKey(StandardDevicePropertyGroups.RF, RFPropertyGroup.AntennaSequence);
PropertyKey Frequency = new PropertyKey(StandardDevicePropertyGroups.RF, RFPropertyGroup.Frequency);
PropertyKey DutyCycle = new PropertyKey(StandardDevicePropertyGroups.RF, RFPropertyGroup.DutyCycle);
PropertyKey EffectiveRange = new PropertyKey(StandardDevicePropertyGroups.RF, RFPropertyGroup.EffectiveRange);
PropertyKey NoiseLevel = new PropertyKey(StandardDevicePropertyGroups.RF, RFPropertyGroup.NoiseLevel);
PropertyKey NoiseLevelThreshold = new PropertyKey(StandardDevicePropertyGroups.RF, RFPropertyGroup.NoiseLevelThreshold);
PropertyKey OperationEnvironment = new PropertyKey(StandardDevicePropertyGroups.RF, RFPropertyGroup.OperationEnvironment);
PropertyKey PowerLevel = new PropertyKey(StandardDevicePropertyGroups.RF, RFPropertyGroup.PowerLevel);
// PropertyKey RFModeContinuous = new PropertyKey(StandardDevicePropertyGroups.RF, RFPropertyGroup.RFModeContinuous);
PropertyKey SessionId = new PropertyKey(StandardDevicePropertyGroups.RF, RFPropertyGroup.SessionId);
PropertyKey rfModeContKey = new PropertyKey(StandardDevicePropertyGroups.RF, RFPropertyGroup.RFModeContinuous);
// Source
PropertyKey Enabled = new PropertyKey(StandardDevicePropertyGroups.Source, SourcePropertyGroup.Enabled);
PropertyKey systemEnabled = new PropertyKey(StandardDevicePropertyGroups.Source, SourcePropertyGroup.SystemEnabled);
//tagRead
PropertyKey DuplicateEliminationTime = new PropertyKey(StandardDevicePropertyGroups.TagRead, TagReadPropertyGroup.DuplicateEliminationTime);
PropertyKey RssiCutoff = new PropertyKey(StandardDevicePropertyGroups.TagRead, TagReadPropertyGroup.RssiCutoff);
//commands
PropertyKey requestTimeOut = new PropertyKey(StandardDevicePropertyGroups.Command, CommandPropertyGroup.RequestTimeout);
//notification
PropertyKey eventMode = new PropertyKey(StandardDevicePropertyGroups.Notification, NotificationPropertyGroup.EventMode);
PropertyKey NotificationHost = new PropertyKey(StandardDevicePropertyGroups.Notification, NotificationPropertyGroup.NotificationHost);
PropertyKey NotificationPort = new PropertyKey(StandardDevicePropertyGroups.Notification, NotificationPropertyGroup.NotificationPort);
PropertyKey NotificationDataSelector = new PropertyKey(StandardDevicePropertyGroups.Notification, NotificationPropertyGroup.TagDataSelector);
profile[nameKey] = "OK Device";
// general
profile[location] =System.IO.Directory.GetCurrentDirectory().ToString();
profile[discription] = "Jiang su Raifu Teck Co.,LTD";
profile[versionKey] = "23 14";
profile[vendor] = "Raifu Teck";
profile[time] = DateTime.Now.ToString();
profile[ntpServer] = "RaifuServer";
profile[Frequency] = 902.4;//freValue(resultBytes[8]);
profile[AirProtocolsSupported] = new string[] { "ISO18000-6B", "EpcClass1Gen1", "EpcClass1Gen2" };//支持的协议;
profile[EffectiveRange] = (double)3.2;
profile[NoiseLevel] = (float)10.14;
profile[NoiseLevelThreshold] = (float)20;
profile[PowerLevel] = (float)12.34;
profile[AirProtocolsInUse] = new string[] { "ISO18000-6B" };// strTagType(resultBytes[10]);//new string[] { "EpcClass1Gen2" }; // 当前的卡类型;
profile[AntennaSequence] = "AntennaSequence";
//sources
profile[Enabled] = true;
profile[systemEnabled] = true;
// tagReads
profile[DuplicateEliminationTime] = Convert.ToInt64(30000);
profile[RssiCutoff] = (float)1.0;
//commands
profile[requestTimeOut] = 40000;
//notification
profile[eventMode] = true;
profile[NotificationPort] = 0;
using (DeviceConnection dc = new DeviceConnection(deviceName))
{
try
{
dc.Open();
dc.SetProperty(StandardDevicePropertyGroups.Command, CommandPropertyGroup.RequestTimeout, 30);
}
catch (Exception ex)
{
ShowException(ex);
}
finally
{
dc.Close();
}
}
}
}
}
上面只是简单演示了几个效果,感性的认识或了解下RFID技术。
本人C#不是很熟悉,上面的代码也不够规范,但意思到了基本算是呵呵
采用这个技术的好处是什么呢?
可以不关心具体的RFID硬件系统了,无论是那个公司的读写设备。
例如:
您在开发RFID数据采集系统时,选的是A公司的产品,但在后期的实施中,因为某种原因,而选择了B公司的产品,按以前的做法,您是要重新写代码了。。。。。
现在嘛,这一切都不是问题了 呵呵 (前提是A 和B 公司的设备都集成到biztalk里了)
OK,该结束了 呵呵
有问题可以一起学习、交流,xxRFID方面的技术哦
C#嘛,{jd1}是菜鸟,只是仓促的被迫的玩了几天