Skip to content

Commit

Permalink
Adapted Program.cs to hardware
Browse files Browse the repository at this point in the history
-removed multithreading of UdpListener which would cause the service running the programm to exit
-added try-catch to Trap Handler to deal with new exceptions from MBSecure Class
-change the value to reset all inputs
  • Loading branch information
Kru3mel committed Sep 3, 2021
1 parent 7bcd59d commit 12cdc3e
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions lightSNMP/lightSNMP/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ static void Main(string[] args)

//initialise mbsecure object
MBSecure mbSecure = new MBSecure(ip, readCommunity, writeCommunity);
mbSecure.ResetInputs(2);

mbSecure.ResetInputs(40);

//Start UDP-Listener in seperat Thread
StartUDPListener(mbSecure);
Expand All @@ -35,8 +36,6 @@ static void Main(string[] args)

static void StartUDPListener(MBSecure mbSecure)
{
Task.Run(() =>
{
Console.WriteLine("Task starting");
try
{
Expand Down Expand Up @@ -77,7 +76,6 @@ static void StartUDPListener(MBSecure mbSecure)
{
Console.WriteLine(e.Message);
}
});
}

static void TrapHandler(SnmpV2Packet packet, MBSecure mbSecure)
Expand All @@ -86,13 +84,24 @@ static void TrapHandler(SnmpV2Packet packet, MBSecure mbSecure)
AxisCamera camera = new AxisCamera();
//set corresponding input in MBSecure if trap signals alarm
if (camera.parseTrap(packet)){
if(camera.AlarmText == "true")
try
{
if (camera.AlarmText == "true")
{
mbSecure.SetInput(camera.KameraID, 1);
}
else
{
mbSecure.SetInput(camera.KameraID, 0);
}
}
catch(SocketException ex)
{
mbSecure.SetInput(camera.KameraID, 1);
Console.WriteLine(ex.Message);
}
else
catch
{
mbSecure.SetInput(camera.KameraID, 0);
Console.WriteLine("Could not set Input");
}
}
}
Expand Down

0 comments on commit 12cdc3e

Please sign in to comment.