-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from libplctag/new-API
Expose all new APIs
- Loading branch information
Showing
11 changed files
with
287 additions
and
12 deletions.
There are no files selected for viewing
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
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
using System; | ||
using System.Threading; | ||
using libplctag.NativeImport; | ||
|
||
namespace ExampleConsoleApp | ||
{ | ||
class NativeImportExample | ||
{ | ||
public static void Run() | ||
{ | ||
|
||
var tagHandle = plctag.create("protocol=ab_eip&gateway=192.168.0.10&path=1,0&cpu=LGX&elem_size=4&elem_count=1&name=MY_DINT", 1000); | ||
|
||
while (plctag.status(tagHandle) == 1) | ||
{ | ||
Thread.Sleep(100); | ||
} | ||
var statusBeforeRead = plctag.status(tagHandle); | ||
if (statusBeforeRead != 0) | ||
{ | ||
Console.WriteLine($"Something went wrong {statusBeforeRead}"); | ||
} | ||
|
||
plctag.read(tagHandle, 1000); | ||
while (plctag.status(tagHandle) == 1) | ||
{ | ||
Thread.Sleep(100); | ||
} | ||
var statusAfterRead = plctag.status(tagHandle); | ||
if (statusAfterRead != 0) | ||
{ | ||
Console.WriteLine($"Something went wrong {statusAfterRead}"); | ||
} | ||
|
||
var theValue = plctag.get_uint32(tagHandle, 0); | ||
|
||
plctag.destroy(tagHandle); | ||
|
||
Console.WriteLine(theValue); | ||
} | ||
|
||
public static void RunCallbackExample() | ||
{ | ||
|
||
var tagHandle = plctag.create("protocol=ab_eip&gateway=192.168.0.10&path=1,0&cpu=LGX&elem_size=4&elem_count=1&name=MY_DINT", 1000); | ||
|
||
while (plctag.status(tagHandle) == 1) | ||
{ | ||
Thread.Sleep(100); | ||
} | ||
var statusBeforeRead = plctag.status(tagHandle); | ||
if (statusBeforeRead != 0) | ||
{ | ||
Console.WriteLine($"Something went wrong {statusBeforeRead}"); | ||
} | ||
|
||
var myCallback = new plctag.callback_func(MyCallback); | ||
var statusAfterRegistration = plctag.register_callback(tagHandle, myCallback); | ||
if (statusAfterRegistration != 0) | ||
{ | ||
Console.WriteLine($"Something went wrong {statusAfterRegistration}"); | ||
} | ||
|
||
plctag.read(tagHandle, 1000); | ||
while (plctag.status(tagHandle) == 1) | ||
{ | ||
Thread.Sleep(100); | ||
} | ||
var statusAfterRead = plctag.status(tagHandle); | ||
if (statusAfterRead != 0) | ||
{ | ||
Console.WriteLine($"Something went wrong {statusAfterRead}"); | ||
} | ||
|
||
var theValue = plctag.get_uint32(tagHandle, 0); | ||
|
||
plctag.destroy(tagHandle); | ||
|
||
Console.WriteLine(theValue); | ||
} | ||
|
||
public static void MyCallback(int tag_id, int event_id, int status) | ||
{ | ||
Console.WriteLine($"Tag Id: {tag_id} Event Id: {event_id} Status: {status}"); | ||
} | ||
|
||
public static void RunLoggerExample() | ||
{ | ||
var myLogger = new plctag.log_callback_func(MyLogger); | ||
var statusAfterRegistration = plctag.register_logger(myLogger); | ||
if (statusAfterRegistration != 0) | ||
{ | ||
Console.WriteLine($"Something went wrong {statusAfterRegistration}"); | ||
} | ||
|
||
var tagHandle = plctag.create("protocol=ab_eip&gateway=192.168.0.10&path=1,0&cpu=LGX&elem_size=4&elem_count=1&name=MY_DINT&debug=4", 1000); | ||
|
||
while (plctag.status(tagHandle) == 1) | ||
{ | ||
Thread.Sleep(100); | ||
} | ||
var statusBeforeRead = plctag.status(tagHandle); | ||
if (statusBeforeRead != 0) | ||
{ | ||
Console.WriteLine($"Something went wrong {statusBeforeRead}"); | ||
} | ||
|
||
plctag.read(tagHandle, 1000); | ||
while (plctag.status(tagHandle) == 1) | ||
{ | ||
Thread.Sleep(100); | ||
} | ||
var statusAfterRead = plctag.status(tagHandle); | ||
if (statusAfterRead != 0) | ||
{ | ||
Console.WriteLine($"Something went wrong {statusAfterRead}"); | ||
} | ||
|
||
var theValue = plctag.get_uint32(tagHandle, 0); | ||
|
||
plctag.destroy(tagHandle); | ||
|
||
Console.WriteLine(theValue); | ||
|
||
} | ||
|
||
public static void MyLogger(int tag_id, int debug_level, string message) | ||
{ | ||
Console.WriteLine($"Tag Id: {tag_id} Debug Level: {debug_level} Message: {message}"); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
|
||
namespace ExampleConsoleApp | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
Example.Run(); | ||
NativeImportExample.Run(); | ||
NativeImportExample.RunCallbackExample(); | ||
NativeImportExample.RunLoggerExample(); | ||
|
||
Console.Read(); | ||
} | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace libplctag | ||
{ | ||
public enum Events | ||
{ | ||
PLCTAG_EVENT_READ_STARTED = 1, | ||
PLCTAG_EVENT_READ_COMPLETED = 2, | ||
PLCTAG_EVENT_WRITE_STARTED = 3, | ||
PLCTAG_EVENT_WRITE_COMPLETED = 4, | ||
PLCTAG_EVENT_ABORTED = 5, | ||
PLCTAG_EVENT_DESTROYED = 6 | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
|
||
namespace libplctag | ||
{ | ||
|
||
public class BusyException : Exception | ||
{ | ||
public BusyException() | ||
{ | ||
} | ||
|
||
public BusyException(string message) | ||
: base(message) | ||
{ | ||
} | ||
|
||
public BusyException(string message, Exception inner) | ||
: base(message, inner) | ||
{ | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
|
||
namespace libplctag | ||
{ | ||
|
||
public class PartialException : Exception | ||
{ | ||
public PartialException() | ||
{ | ||
} | ||
|
||
public PartialException(string message) | ||
: base(message) | ||
{ | ||
} | ||
|
||
public PartialException(string message, Exception inner) | ||
: base(message, inner) | ||
{ | ||
} | ||
} | ||
} |
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
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
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