RMCLink Component

How to: Use from PHP

PHP users use the RMCLink COM Component interface. Specifics on using this component from PHP are described below, including a complete example script. The example script is also included as a PHP 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 line in your PHP file:

$srv = new COM("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:

$rmc = $srv->CreateEthernetLink(2, "192.168.0.22");

Notice that as described below, PHP 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

PHP 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

To read data from the controller, use the ReadFFile or ReadLFile methods. It is not necessary to use the ReadFFile_Script or ReadLFile_Script methods.

$data = $rmc->ReadFFile(8,8,2);
 

Notice that the ReadBit and ReadBitField methods can be used as well.

Writing Data to the Controller

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

Example

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

PHP (Sample.php)

<?php
// First we need to create the RMCLinkServer COM object.
$srv = new COM("RMCLink.RMCLinkServer");
 
// Use our RMCLinkServer to create the correct type of RMCLink object.
// NOTE: PHP does not support enumerations, so we use the literal value (dtRMC70=2).
$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(8,8,2);
echo("Actual Postion = {$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