Skip to content

Commit

Permalink
Add createfinsclient
Browse files Browse the repository at this point in the history
  • Loading branch information
o3o committed May 5, 2019
1 parent 094bd81 commit ba8a05a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
12 changes: 9 additions & 3 deletions src/dfins/channel.d
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* Communication channels
*
* Copyright: © 2016-2026 Orfeo Da Vià.
* License: Boost Software License - Version 1.0 - August 17th, 2003
* Authors: Orfeo Da Vià
*/
module dfins.channel;

import std.experimental.logger;
Expand Down Expand Up @@ -41,7 +48,7 @@ interface IChannel {
}

/**
* Implementazione di $(LINK IChannel) con protocollo ethernet (UDP)
* UDP channel.
*/
class UdpChannel : IChannel {
private Socket socket;
Expand All @@ -55,7 +62,7 @@ class UdpChannel : IChannel {
}

/**
* Invia il messaggio e ritorna una risposta
* Send a message and wait for a reply
*/
ubyte[] send(const(ubyte[]) msg) {
int attempt;
Expand Down Expand Up @@ -92,7 +99,6 @@ class UdpChannel : IChannel {
}

/**
/*
* Convenience functions that create an `IChannel` object
*
* Params:
Expand Down
33 changes: 27 additions & 6 deletions src/dfins/fins.d
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Fins client
*
* Copyright: © 2016-2026 Orfeo Da Viá.
* Copyright: © 2016-2026 Orfeo Da Vià.
* License: Boost Software License - Version 1.0 - August 17th, 2003
* Authors: Orfeo Da Vià
*/
Expand Down Expand Up @@ -379,21 +379,17 @@ class FinsClient {
}

/**
* Read an Omron PLC area: the area must be defined as CJ like area
* Read an Omron PLC area
*
* Params:
* area = The area type
* start = The start offset for the read process.
* size = The size of the area to read. IMPORTANT: The size is expressed in WORD (2 byte)
*
*
* Returns:
* The byte array buffer in which will be store the PLC readed area.
*
*/
ubyte[] readArea(MemoryArea area, ushort start, ushort size) {
import std.stdio;

ubyte[] cmdBlock;

//memory area code
Expand Down Expand Up @@ -459,3 +455,28 @@ string mainErrToString(ubyte mainErr) {
return "Unknown error";
}
}

/**
* Convenience functions that create an `FinsClient` object.
*
* Examples:
* --------------------
* FinsClient f = createFinsClient("192.168.1.1", 2000, 9600);
* --------------------
*
* Params:
* ip = IP address
* timeout = Send and receive timeout in ms
* port = Port number (default 9600)
*/
FinsClient createFinsClient(string ip, long timeout, ushort port = 9600)
in {
assert(ip.length);
assert(timeout >= 0);
}
do {
import dfins.channel: IChannel, createUdpChannel;
IChannel chan = createUdpChannel(ip, timeout);
Header h = header(ip.getSubnet);
return new FinsClient(chan, h);
}
4 changes: 4 additions & 0 deletions src/dfins/util.d
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/**
* Utility functions to convert PLC words
*
* Copyright: © 2016-2026 Orfeo Da Vià.
* License: Boost Software License - Version 1.0 - August 17th, 2003
* Authors: Orfeo Da Vià
*/
module dfins.util;

Expand Down

0 comments on commit ba8a05a

Please sign in to comment.