In this example, the generic “instrument” that you control is Microsoft®Internet Explorer®(IE), which is represented by a COM object. (This example works only on Windows®系统。)通过示例工作,您编写了一个简单的matlab®仪器通用驱动程序允许仪器控制工具箱™软件与COM对象通信。使用图形界面和命令行代码,使用您的驱动程序创建IE浏览器窗口,控制其大小,并指定所显示的网页。在为任何类型的仪器编写通用驱动程序时,可以应用在该示例中所示的原理。
在本节中,您可以创建一个新驱动程序,并指定为此驱动程序创建对象时会发生什么。
从MATLAB命令窗口打开MATLAB仪器驱动程序编辑器。
midedit
To make it known that this driver is a generic driver, in the MATLAB Instrument Driver Editor, select文件>新的>通用驾驶员, as shown.
Select文件>另存为.
导航到要保存驱动程序的目录,并给出您想要的任何名称。此示例使用名称IE_drv
. Remember where you have saved your driver.
选择概括
node in the driver editor window. Set the fields of this pane with any values you want. This example uses the following settings:
制造商 |
|
金宝app支持的模型 |
|
Instrument type |
|
Driver version |
|
选择节点Initialization and Cleanup
.
点击创造tab.
这是在使用此驱动程序创建设备对象时定义要执行的代码的位置。此示例标识Internet Explorer的COM对象,并将句柄分配给该对象Interface
正在创建的设备对象的属性。
Add the following lines of code to the创造标签:
IE = ACTXSERVER('InternetExplorer.Application');obj.interface = IE);
点击连接tab.
This is where you define the code to execute when you connect your device object to your instrument or software.
Add the following lines of code to the连接标签:
IE = get(obj,'interface');IE.visible = 1);IE.FULLSCREEN = 0);
The first line getsIE
作为COM对象的句柄,基于分配创造代码。The two lines after that set the window visibility and size.
MATLAB仪器驱动程序编辑器中的通用驱动程序的写作属性是写入直接代码的问题。
在此示例中,您可以定义两个属性。第一个属性使用与COM对象的相应属性相同的名称;第二属性使用相应的COM对象属性使用不同的名称。
The position of the IE browser window is determined by the最佳
和左
properties of its COM object. In the following steps, you make the最佳
property available to your device object through your generic driver. For this property, the name of the property is the same in both the COM object and in your device object.
选择Properties
驱动程序编辑器树中的节点。
在里面添加属性field, enter the text最佳
, and clickAdd.
Expand theProperties
node in the tree, and select the new node最佳
.
点击财产价值tab. Your property can have a numeric value corresponding to screen pixels. For this example, you can limit the value of the property from0
to200.
.
确保这一点数据类型字段表示双倍的
. In theConstraint字段,单击下拉菜单并选择Bounded
.
Keep the最低限度value of0.0
,并输入一个最大value of200.
.
Your driver editor window should look like the following figure.
Now that you have defined the data type and acceptable values of the property, you can write the code to be executed whenever the device object property is accessed by得到
或者set
.
点击Codetab.
阅读财产的概念相当简单。当你得到的时候最佳
设备对象的属性,驱动程序仅获取对应的COM对象的值最佳
property. So all you need in the Get code function is to identify the COM object to get the information from.
Add the following code at the bottom of the function in theGet code窗格:
IE = obj.interface;propertyvalue = get(即propertyName);
The first line getsIE
as a handle to the COM object. Remember that theInterface
property of the device object is set to this value back in the driver's创造代码。第二行检索COM对象的值最佳
property, and assigns it topropertyValue
, which is returned to the得到
function for the device object.
Add the following code at the bottom of the function in the设置代码窗格:
IE = get(obj,'interface');IE.propertyName = propertyValue;
在里面preceding steps, you created in your driver a device object property that has the same name as the property of the COM object representing your instrument. You can also create properties with names that do not match those of the COM object properties. In the following steps, you create a property calledvsize.
that corresponds to the IE COM object property高度
.
选择Properties
驱动程序编辑器树中的节点。
在里面添加属性field, enter the textvsize.
, and clickAdd.
Expand theProperties
node in the tree, and select the new nodevsize.
.
点击财产价值tab. This property can have a numeric value corresponding to screen pixels, whose range you define as200.
to800
.
确保这一点数据类型字段表示双倍的
. In theConstraint字段,单击下拉菜单并选择Bounded
.
Enter a最低限度value of200.
,并输入一个最大value of800
.
点击Codetab.
Add the following code at the bottom of the function in theGet code窗格:
IE = obj.interface;propertyValue = ie.Height;
Add the following code at the bottom of the function in the设置代码窗格:
IE = get(obj,'interface');set(ie, 'Height', propertyValue);
保存你的司机。
Internet Explorer的常用功能是下载网页。在以下步骤中,您可以创建一个调用的函数去
that allows you to navigate the Web with the browser.
选择Functions
驱动程序编辑器树中的节点。
在里面Add functionfield, enter the text去
, and clickAdd.
Expand theFunctions
node in the tree, and select the new node去
.
MATLAB仪器驱动程序编辑器中的通用驱动程序的函数是编写直接代码的问题。
Your去
function requires only one input argument: the URL of the Web page to navigate to. You can call that argument地点
.
更改MATLAB代码窗格的第一行以阅读
函数goto(obj,网站)
变量obj
is the device object using this driver. The value of地点
是使用此驱动程序时传递到此函数的字符矢量。你的功能然后必须通过价值地点
on to the IE COM object. So your function must get a handle to the COM object, then call the IE COM methodNavigate2
, passing to it the value of地点
.
Add the following code at the bottom of the function in the MATLAB code pane:
IE = obj.interface;调用(即'Navigate2',网站);
Save your driver, and close the MATLAB Instrument Driver Editor.
Now that your generic driver is ready, you can use it with theTest and Measurement Tool或在Matlab命令行。