Commit 0881e316 authored by Stéphane LOS's avatar Stéphane LOS
Browse files

Updated libsnap7 binding and tests

parent 5f97baa4
Pipeline #317255189 passed with stages
in 3 minutes and 28 seconds
......@@ -42,6 +42,8 @@ title Ada For Automation Applications
-- Communication
--- Legacy field buses
--- Real Time Ethernet
--- IoT / IIoT
--- S7 Communication
++ User Interface
+++ Without UI
......@@ -104,6 +106,10 @@ title Ada For Automation
++++_ Master
++++_ Slave
++ LibSnap7
+++ S7 Communication
++++_ Client
++ Hilscher cifX API
+++ Hardware
++++ Dual Port Memory
......@@ -264,6 +270,10 @@ An abstract project, shared by the other ones and containing common Hilscher rel
The project for the libmodbus library. +
It is possible that you have to adjust it to suit your installation.
*libsnap7.gpr* +
The project for the Snap7 library. +
It is possible that you have to adjust it to suit your installation.
*libcifx.gpr* +
The project for the Hilscher cifX Device Driver library. +
It is possible that you have to adjust it to suit your installation. +
......
with "./shared.gpr";
project Libsnap7 is
......@@ -6,10 +7,59 @@ project Libsnap7 is
for Library_Kind use "dynamic";
for Externally_Built use "True";
-- for Library_Dir use "..\..\SNAP7\snap7-full-1.4.2\release\Windows\Win64";
-- for Library_Dir use "..\..\SNAP7\snap7-full-1.4.2\build\bin\Legacy\win64";
for Library_Dir use "..\..\SNAP7\snap7-full-1.4.2\build\windows\GNAT\libs\x86_64";
for Source_Dirs use ("..\..\SNAP7\snap7-full-1.4.2\release\Wrappers\c-cpp");
Snap7_Dir := "../deps_build/Snap7/snap7-full-1.4.2/";
Snap7_Build_Dir := Snap7_Dir & "build/";
for Source_Dirs use (Snap7_Dir & "release/Wrappers/c-cpp");
case Shared.OS is
when "unknown" =>
when "Windows_NT" =>
Snap7_Build_Dir := Snap7_Build_Dir & "windows/GNAT/";
for Library_Dir use Snap7_Build_Dir & "libs/x86_64";
when "linux" =>
Snap7_Build_Dir := Snap7_Build_Dir & "linux/GNAT/";
case Shared.Arch is
when "x86_64" =>
for Library_Dir use Snap7_Build_Dir & "libs/x86_64";
when "armhf" =>
for Library_Dir use "/usr/lib/arm-linux-gnueabihf";
when others =>
for Library_Dir use
"Arch " & Shared.Arch & " is unknown, so is Library_Dir";
end case;
end case;
package Linker is
case Shared.OS is
when "unknown" =>
when "Windows_NT" =>
for Linker_Options use ("--verbose");
when "linux" =>
for Linker_Options use (
-- "--verbose",
"-lpthread",
"-lrt"
);
end case;
end Linker;
end Libsnap7;
......@@ -34,7 +34,7 @@
-- <group>Protocols</group>
-- <c_version>1.4.2</c_version>
-- with System; use System;
with System; use System;
with Interfaces.C;
package A4A.Protocols.LibSnap7 is
......@@ -153,7 +153,8 @@ package A4A.Protocols.LibSnap7 is
-- void *pUsrData);
private
type S7Object is new C.unsigned_long_long;
type S7Object is new System.Address;
-- type S7Object is new C.unsigned_long_long;
-- typedef uintptr_t S7Object;
-- // multi platform/processor object reference
-- // DON'T CONFUSE IT WITH AN OLE OBJECT, IT'S SIMPLY
......
......@@ -23,6 +23,7 @@
------------------------------------------------------------------------------
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Characters.Latin_1;
with Interfaces.C; use Interfaces.C;
......@@ -33,12 +34,10 @@ with A4A.Library.Conversion; use A4A.Library.Conversion;
procedure Test_libsnap7_client is
-- Should work on Linux
-- GREEN_STRING_START : constant String := "\033[42m";
-- GREEN_STRING_STOP : constant String := "\033[m";
-- On Windows, not supported until W10...
GREEN_STRING_START : constant String := "";
GREEN_STRING_STOP : constant String := "";
RED_CONSOLE : constant String := Ada.Characters.Latin_1.ESC & "[41m";
GREEN_CONSOLE : constant String := Ada.Characters.Latin_1.ESC & "[42m";
NORMAL_CONSOLE : constant String := Ada.Characters.Latin_1.ESC & "[0m";
Client : aliased S7Object;
Result : C.int;
......@@ -131,12 +130,12 @@ procedure Test_libsnap7_client is
procedure Show_Data (DataIn : Byte_Array) is
What : constant String := CRLF & GREEN_STRING_START
What : constant String := CRLF & GREEN_CONSOLE
& "***********************************************" & CRLF
& " MyUsrData in Hex" & CRLF & CRLF
& Data_String (DataIn => DataIn) & CRLF
& "***********************************************"
& GREEN_STRING_STOP & CRLF;
& NORMAL_CONSOLE & CRLF;
begin
Put (What);
end Show_Data;
......@@ -420,10 +419,10 @@ begin
Slot => 3);
if Result = 0 then
Put_Line ("Connected ! :-)");
Put_Line (GREEN_CONSOLE & "Connected ! :-)" & NORMAL_CONSOLE);
Connected := True;
else
Put_Line ("Not Connected ! :-(");
Put_Line (RED_CONSOLE & "Not Connected ! :-(" & NORMAL_CONSOLE);
end if;
if Connected then
......@@ -452,10 +451,10 @@ begin
Result := Cli_Disconnect (Client => Client);
if Result = 0 then
Put_Line ("Disconnected ! :-)");
Connected := False;
Put_Line (GREEN_CONSOLE & "Disconnected ! :-)" & NORMAL_CONSOLE);
Connected := True;
else
Put_Line ("Not Disconnected ! :-(");
Put_Line (RED_CONSOLE & "Not Disconnected ! :-(" & NORMAL_CONSOLE);
end if;
end if;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment