Skip to content

Commit

Permalink
Add timer example
Browse files Browse the repository at this point in the history
  • Loading branch information
o3o committed Jun 8, 2017
1 parent 11368ec commit 7b6dcb8
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .editorconfig
@@ -0,0 +1,19 @@
[*.d]
dfmt_align_switch_statements = true
# allman, otbs, or stroustrup
dfmt_brace_style = otbs
#dfmt_brace_style = stroustrup
dfmt_outdent_attributes = true
dfmt_outdent_labels = true
dfmt_soft_max_line_length = 80
dfmt_space_after_cast = false
dfmt_space_after_keywords = true
dfmt_split_operator_at_line_end = false

trim_trailing_whitespace = true
end_of_line = lf
indent_size = 3
indent_style = space
insert_final_newline = true
max_line_length = 120
tab_width = 8
12 changes: 12 additions & 0 deletions examples/timerc/dub.sdl
@@ -0,0 +1,12 @@
name "timer"
description "Simple timer example"
authors "Orfeo Da Viá"
copyright "Copyright © 2017, o3o"
license "LGPL v3.0.0"
dependency "dinodave" path="../../"

targetType "executable"
targetPath "bin"
libs "nodave" platform="posix"
sourceFiles "../../lib/libnodave.lib" platform="windows-x86_32-dmd"
copyFiles "../../lib/libnodave.dll" platform="windows-x86_32-dmd"
34 changes: 34 additions & 0 deletions examples/timerc/src/app.d
@@ -0,0 +1,34 @@
import std.stdio;
import std.conv;

import dinodave;

void main(string[] args) {
enum string IP = "192.168.0.150";
string ip = IP;
if (args.length > 1) {
ip = args[1];
}

writeln("Use ip ", ip);
writeln("\nTrying to read 4 items from Timers (supposed to work S7-3xx/4xx)\n");
auto dc = createConnection(ip);
// read 4 timers: each timer has 2 bytes
const(int) res = daveReadBytes(dc, daveTimer, 0, 0, 4, null);

writefln("function result:%d=%s\n", res, daveStrerror(res));

if (res == 0) {
writeln("\nShowing the results using daveGetSeconds(dc)\n");
writefln("Time: %0.3f, ", daveGetSeconds(dc));
writefln("%0.3f, ", daveGetSeconds(dc));
writefln("%0.3f, ", daveGetSeconds(dc));
writefln(" %0.3f\n", daveGetSeconds(dc));

writeln("\nShowing the same results using daveGetSecondsAt(dc,position)\n");
writefln("Time: %0.3f, ", daveGetSecondsAt(dc, 0));
writefln("%0.3f, ", daveGetSecondsAt(dc, 2));
writefln("%0.3f, ", daveGetSecondsAt(dc, 4));
writefln(" %0.3f\n", daveGetSecondsAt(dc, 6));
}
}

0 comments on commit 7b6dcb8

Please sign in to comment.