RMCLink Component

How to: Use from VBScript

Note: As of October 2023, VBScript is a deprecated Windows feature. This means that future versions of Windows may not have VBScript available by default or may not have VBScript available at all. Read more on Microsoft Learn.

VBScript users use the RMCLink COM Component interface. Specifics on using this component from VBScript are described below, including a complete example script. The example script is also included as a VBScript project in the RMCLink example projects.

Creating an RMCLink Object

As is common for all languages, the first step is to create an instance of the RMCLink class. This is a two step process: first create an RMCLinkServer object, and then use that object to create the appropriate type of RMCLink object.

To create the RMCLinkServer object, use the following lines in your VBScript file:

Dim srv
Set srv = CreateObject("RMCLink.RMCLinkServer")

You can now use the newly created srv variable to create the RMCLink object using one of RMCLinkServer's CreateEthernetLink, CreateSerialLink or CreateUSBLink methods. The following line creates a link for communicating with an RMC70 at IP address 192.168.0.22:

Dim rmc
Set rmc = srv.CreateEthernetLink(2, "192.168.0.22")

Notice that as described below, VBScript cannot use enumerations, and therefore, although the CreateEthernetLink,CreateSerialLink and CreateUSBLink methods take a DeviceType parameter, the literal value for the desired enumeration must be used.

Use of Enumerations

VBScript cannot use enumerations. Therefore, although the CreateEthernetLink,CreateSerialLink and CreateUSBLink methods are specified to have the devType parameter be of type DeviceType, you must enter the literal value of the enumeration member you want to use. Similarly, for the IsConnected method's ping parameter, you will have to use the literal values in place of the PingType enumeration members. Each enumeration topic lists the literal values next to the named values (e.g. ptDoNotPing = 0).

Reading Data from the Controller

Because of the requirements that VBScript has on using arrays passed back to it from COM components, you must not use ReadFFile or ReadLFile; use ReadFFile_Script or ReadLFile_Script instead. The first two functions will appear to work, but you will not be able to access the elements in the returned array later in your program.

Notice that the ReadBit and ReadBitField methods can be used as well and have no VBScript issues.

Writing Data to the Controller

The WriteFFile and WriteLFile methods can be used normally. They need to be passed a VBScript array with the same length as the count parameter. Refer to these method's topics for an example.

Notice that in addition to the example below, most method topics include an example in VBScript as well. These can be used if you have particular difficulty making one or another method work in VBScript.

Example

The following code is an example of a VBScript program. This example script is also included as a VBScript project in the RMCLink example projects.

VBScript (Sample.vbs)

Option Explicit
Dim srv, rmc, data
 
' First we need to create the RMCLinkServer COM object.
Set srv = CreateObject("RMCLink.RMCLinkServer")
 
' Use our RMCLinkServer to create the correct type of RMCLink object.
' NOTE: VBScript does not support enumerations, so we use the literal value (dtRMC70=2).
Set rmc = srv.CreateEthernetLink(2, "192.168.0.22")
 
' Establish the connection.
rmc.Connect
 
' Read F8:8 and F8:9 (Axis 0 Actual Position and Velocity)
data = rmc.ReadFFile_Script(8,8,2)
WScript.Echo "Actual Position = " & data(0) & ", Actual Velocity = " & data(1)
 
' Close the connection.
rmc.Disconnect

 

See Also

RMCLink COM Component | How Do I Overview | RMCLink Component


Send comments on this topic.

Copyright (c) 2024 Delta Computer Systems, Inc. dba Delta Motion