Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions LibNoDaveConnectionLibrary/Communication/LibNoDave/libnodave.net.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ connection to external devices.
*/
public struct daveOSserialType
{
public volatile IntPtr rfd;
public volatile IntPtr wfd;
public int rfd;
public int wfd;
}
/*
Protocol types to be used with new daveInterface:
Expand Down Expand Up @@ -1966,16 +1966,16 @@ public int getErrorOfResult(int number)
#else
[DllImport("__Internal", EntryPoint = "setPort")]
#endif
public static extern IntPtr setPort64([MarshalAs(UnmanagedType.LPStr)] string portName, [MarshalAs(UnmanagedType.LPStr)] string baud, int parity);
public static extern int setPort64([MarshalAs(UnmanagedType.LPStr)] string portName, [MarshalAs(UnmanagedType.LPStr)] string baud, int parity);

#if !IPHONE
[DllImport("libnodave_jfkmod.dll", EntryPoint = "setPort")]
#else
[DllImport("__Internal", EntryPoint = "setPort")]
#endif
public static extern IntPtr setPort32([MarshalAs(UnmanagedType.LPStr)] string portName, [MarshalAs(UnmanagedType.LPStr)] string baud, int parity);
public static extern int setPort32([MarshalAs(UnmanagedType.LPStr)] string portName, [MarshalAs(UnmanagedType.LPStr)] string baud, int parity);

public static IntPtr setPort(string portName, string baud, int parity)
public static int setPort(string portName, string baud, int parity)
{
if (IntPtr.Size == 8)
return setPort64(portName, baud, parity);
Expand Down Expand Up @@ -2011,7 +2011,7 @@ public static IntPtr openSocket(int port, string portName)

#if !IPHONE
[DllImport("libnodave_jfkmod64.dll", EntryPoint = "openS7online")]
public static extern IntPtr openS7online64(
public static extern int openS7online64(
[MarshalAs(UnmanagedType.LPStr)] string portName,
int hwnd
);
Expand All @@ -2021,15 +2021,15 @@ int hwnd

#if !IPHONE
[DllImport("libnodave_jfkmod.dll", EntryPoint = "openS7online")]
public static extern IntPtr openS7online32(
public static extern int openS7online32(
[MarshalAs(UnmanagedType.LPStr)] string portName,
int hwnd
);
#else
public static IntPtr openS7online(string portName, int hwnd) { return IntPtr.Zero; }
#endif

public static IntPtr openS7online(string portName, int hwnd)
public static int openS7online(string portName, int hwnd)
{
if (IntPtr.Size == 8)
return openS7online64(portName, hwnd);
Expand All @@ -2049,16 +2049,16 @@ public static IntPtr openS7online(string portName, int hwnd)
#else
[DllImport("__Internal", EntryPoint = "closePort")]
#endif
protected static extern int closePort64(IntPtr port);
protected static extern int closePort64(int port);

#if !IPHONE
[DllImport("libnodave_jfkmod.dll", EntryPoint = "closePort")]
#else
[DllImport("__Internal", EntryPoint = "closePort")]
#endif
protected static extern int closePort32(IntPtr port);
protected static extern int closePort32(int port);

public static int closePort(IntPtr port)
public static int closePort(int port)
{
if (IntPtr.Size == 8)
return closePort64(port);
Expand Down Expand Up @@ -2088,19 +2088,19 @@ public static int closeSocket(IntPtr port)

#if !IPHONE
[DllImport("libnodave_jfkmod64.dll", EntryPoint = "closeS7online")]
public static extern int closeS7online64(IntPtr port);
public static extern int closeS7online64(int port);
#else
public static int closeS7online(IntPtr port) { return 0; }
#endif

#if !IPHONE
[DllImport("libnodave_jfkmod.dll", EntryPoint = "closeS7online")]
public static extern int closeS7online32(IntPtr port);
public static extern int closeS7online32(int port);
#else
public static int closeS7online(IntPtr port) { return 0; }
#endif

public static int closeS7online(IntPtr port)
public static int closeS7online(int port)
{
if (IntPtr.Size == 8)
return closeS7online64(port);
Expand Down
12 changes: 6 additions & 6 deletions LibNoDaveConnectionLibrary/Communication/PLCConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public string Name

private async Task ConnectAsync(TimeSpan connectTimeout)
{
_fds.rfd = IntPtr.Zero;
_fds.rfd = 0;

if (_tcpClient != null)
{
Expand Down Expand Up @@ -216,7 +216,7 @@ private async Task ConnectAsync(TimeSpan connectTimeout)

Logger?.Invoke("socket thread - got socket pointer:" + _tcpClient.Client.Handle.ToString());

_fds.rfd = _tcpClient.Client.Handle;
_fds.rfd = _tcpClient.Client.Handle.ToInt32();
}

#region General
Expand Down Expand Up @@ -266,7 +266,7 @@ public void Connect()
connectionType = 50;
_errorCodeConverter = libnodave.daveStrerror;
_fds.rfd = libnodave.openS7online(_configuration.EntryPoint, 0);
if (_fds.rfd.ToInt32() == -1)
if (_fds.rfd == -1)
{
_NeedDispose = false;
throw new Exception("Error: " + libnodave.daveStrS7onlineError());
Expand Down Expand Up @@ -305,15 +305,15 @@ public void Connect()

//if the socket handle still has its default value after connection
//this means it was an IP connection type, and it did not succed
if (_fds.rfd == IntPtr.Zero && _configuration.ConnectionType != LibNodaveConnectionTypes.Use_Step7_DLL && _configuration.ConnectionType != LibNodaveConnectionTypes.Use_Step7_DLL_Without_TCP && _configuration.ConnectionType != LibNodaveConnectionTypes.Use_Step7_DLL_Automatic_TCP_Detection)
if (_fds.rfd == 0 && _configuration.ConnectionType != LibNodaveConnectionTypes.Use_Step7_DLL && _configuration.ConnectionType != LibNodaveConnectionTypes.Use_Step7_DLL_Without_TCP && _configuration.ConnectionType != LibNodaveConnectionTypes.Use_Step7_DLL_Automatic_TCP_Detection)
{
_NeedDispose = false;
throw new Exception("Error: Timeout Connecting the IP (" + _configuration.CpuIP + ":" +
_configuration.Port + ")");
}

//if the read handle is still null or even has an error code, except for Simatic NEt connectoins
if ((_configuration.ConnectionType != LibNodaveConnectionTypes.Use_Step7_DLL && _configuration.ConnectionType != LibNodaveConnectionTypes.Use_Step7_DLL_Without_TCP && _configuration.ConnectionType != LibNodaveConnectionTypes.Use_Step7_DLL_Automatic_TCP_Detection && _fds.rfd.ToInt32() == 0) || _fds.rfd.ToInt32() < 0)
if ((_configuration.ConnectionType != LibNodaveConnectionTypes.Use_Step7_DLL && _configuration.ConnectionType != LibNodaveConnectionTypes.Use_Step7_DLL_Without_TCP && _configuration.ConnectionType != LibNodaveConnectionTypes.Use_Step7_DLL_Automatic_TCP_Detection && _fds.rfd == 0) || _fds.rfd < 0)
{
_NeedDispose = false;
throw new Exception(
Expand Down Expand Up @@ -4023,7 +4023,7 @@ public void Dispose()
case LibNodaveConnectionTypes.Netlink_Pro:
_tcpClient.Close();
_tcpClient = null;
_fds.rfd = IntPtr.Zero;
_fds.rfd = 0;
break;
}
}
Expand Down
10 changes: 5 additions & 5 deletions externalDlls/libnodave/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
#
# To test with g++ which does stricter type checking:
#
##CC=g++
CFLAGS=-Wall -Winline -DLINUX -DDAVE_LITTLE_ENDIAN
CTFLAGS=-Wall -Winline -fPID -DLINUX -DDAVE_LITTLE_ENDIAN
CPPFLAGS=-Wall -Winline -DLINUX -DDAVE_LITTLE_ENDIAN
#
CC=gcc
CFLAGS=-Wall -Winline -DLINUX -DDAVE_LITTLE_ENDIAN -fPIC
CTFLAGS=-Wall -Winline -fPID -DLINUX -DDAVE_LITTLE_ENDIAN -fPIC
CPPFLAGS=-Wall -Winline -DLINUX -DDAVE_LITTLE_ENDIAN -fPIC
#
# The following is needed to enable workarounds for statements that do
# not work on (some?) ARM processors:
# It also helped on some machine running HP-UX.
Expand Down
21 changes: 11 additions & 10 deletions externalDlls/libnodave/nodave.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Library specific:
#define DECL2
#include <time.h>
#include <sys/time.h>
#include <sys/socket.h>
#endif

#ifdef HAVE_UNISTD
Expand Down Expand Up @@ -611,7 +612,7 @@ void DECL2 daveAddDbRead400ToReadRequest(PDU *p, int DBnum, int offset, int byte
#endif

#ifdef DEBUG_CALLS
LOG6("daveAddDbRead400ToReadRequest(PDU:%p db:%p offset:%p byteCount:%p)\n", p, DBnum, offset, byteCount);
LOG5("daveAddDbRead400ToReadRequest(PDU:%p db:%p offset:%p byteCount:%p)\n", p, DBnum, offset, byteCount);
FLUSH;
#endif

Expand Down Expand Up @@ -670,7 +671,7 @@ void DECL2 daveAddSymbolToReadRequest(PDU *p, void * completeSymbol, int complet

void DECL2 daveAddSymbolVarToReadRequest(PDU *p, void * completeSymbol, int completeSymbolLength) {
#ifdef DEBUG_CALLS
LOG6("daveAddSymbolVarToReadRequest(PDU:%p symbol:%s)\n", p, completeSymbol);
LOG3("daveAddSymbolVarToReadRequest(PDU:%p symbol:%s)\n", p, completeSymbol);
FLUSH;
#endif

Expand Down Expand Up @@ -1791,7 +1792,7 @@ int DECL2 daveExecReadRequest(daveConnection * dc, PDU *p, daveResultSet* rl){
/* printf("result %d: %d %d %d %d\n",i, *q,q[1],q[2],q[3]); */
if (daveDebug & daveDebugPDU)
{
LOG2("daveExecReadRequest result %d: %d %d %d %d\n", i, *q, q[1], q[2], q[3]);
//LOG2("daveExecReadRequest result %d: %d %d %d %d\n", i, *q, q[1], q[2], q[3]);
FLUSH;
}
if ((*q == 255) && (rlen>4)) {
Expand Down Expand Up @@ -1825,7 +1826,7 @@ int DECL2 daveExecReadRequest(daveConnection * dc, PDU *p, daveResultSet* rl){
/* printf("Store result %d length:%d\n", i, len); */
if (daveDebug & daveDebugPDU)
{
LOG2("Store result %d length:%d\n", i, len);
//LOG2("Store result %d length:%d\n", i, len);
FLUSH;
}
c2->length = len;
Expand Down Expand Up @@ -1949,7 +1950,7 @@ int DECL2 daveUseResultBuffer(daveResultSet * rl, int n, void * buffer){
daveResult * dr;
if (daveDebug & daveDebugAll)
{
LOG2("daveUseResultBuffer(result set:%p, number:%d)\n", rl, n);
//LOG2("daveUseResultBuffer(result set:%p, number:%d)\n", rl, n);
}
if (rl == NULL)
{
Expand Down Expand Up @@ -6336,10 +6337,10 @@ int DECL2 daveGetProgramBlock(daveConnection * dc, int blockType, int number, ch
return daveGetS5ProgramBlock(dc, blockType, number, buffer, length);
}

res = initUpload(dc, blockType, number, &uploadID);
res = initUpload(dc, blockType, number, bb);
if (res != 0) return res;
do {
res = doUpload(dc, &more, &bb, &len, uploadID);
res = doUpload(dc, &more, &bb, &len, (uc*)uploadID);
totlen += len;
if (res != 0) return res;
} while (more);
Expand Down Expand Up @@ -6549,7 +6550,7 @@ int DECL2 daveGetNCProgram(daveConnection *dc, const char *filename, uc *buffer,
len = 0;
totlen = 0;

res = initUploadNC(dc, filename, &uploadID);
res = initUploadNC(dc, filename, bb);
if (res != 0) return res;
do {
res = doUploadNC(dc, &more, &bb, &len, uploadID);
Expand Down Expand Up @@ -7847,7 +7848,7 @@ int DECL2 _daveSCP_send(int fd, uc * reqBlock) {
fdr->offset_1 = 80; //Offset of the Begin of userdata (but the 4 first unkown bytes are not count)

if (fdr->application_block_subsystem == 0xE4) //Fix for PLCSim
Sleep(50); //Fix for PLCSim
sleep(50); //Fix for PLCSim

return SCP_send(fd, fdr->seg_length_1 + fdr->headerlength, reqBlock);
}
Expand All @@ -7858,7 +7859,7 @@ int daveSCP_receive(int h, uc * buffer) {
fdr = (S7OexchangeBlock*)buffer;

if (fdr->application_block_subsystem == 0xE4) //Fix for PLCSim
Sleep(50); //Fix for PLCSim
sleep(50); //Fix for PLCSim

res = SCP_receive(h, 0xFFFF, &datalen, sizeof(S7OexchangeBlock), buffer);
if (daveDebug & daveDebugByte) {
Expand Down
10 changes: 5 additions & 5 deletions externalDlls/libnodave/nodave.h
Original file line number Diff line number Diff line change
Expand Up @@ -759,8 +759,8 @@ extern "C" {
Functions to load blocks from PLC:
*/
EXPORTSPEC void DECL2 _daveConstructUpload(PDU *p, char blockType, int blockNr); // char or uc,to decide
EXPORTSPEC void DECL2 _daveConstructDoUpload(PDU * p, int uploadID);
EXPORTSPEC void DECL2 _daveConstructEndUpload(PDU * p, int uploadID);
EXPORTSPEC void DECL2 _daveConstructDoUpload(PDU * p, uc *uploadID);
EXPORTSPEC void DECL2 _daveConstructEndUpload(PDU * p, uc *uploadID);

/*
Functions to load files from NC:
Expand Down Expand Up @@ -865,9 +865,9 @@ extern "C" {
/*
PLC program read functions:
*/
EXPORTSPEC int DECL2 initUpload(daveConnection * dc, char blockType, int blockNr, int * uploadID); // char or uc,to decide
EXPORTSPEC int DECL2 doUpload(daveConnection*dc, int * more, uc**buffer, int*len, int uploadID);
EXPORTSPEC int DECL2 endUpload(daveConnection*dc, int uploadID);
EXPORTSPEC int DECL2 initUpload(daveConnection * dc, char blockType, int blockNr, uc *uploadID); // char or uc,to decide
EXPORTSPEC int DECL2 doUpload(daveConnection*dc, int * more, uc**buffer, int*len, uc *uploadID);
EXPORTSPEC int DECL2 endUpload(daveConnection*dc, uc *uploadID);

/*
NC file read functions:
Expand Down
3 changes: 2 additions & 1 deletion externalDlls/libnodave/openSocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>

#include "nodave.h"
#include "log2.h"
/* The following two lines seem to be necessary for FreeBSD and do no harm on Linux */

#include <netinet/in.h>
Expand Down