static void Main(string[] args) { try { // enable the logger, writes to the console kdrive.Logger.SetConsoleChannel(); BaosConnection baosConnection = new BaosConnection(); using (baosConnection) { // create a TPC/IP connection with the remote BAOS device baosConnection.connectIpByName("Baos-Sample", true); Connector connector = new Connector(baosConnection); // turn light on, sleep, turn light off switchLight(connector, true); waitTimeout(connector); switchLight(connector, false); baosConnection.disconnect(); } } catch (kdrive.KdriveException exception) { Console.WriteLine(exception.Message); } finally { // release the logging resources kdrive.Logger.Shutdown(); } }
static void Main(string[] args) { try { // enable the logger, writes to the console kdrive.Logger.SetConsoleChannel(); BaosConnection baosConnection = new BaosConnection(); using (baosConnection) { // create a TPC/IP connection with the remote BAOS device baosConnection.connectIpByName("Baos-Sample"); Connector connector = new Connector(baosConnection); readServerItems(connector); baosConnection.disconnect(); } } catch (kdrive.KdriveException exception) { Console.WriteLine(exception.Message); } finally { // release the logging resources kdrive.Logger.Shutdown(); } }
/// <summary> /// Event handler for click buttonRead /// First we create a connection to the device /// with the Name or IP in the textbox. Is that device not available, we see /// an error message in the messagebox. Otherwise we create the connection and read /// out the datapoints properties /// </summary> private void buttonRead_Click(object sender, EventArgs e) { // clear old data from the data grid dataGridView.Rows.Clear(); if (editConnection.Text == "") { MessageBox.Show("Please insert a valid IP-Address or Name"); return; } try { BaosConnection baosConnection = new BaosConnection(); using (baosConnection) { if (radioByIP.Checked) { // create a TPC/IP connection with the remote BAOS device by IPv4 address baosConnection.connectIp(editConnection.Text, true); } else { //Connecting with the device which has this Name baosConnection.connectIpByName(editConnection.Text, true); } Connector connector = new Connector(baosConnection); //Reading the datapoints readDatapointDescriptions(connector); baosConnection.disconnect(); } } catch (kdrive.KdriveException exception) { MessageBox.Show(exception.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
/// <summary> /// Release the resources and disconnect /// </summary> private void disconnectBaos() { try { if (baosEvent != null) { baosEvent.disable(); } if (baosConnection != null) { baosConnection.disconnect(); baosConnection.Dispose(); } } catch (kdrive.KdriveException exception) { MessageBox.Show(exception.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }