本文整理汇总了C#中ConnectionManager.StartConnectionManager方法的典型用法代码示例。如果您正苦于以下问题:C# ConnectionManager.StartConnectionManager方法的具体用法?C# ConnectionManager.StartConnectionManager怎么用?C# ConnectionManager.StartConnectionManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConnectionManager
的用法示例。
在下文中一共展示了ConnectionManager.StartConnectionManager方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Setup
// Setup function
public void Setup()
{
_transport = new SerialTransport {CurrentSerialSettings = {DtrEnable = false}};
// some boards (e.g. Sparkfun Pro Micro) DtrEnable may need to be true.
// We do not need to set serial port and baud rate: it will be found by the connection manager
// Initialize the command messenger with the Serial Port transport layer
// Set if it is communicating with a 16- or 32-bit Arduino board
_cmdMessenger = new CmdMessenger(_transport, BoardType.Bit16)
{
PrintLfCr = false // Do not print newLine at end of command, to reduce data being sent
};
// The Connection manager is capable or storing connection settings, in order to reconnect more quickly
// the next time the application is run. You can determine yourself where and how to store the settings
// by supplying a class, that implements ISerialConnectionStorer. For convenience, CmdMessenger provides
// simple binary file storage functionality
var serialConnectionStorer = new SerialConnectionStorer("SerialConnectionManagerSettings.cfg");
// We don't need to provide a handler for the Identify command - this is a job for Connection Manager.
_connectionManager = new SerialConnectionManager(
_transport as SerialTransport,
_cmdMessenger,
(int) Command.Identify,
CommunicationIdentifier,
serialConnectionStorer)
{
// Enable watchdog functionality.
WatchdogEnabled = true,
// Instead of scanning for the connected port, you can disable scanning and only try the port set in CurrentSerialSettings
//DeviceScanEnabled = false
};
// Show all connection progress on command line
_connectionManager.Progress += (sender, eventArgs) =>
{
// If you want to reduce verbosity, you can only show events of level <=2 or ==1
if (eventArgs.Level <= 3) Console.WriteLine(eventArgs.Description);
};
// If connection found, tell the arduino to turn the (internal) led on
_connectionManager.ConnectionFound += (sender, eventArgs) =>
{
// Create command
var command = new SendCommand((int)Command.TurnLedOn);
// Send command
_cmdMessenger.SendCommand(command);
};
//You can also do something when the connection is lost
_connectionManager.ConnectionTimeout += (sender, eventArgs) =>
{
//Do something
};
// Finally - activate connection manager
_connectionManager.StartConnectionManager();
}
示例2: Initialize
public void Initialize()
{
Debug.WriteLine("***********************************START*************************");
_transport = new SerialTransport { CurrentSerialSettings = { DtrEnable = false } };
_cmdMessenger = new CmdMessenger(_transport, BoardType.Bit16) { PrintLfCr = false };
_cmdMessenger.NewLineReceived += _cmdMessenger_NewLineReceived;
_cmdMessenger.NewLineSent += _cmdMessenger_NewLineSent;
AttachCallbacks();
_connectionManager = new SerialConnectionManager((_transport as SerialTransport), _cmdMessenger, (int)Command.Watchdog, UniqueDeviceID);
_connectionManager.WatchdogEnabled = true;
_connectionManager.WatchdogTimeout = WatchdogTimeout;
_connectionManager.WatchdogRetryTimeout = WatchdogRetryTimeout;
_connectionManager.ConnectionFound += _connectionManager_ConnectionFound;
_connectionManager.ConnectionTimeout += _connectionManager_ConnectionTimeout;
OnConnecting();
_connectionManager.StartConnectionManager();
}
示例3: Setup
// Setup function
public void Setup()
{
// Let's show all bluetooth devices
ShowBluetoothInfo();
// Now let us set Bluetooth transport
_transport = new BluetoothTransport()
{
// If you know your bluetooth device and you have already paired
// you can directly connect to you Bluetooth Device by adress adress.
// Under windows you can find the adresss at:
// Control Panel >> All Control Panel Items >> Devices and Printers
// Right-click on device >> properties >> Unique id
CurrentBluetoothDeviceInfo = BluetoothUtils.DeviceByAdress("20:13:07:26:10:08")
};
// Initialize the command messenger with the Serial Port transport layer
// Set if it is communicating with a 16- or 32-bit Arduino board
_cmdMessenger = new CmdMessenger(_transport)
{
PrintLfCr = false // Do not print newLine at end of command, to reduce data being sent
};
// The Connection manager is capable or storing connection settings, in order to reconnect more quickly
// the next time the application is run. You can determine yourself where and how to store the settings
// by supplying a class, that implements ISerialConnectionStorer. For convenience, CmdMessenger provides
// simple binary file storage functionality
var bluetoothConnectionStorer = new BluetoothConnectionStorer("BluetoothConnectionManagerSettings.cfg");
// It is easier to let the BluetoothConnectionManager connection for you.
// It will:
// - Auto discover Bluetooth devices
// - If not yet paired, try to pair using the default Bluetooth passwords
// - See if the device responds with the correct CommunicationIdentifier
_connectionManager = new BluetoothConnectionManager(
_transport as BluetoothTransport,
_cmdMessenger,
(int) Command.Identify,
CommunicationIdentifier,
bluetoothConnectionStorer)
{
// Enable watchdog functionality.
WatchdogEnabled = true,
// You can add PIN codes for specific devices
DevicePins =
{
{"01:02:03:04:05:06","6666"},
{"01:02:03:04:05:07","7777"},
},
// You can also add PIN code to try on all unpaired devices
// (the following PINs are tried by default: 0000, 1111, 1234 )
GeneralPins =
{
"8888",
}
};
// Show all connection progress on command line
_connectionManager.Progress += (sender, eventArgs) =>
{
if (eventArgs.Level <= 3) Console.WriteLine(eventArgs.Description);
};
// If connection found, tell the arduino to turn the (internal) led on
_connectionManager.ConnectionFound += (sender, eventArgs) =>
{
// Create command
var command = new SendCommand((int)Command.TurnLedOn);
// Send command
_cmdMessenger.SendCommand(command);
};
// Finally - activate connection manager
_connectionManager.StartConnectionManager();
}