ModControl is a proprietary communication protocol that is used by several Cynox devices like Camp-Control and Camp-Control Compact.
This library provides a high level abstraction of the protocol as intended for use by the master. The master always initiates the communication and it addresses a specific client by using the respective client/device address.
- Create an IConnection and connect to device
- Send requests to switch an output and retrieve a counter value
- Handle responses and errors
// Create default device
var device = new ModControlDevice {
Address = 1,
};
using IConnection connection = new TcpConnection("192.168.6.155", 1470);
// Establish connection
try
{
device.Connect(connection);
}
catch (ConnectionException ex)
{
Debug.WriteLine($"Failed to connect. {ex}");
return;
}
var setOutputResponse = device.SetOutput(0, true);
// Check if request was successful
if (setOutputResponse.Error != ResponseError.None)
{
Debug.WriteLine($"Request failed: {setOutputResponse.Error}");
}
var getCounterResponse = device.GetCounter(2);
// Check if request was successful
if (getCounterResponse.Error != ResponseError.None)
{
Debug.WriteLine($"Request failed: {getCounterResponse.Error}");
}
else
{
// Log counter value
Debug.WriteLine($"Current counter value for channel {getCounterResponse.Channel} = {getCounterResponse.Value}");
}
// Disconnect
device.Disconnect();