Communication Gateway
The Communication Gateway allows seamless integration across all the Cambridge Technology scan controllers. It effectively hides the entire routine housekeeping operations and complex communication processes by logically representing the actual hardware devices in a more manageable software objects.
To initialize the communication gateway, create a unique ScanDeviceManager object.
// Creates Scan Device Manager instance
ScanDeviceManager scanDeviceManager = new ScanDeviceManager();
ScanDeviceManager Class
The ScanDeviceManager class has been implemented to provide the necessary functionality to communicate with the range of Cambridge Technology scan controllers. The ScanDeviceManager class effectively encapsulates different controller types into one simple interface which provides an easy-to-use software interface for the API user.
A single instance of ScanDeviceManager is enough to load and manage controllers, create and manage ScanDocuments for laser marking, and retrieve status information from the controllers.
To start the communication process with a Controller card, create an instance of the ScanDeviceManager class and load the configuration data into it. The Load command will try to open the “Configuration.xml” file which contains the controller types it should look for.
// Load the Configuration.xml file of devices
scanDeviceManager.LoadConfiguration();
The Configuration.xml file that comes with the sample code has been pre-configured to load a virtual controller that is capable of estimating cycle time for a given vector scanning. In production environments, the configuration file may need certain modifications depending on the type of controllers used.
Status Reporting
Status messages are useful in identifying the present state of the operation happening in the controller and knowing whether the last requested operation has been executed successfully. Exceptions or faults are also reported in the same manner.
Status reporting can be achieved by selecting the desired status categories and then querying the status of the device.
Select the desired status categories first, using the EnabledStatusCategories command
scanDeviceManager.EnabledStatusCategories |= DeviceStatusCategories.ConnectionStatus
| DeviceStatusCategories.ScanningStatus
| DeviceStatusCategories.LaserPositionStatus
| DeviceStatusCategories.MOTF0Position
| DeviceStatusCategories.MOTF1Position
| DeviceStatusCategories.XY2GalvoStatus
The selected status categories (DeviceStatusCategories) will be monitored now and the status of the selected categories can be queried using the GetDeviceStatusSnaphot command.
string selectedDeviceName = "SMC_DEMO";
DeviceStatusSnapshot stat = scanDeviceManager.GetDeviceStatusSnapshot(selectedDeviceName);
It is possible to add or remove status categories from the ScanDeviceManager object at anytime.
The DeviceStatusChanged event handler can be used to receive status change events from the controller too. Once received, call the GetDeviceStatusSnaphot command to retrieve the status change.
string selectedDeviceName = "SMC_DEMO";
...
scanDeviceManager.EnabledStatusCategories |= DeviceStatusCategories.ConnectionStatus | DeviceStatusCategories.ScanningStatus;
scanDeviceManager.DeviceStatusChanged += new EventHandler<DeviceStatusChangedEventArgs>(scanDeviceManager_DeviceStatusChanged);
private void scanDeviceManager_DeviceStatusChanged(object sender, DeviceStatusChangedEventArgs e)
{
if (this.InvokeRequired)
{
this.BeginInvoke(new EventHandler<DeviceStatusChangedEventArgs>(scanDeviceManager_DeviceStatusChanged), sender, e);
}
else
{
DeviceStatusSnapshot stat = scanDeviceManager.GetDeviceStatusSnapshot(selectedDeviceName);
...
}
}
ScanDeviceManager also supports the following event notifications that could be used to receive important notifications about the status of the connected controller.
DeviceListChanged | Notifies when a new device is present in the device network or when a device goes offline |
DeviceStatusChanged | Notifies when the device status change or in error |
ScanDeviceGatewayFailed | Notifies when the device gateway encounters issues in communicating with devices |
Connecting to a Controller
Use the InitializeHardware function to initialize the ScanDeviceManager and start communication with the controller network. It will take a few milliseconds to initialize the Device Manager and once completed it will search for the controllers that are available on the network.
scanDeviceManager.InitializeHardware();
// Wait until the manager instance is initialized
Thread.Sleep(1000);
// Search for the available controllers
string[] newDeviceList = null;
newDeviceList = scanDeviceManager.GetDeviceList();
Use the connect command to connect to a selected controller card using the unique name of the controller card.
try
{
scanDeviceManager.Connect(selectedDeviceName);
}
catch (DeviceNotFoundException)
{
//Device could not be found
}