Connect
In the following it is assumed that the project itself is set up correctly - so all required references are added etc.
Driver manager
The DriverManager
object is a central piece in the SDK as its the object that loads a specific sensor driver - like the driver for the Trimble SSeries.
While the interface itself is unified the SDK needs to know what type of instrument is connected.
The snipped below shows a way to init the DriverManager and a couple of important things:
- The
IsvDetails.Developer
parameter is used to run the SDK in development mode. - The
Trimble.Ssi.Driver.CarpoBased.Driver.SSeries.Windows.dll
gets loaded - A
driver
instance is created from the loaded driver - The
_sensor
is one instance of the currently loadeddriver
(could be more) - Set the static
DriverLogFilePath
property to some folder that gets created if not existing
IDriverManager driverManager = new DriverManager(IsvDetails.Developer);
try
{
var driverDir = Directory.GetCurrentDirectory() + @".\..\..\..\lib\ssi\" + @"Trimble.Ssi.Driver.CarpoBased.Driver.SSeries.Windows.dll";
Assembly driverAssembly = Assembly.LoadFrom(driverDir);
driverManager.RegisterDriverAssembly(driverAssembly);
IList<IDriverInformation> drivers = driverManager.ListAvailableDrivers();
IDriverInformation driverInformation = drivers.FirstOrDefault();
var driver = driverManager.CreateDriver(driverInformation);
_sensor = driver.CreateSensor();
var logPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "TPSDK_log");
_ = !Directory.Exists(logPath) ? Directory.CreateDirectory(logPath) : null;
DriverManager.DriverLogFilePath = logPath;
}
catch (Exception e)
{
throw;
}
Connecting to a sensor instance
At this stage we have a valid sensor instance which we can query for features.
For example a sensor knows all its supported connection types and methods. In case of a Trimble SSeries this is:
- USB
- Serial
- Bluetooth
- Radio
So making a call
var supportedConnectionTypes = _sensor.ListSupportedConnectionTypes();
will return an IEnumerable<ConnectionType>
with the corresponding information.
USB
For simplicity we will use USB to connect
if (_sensor.IsSupported(ConnectionType.Usb))
{
var connectionSettingsContainer = new ConnectionSettings(ConnectionType.Usb);
try
{
await Task.Run(() => _sensor.Connect(connectionSettingsContainer));
Initialize();
return true;
}
catch (Exception e)
{
exceptionCallback(e);
}
}
Bluetooth
A Bluetooth connection is a little more complicated as it requires the BT address as parameter.
An async
function that will perform a Bluetooth connection may look like this:
public async Task<bool> ConnectViaBluetooth(Action<Exception> exceptionCallback, String bluetoothAddress)
{
if (_sensor.IsSupported(ConnectionType.BluetoothSocket))
{
var connectionParameter = _sensor.CreateConnectionParameter(ConnectionParameterType.BluetoothSocketSettings) as IConnectionParameterBluetoothSocketSettings;
connectionParameter.BluetoothParameter = connectionParameter.CreateBluetoothParameter(bluetoothAddress);
var parameters = new List<IConnectionParameter> { connectionParameter };
var connectionSettingsContainer = new ConnectionSettings(ConnectionType.BluetoothSocket, parameters);
try
{
await Task.Run(() => _sensor.Connect(connectionSettingsContainer));
return true;
}
catch (Exception ex)
{
exceptionCallback(ex);
}
}
return false;
}
Bluetooth radio bridge like EM120 via EDB10
The most complicated connection type is ConnectionType.BluetoothRadio
because it combines two existing parameters (Bluetooth and radio) to a new type:
public async Task<bool> ConnectViaBluetoothRadio(Action<Exception> exceptionCallback, String bluetoothAddress, int channel, int networkId)
{
if (_sensor.IsSupported(ConnectionType.BluetoothRadio))
{
var connectionParameterBluetooth = _sensor.CreateConnectionParameter(ConnectionParameterType.BluetoothSocketSettings) as IConnectionParameterBluetoothSocketSettings;
connectionParameterBluetooth.BluetoothParameter = connectionParameterBluetooth.CreateBluetoothParameter(bluetoothAddress);
var connectionParameterRadio = _sensor.CreateConnectionParameter(ConnectionParameterType.RadioCommonSettings) as IConnectionParameterRadioCommonSettings;
connectionParameterRadio.Channel = channel;
connectionParameterRadio.NetworkId = networkId;
var parameters = new List<IConnectionParameter> { connectionParameterBluetooth, connectionParameterRadio };
var connectionSettingsContainer = new ConnectionSettings(ConnectionType.BluetoothRadio, parameters);
try
{
await Task.Run(() => _sensor.Connect(connectionSettingsContainer));
Initialize();
return true;
}
catch (Exception ex)
{
exceptionCallback(ex);
}
}
return false;
}
This examples also shows a principle of the SDK.
There are multiple ConnectionParamterType
s based on the connection. Examples are:
IConnectionParameterBluetoothSocketSettings
for the Bluetooth socket addressIConnectionParameterRadioCommonSettings
for radio id and channelIConnectionParameterSerialSettings
for the serial port
All such settings get collected in a List
- in this case a List<IConnectionParameter>
called parameters
.
In the end the ConnectionType
as well as the parameter list describing this connection type go into a final ConnectionSettings
instance which is used for the connection process.