diff --git a/LibNoDaveConnectionLibrary/Communication/LibNoDave/libnodave.net.cs b/LibNoDaveConnectionLibrary/Communication/LibNoDave/libnodave.net.cs index d5635813..fefc54f0 100644 --- a/LibNoDaveConnectionLibrary/Communication/LibNoDave/libnodave.net.cs +++ b/LibNoDaveConnectionLibrary/Communication/LibNoDave/libnodave.net.cs @@ -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: @@ -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); @@ -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 ); @@ -2021,7 +2021,7 @@ 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 ); @@ -2029,7 +2029,7 @@ int hwnd 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); @@ -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); @@ -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); diff --git a/LibNoDaveConnectionLibrary/Communication/PLCConnection.cs b/LibNoDaveConnectionLibrary/Communication/PLCConnection.cs index 0bad5ead..4753b27d 100644 --- a/LibNoDaveConnectionLibrary/Communication/PLCConnection.cs +++ b/LibNoDaveConnectionLibrary/Communication/PLCConnection.cs @@ -171,7 +171,7 @@ public string Name private async Task ConnectAsync(TimeSpan connectTimeout) { - _fds.rfd = IntPtr.Zero; + _fds.rfd = 0; if (_tcpClient != null) { @@ -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 @@ -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()); @@ -305,7 +305,7 @@ 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 + ":" + @@ -313,7 +313,7 @@ public void Connect() } //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( @@ -4023,7 +4023,7 @@ public void Dispose() case LibNodaveConnectionTypes.Netlink_Pro: _tcpClient.Close(); _tcpClient = null; - _fds.rfd = IntPtr.Zero; + _fds.rfd = 0; break; } } diff --git a/externalDlls/libnodave/Makefile b/externalDlls/libnodave/Makefile index 0917912d..d3216dee 100644 --- a/externalDlls/libnodave/Makefile +++ b/externalDlls/libnodave/Makefile @@ -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. diff --git a/externalDlls/libnodave/nodave.c b/externalDlls/libnodave/nodave.c index fec723f2..f78222dd 100644 --- a/externalDlls/libnodave/nodave.c +++ b/externalDlls/libnodave/nodave.c @@ -48,6 +48,7 @@ Library specific: #define DECL2 #include #include +#include #endif #ifdef HAVE_UNISTD @@ -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 @@ -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 @@ -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)) { @@ -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; @@ -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) { @@ -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); @@ -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); @@ -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); } @@ -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) { diff --git a/externalDlls/libnodave/nodave.h b/externalDlls/libnodave/nodave.h index df703d9f..757b8fa6 100644 --- a/externalDlls/libnodave/nodave.h +++ b/externalDlls/libnodave/nodave.h @@ -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: @@ -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: diff --git a/externalDlls/libnodave/openSocket.c b/externalDlls/libnodave/openSocket.c index a0243744..8fd3094a 100644 --- a/externalDlls/libnodave/openSocket.c +++ b/externalDlls/libnodave/openSocket.c @@ -34,7 +34,8 @@ #include #include #include - +#include "nodave.h" +#include "log2.h" /* The following two lines seem to be necessary for FreeBSD and do no harm on Linux */ #include