Created
January 29, 2010 09:32
-
-
Save pklaus/289597 to your computer and use it in GitHub Desktop.
Example Usage of the NETIO-230A class written in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// example of usage of the class for the Koukaam NETIO-230A written in C# | |
// find it on <http://koukaam.se/koukaam/forum/viewthread.php?forum_id=33&thread_id=1569> | |
using System; | |
using CSC.Koukaam.NetIO230A.DiscoverProtocol; | |
using CSC.Koukaam.NetIO230A; | |
namespace netio230a_cs | |
{ | |
class MainClass | |
{ | |
public static void Main(string[] args) | |
{ | |
Console.WriteLine("NETIO-230A CS v0.1"); | |
// Create an instance of the discover object | |
Discover NetIODiscover = new Discover(); | |
// Create a handler for the devices it returns | |
NetIODiscover.DeviceList += new DeviceListEventHandler(NetIODiscover_DeviceList); | |
// Discover all devices in the network | |
NetIODiscover.GetAllDevices(); | |
} | |
static void NetIODiscover_DeviceList(object sender, DeviceListEventArgs e) | |
{ | |
if (e.Devices.Count > 0) | |
{ | |
try | |
{ | |
// Read the first device in the list (we might have more) | |
DeviceInfoPacket packet = e.Devices[0]; | |
// Use the device info packet to create an instance of the device class | |
Device device = packet.ToDevice(); | |
/* if you would want to instantiate the Device manually you would do: | |
System.Net.IPAddress ip = System.Net.IPAddress.Parse("192.168.102.4"); | |
Device device = new Device("Zarathustra", ip, 1234); */ | |
// Set username and password of the device | |
device.Username = "admin"; | |
device.Password = "admin"; | |
// Check if the password and the username are valid | |
if (device.CredentialsValid) | |
{ | |
// read the name of the port 1 of the device | |
string port1name = device[DevicePort.One].Name; | |
// write it to the console | |
Console.WriteLine(port1name); | |
// read the name of the port 1 of the device | |
double version = device.Version; | |
// write it to the console | |
Console.WriteLine(version.ToString("#0.00")); | |
// read the system time of the device | |
DateTime systemTime = device.TimeSettings.SystemTime; | |
// write it to the console | |
Console.WriteLine(systemTime.ToString("dd.MM.yyyy HH:mm:ss")); | |
// Turn off port 2 (it will instantly turn the port off) | |
device[DevicePort.Two].Status = false; | |
} | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} | |
} | |
else | |
{ | |
Console.WriteLine("No NETIO-230A found"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment