├── .gitignore
├── CMakeLists.txt
├── test
├── df1d
└── test.php
├── src
├── write_float.c
├── write_integer.c
├── read_float.c
├── read_integer.c
├── read_boolean.c
├── write_boolean.c
├── write_AB.c
├── read_A2.c
├── write_AA.c
├── read_socket.c
├── main.c
├── select_fnct.c
├── common.c
├── server.c
├── calc_address.c
├── df1.h
├── serial.c
└── df1.c
├── README
└── Makefile
/.gitignore:
--------------------------------------------------------------------------------
1 | CMakeFiles/
2 | bin/
3 | cmake_install.cmake
4 | CMakeCache.txt
5 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 2.6)
2 |
3 | #Déclaration du projet
4 | project(df1)
5 | set(EXECUTABLE_OUTPUT_PATH bin/${CMAKE_BUILD_TYPE})
6 |
7 | #Génération de la liste des fichiers sources
8 | file(
9 | GLOB_RECURSE
10 | source_files
11 | src/*
12 | )
13 |
14 | #Déclaration de l'exécutable
15 | add_executable(
16 | df1
17 | ${source_files}
18 | )
19 |
--------------------------------------------------------------------------------
/test/df1d:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # chkconfig: 2345 80 90
4 | # description: Server df1 for SLC500 AB PLC
5 |
6 | PATH=/sbin:/bin:/usr/sbin:/usr/bin
7 | export PATH
8 |
9 | # Source function library.
10 | #. /etc/rc.d/init.d/functions
11 |
12 | # See how we are called.
13 | case "$1" in
14 | start)
15 | printf "Starting df1 server...\n"
16 | df1
17 | echo ""
18 | ;;
19 | stop)
20 | PID=`pidof -s df1`
21 | if [ "$PID" ]; then
22 | printf "Stopping df1 server...\n"
23 | kill -3 $PID
24 | fi
25 | echo ""
26 | ;;
27 | restart)
28 | $0 stop
29 | $0 start
30 | ;;
31 | *)
32 | printf "Usage: df1 {start|stop|restart}\n"
33 | exit 1
34 | esac
35 |
36 |
--------------------------------------------------------------------------------
/src/write_float.c:
--------------------------------------------------------------------------------
1 | /* Copyright (C) 2002 Stephane LEICHT (stephane.leicht@gmail.com)
2 | *
3 | * This program is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation, either version 3 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * This program is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with this program. If not, see .
15 | */
16 |
17 | #include "df1.h"
18 |
19 | //*********************************************************
20 | int write_float(int plctype, char *straddress, float *value)
21 | {
22 | int error=ERROR_WRITE;
23 | TThree_Address_Fields address;
24 |
25 | if ((error = calc_address(straddress,&address))!=SUCCES)
26 | return error;
27 | if (plctype==SLC)
28 | error=write_AA(address,value,sizeof(*value));
29 | return error;
30 | }
31 |
--------------------------------------------------------------------------------
/src/write_integer.c:
--------------------------------------------------------------------------------
1 | /* Copyright (C) 2002 Stephane LEICHT (stephane.leicht@gmail.com)
2 | *
3 | * This program is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation, either version 3 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * This program is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with this program. If not, see .
15 | */
16 |
17 | #include "df1.h"
18 |
19 | //*********************************************************
20 | int write_integer(int plctype, char *straddress, word *value)
21 | {
22 | int error=ERROR_WRITE;
23 | TThree_Address_Fields address;
24 |
25 | if ((error = calc_address(straddress,&address))!=SUCCES)
26 | return error;
27 | if (plctype==SLC)
28 | error=write_AA(address,value,sizeof(*value));
29 | return error;
30 | }
31 |
--------------------------------------------------------------------------------
/src/read_float.c:
--------------------------------------------------------------------------------
1 | /* Copyright (C) 2002 Stephane LEICHT (stephane.leicht@gmail.com)
2 | *
3 | * This program is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation, either version 3 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * This program is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with this program. If not, see .
15 | */
16 |
17 | #include "df1.h"
18 |
19 | //*********************************************************
20 | int read_float(int plctype, char *straddress, float *value)
21 | {
22 | int error=ERROR_READ_INTEGER;
23 | TThree_Address_Fields address;
24 |
25 | *value=0;//init to 0
26 | if ((error = calc_address(straddress,&address))!=SUCCES)
27 | return error;
28 | if (plctype==SLC)
29 | error=read_A2(address,value,sizeof(*value));
30 | return error;
31 | }
32 |
--------------------------------------------------------------------------------
/src/read_integer.c:
--------------------------------------------------------------------------------
1 | /* Copyright (C) 2002 Stephane LEICHT (stephane.leicht@gmail.com)
2 | *
3 | * This program is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation, either version 3 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * This program is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with this program. If not, see .
15 | */
16 |
17 | #include "df1.h"
18 |
19 | //*********************************************************
20 | int read_integer(int plctype, char *straddress, word *value)
21 | {
22 | int error=ERROR_READ_INTEGER;
23 | TThree_Address_Fields address;
24 |
25 | *value=0;//init to 0
26 | if ((error = calc_address(straddress,&address))!=SUCCES)
27 | return error;
28 | if (plctype==SLC)
29 | error=read_A2(address,value,sizeof(*value));
30 | return error;
31 | }
32 |
--------------------------------------------------------------------------------
/src/read_boolean.c:
--------------------------------------------------------------------------------
1 | /* Copyright (C) 2002 Stephane LEICHT (stephane.leicht@gmail.com)
2 | *
3 | * This program is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation, either version 3 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * This program is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with this program. If not, see .
15 | */
16 |
17 | #include "df1.h"
18 |
19 | //*********************************************************
20 | int read_boolean(int plctype, char *straddress, int *value)
21 | {
22 | int error=ERROR_READ_INTEGER;
23 | TThree_Address_Fields address;
24 | byte posit;
25 | int temp=1;
26 | int tempvalue;
27 |
28 | tempvalue=0;//init to 0
29 | if ((error = calc_address(straddress,&address))!=SUCCES)
30 | return error;
31 | posit=address.s_eleNumber;
32 | address.s_eleNumber=0;
33 | if (plctype==SLC)
34 | error=read_A2(address,&tempvalue,sizeof(tempvalue));
35 | *value=(temp&(tempvalue>>posit));
36 | return error;
37 | }
38 |
--------------------------------------------------------------------------------
/src/write_boolean.c:
--------------------------------------------------------------------------------
1 | /* Copyright (C) 2002 Stephane LEICHT (stephane.leicht@gmail.com) h
2 | *
3 | * This program is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation, either version 3 of the License, or
6 | * (at your option) any later version.
7 | *
8 | * This program is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with this program. If not, see .
15 | */
16 |
17 | #include "df1.h"
18 |
19 | //*********************************************************
20 | int write_boolean(int plctype, char *straddress, int *value)
21 | {
22 | int error=ERROR_READ_INTEGER;
23 | TThree_Address_Fields address;
24 | byte posit;
25 | word valuebool;
26 | word mask;
27 |
28 | if ((error = calc_address(straddress,&address))!=SUCCES)
29 | return error;
30 | posit=address.s_eleNumber;
31 | if (plctype==SLC){
32 | mask = 0x0001<
2 |
3 | TEST
4 |
5 |
6 |
7 | Test DF1
8 |
9 | $service_port = 17560;
10 | $address = "localhost";
11 | $socket = socket_create( AF_INET, SOCK_STREAM, 0 );
12 | if( $socket < 0 ) {
13 | echo "socket_create() failed: reason: " . socket_strerror( $socket ) . "\n";
14 | exit;
15 | }
16 |
17 | /* Attempt to connect to $address on $service_port */
18 | if( !( socket_connect( $socket, $address, $service_port ) ) ) {
19 | $result = socket_last_error( $socket );
20 | socket_clear_error( $socket );
21 | print "Error connecting to $ip:$port -- " . socket_strerror( $result ) . " ($result)\n";
22 | exit;
23 | }
24 | function readSLC($tag) {
25 | global $socket;
26 | $value = "";
27 | socket_write( $socket, $tag, strlen( $tag ) );
28 | $value = socket_read( $socket, 128, PHP_NORMAL_READ );
29 | return trim($value);
30 | }
31 | function writeSLC($tag,$value) {
32 | global $socket;
33 | $tag = $tag ."=".$value;
34 | socket_write( $socket, $tag, strlen( $tag ) );
35 | $value = socket_read( $socket, 128, PHP_NORMAL_READ );
36 | return trim($value);
37 | }
38 | echo "Time SLC : ".readSLC('S2:40').":".readSLC('S2:41').":".readSLC('S2:42')."
";
39 | echo "
";
40 | echo "F8:0=".floatval(readSLC('F8:0'))."
";
41 | echo "
";
42 | echo "F8:1=".floatval(readSLC('F8:1'))."
";
43 | echo "
";
44 | echo "F8:2=".floatval(readSLC('F8:2'))."
";
45 | echo "
";
46 | echo "
";
47 |
48 | echo "N7:4= ".readSLC('n7:4')."
";
49 | //echo "write N7:4=10".writeSLC('n7:4','10')."
";
50 | echo "
";
51 |
52 | socket_close( $socket );
53 |
54 | ?>
55 |
56 |