Index: tools/FAD/simple_daq/Makefile
===================================================================
--- tools/FAD/simple_daq/Makefile	(revision 255)
+++ tools/FAD/simple_daq/Makefile	(revision 256)
@@ -2,5 +2,5 @@
 CFLAGS=-c -Wall
 LDFLAGS=
-SOURCES=simple_daq.cpp cmd_send.cpp
+SOURCES=simple_daq.cpp cmd_send.cpp ../SocketFunctions/SocketFunctions.cpp
 OBJECTS=$(SOURCES:.cpp=.o)
 EXECUTABLE=simple_daq
Index: tools/FAD/simple_daq/simple_daq.cpp
===================================================================
--- tools/FAD/simple_daq/simple_daq.cpp	(revision 255)
+++ tools/FAD/simple_daq/simple_daq.cpp	(revision 256)
@@ -1,5 +1,5 @@
 /********************************************************************\
 
-  Read 8 Channels from FAD-Board
+  Read SOCKETS_PER_FAD Channels from FAD-Board
   Write Commands to Socket 0, Commands must be (n * 16) Bit long
   
@@ -18,85 +18,59 @@
 #endif
 #include "simple_daq.h"
+#include "../SocketFunctions/SocketFunctions.h"
 
-int SocketDescriptor[8];
+
+int *SocketDescriptor;
 
 int main(int argc, char *argv[])
 {
+	// what kind of buffer is this?
 	char Buffer[MAX_COM_SIZE];
 	
-	// default server
-	char ServerName[IP_ADDR_LENGTH] = IP_ADDR_DEFAULT; // default IP-Address
+	int read_return;
 
-	int i, read_return;
+	fd_set ReadFileDescriptor;
+	int max_fd = 0;
+	
+	FILE* outfile[SOCKETS_PER_FAD];
+	char outfilename[PATH_MAX];
 
-	int DAQPort = FIRST_DAQPORT;
-	struct sockaddr_in SocketAddress[8];
-	struct in_addr Serveripv4addr;
-	fd_set ReadFileDescriptor;
-
-	FILE* fhandle[8];
-	char fname[PATH_MAX];
-
-	int max_fd = 0;
-
-	// Get IP-Address from command line
+	
+		SimpleDaqConfiguration *conf;
+	// Get configuration file path from command line
+	// Get configurarion from configurationfile.
+	// such as FAD IP Adress
 	if (argc > 1)
 	{
-		strncpy (ServerName, argv[1], IP_ADDR_LENGTH);
+		conf = getConfig(argv[1]);
+	} else {
+		conf = getConfig(CONFIG_FILE_PATH);
 	}
 	
-	// Convert IP-Addr to binary
-	if (inet_pton (AF_INET, ServerName, &Serveripv4addr) <= 0)
-	{
-		printf ("Error: network address not valid\n");
+	// Open sockets
+	SocketDescriptor = OpenSockets(SOCKETS_PER_FAD);
+	if (SocketDescriptor == NULL) {
 		exit_program (EXIT_FAILURE);
 	}
+	max_fd = GetMaxFileDescriptor(SOCKETS_PER_FAD, SocketDescriptor);
+	
+	// Connect to server
+	if( Connect2Server(	SocketDescriptor, SOCKETS_PER_FAD, FIRST_DAQPORT, conf->FADIPAddress, 1) != SOCKETS_PER_FAD) {
+			// Connect2Server prints some error messages in case of exceptions...
+			printf ("Error in Connect2Server()\n");
+			exit_program (EXIT_FAILURE);
+	}
 
-	// Open sockets
-	for (i = 0; i < 8; i++)
+	// Open files for output
+	for (int i = 0; i < SOCKETS_PER_FAD; i++)
 	{
-		if ((SocketDescriptor[i] = socket (PF_INET, SOCK_STREAM, 0)) == -1)
+		sprintf (outfilename, "%s/%s-%d.%s", conf->outfilepath, conf->outfilename, i, conf->outfileext);
+		if ((outfile[i] = fopen (outfilename, "w")) == NULL)
 		{
-			printf ("Error: Could not open socket Nr.: %d\n", i);
-			exit_program (EXIT_FAILURE);
-		}
-		else
-		{
-			if (SocketDescriptor[i] > max_fd)
-			{
-				max_fd = SocketDescriptor[i];
-			}
-		}
-	}
-	
-	// Open files for output
-	for (i = 0; i < 8; i++)
-	{
-		sprintf (fname, "socket-%d.dat", i);
-		if ((fhandle[i] = fopen (fname, "w")) == NULL)
-		{
-			printf ("Error: Could not open file %s\n", fname);
+			printf ("Error: Could not open file %s\n", outfilename);
 			exit_program (EXIT_FAILURE);
 		}
 	}
 
-	// Connect to server
-	printf ("Trying to connect to %s...\n", ServerName);
-	for (i = 0; i < 8; i++)
-	{
-		SocketAddress[i].sin_family = PF_INET;
-		SocketAddress[i].sin_port = htons ((unsigned short) DAQPort + i);
-		SocketAddress[i].sin_addr = Serveripv4addr;
-		
-		if (connect (SocketDescriptor[i], (struct sockaddr *) &SocketAddress[i], sizeof (SocketAddress[i])) == -1)
-		{
-			printf ("Error: Could not connect to server %s (port %d)\n", ServerName, DAQPort + i);
-			exit_program (EXIT_FAILURE);
-		}
-		else
-		{
-			printf ("Connected to %s:%d\n", ServerName, DAQPort + i);
-		}
-	}
 
 	signal (SIGPIPE, SIG_IGN); // Do not kill process if writing to closed socket
@@ -108,9 +82,7 @@
 		fflush (stdout);
 
-		FD_ZERO (&ReadFileDescriptor);
-		
+		FD_ZERO (&ReadFileDescriptor);		
 		FD_SET(STDIN_FILENO, &ReadFileDescriptor);
-		
-		for (i = 0; i < 8; i++)
+		for (int i = 0; i < SOCKETS_PER_FAD; i++)
 		{
 			FD_SET (SocketDescriptor[i], &ReadFileDescriptor);
@@ -137,5 +109,5 @@
 		{
 			// Check all sockets
-			for (i = 0; i < 8; i++)
+			for (int i = 0; i < SOCKETS_PER_FAD; i++)
 			{
 				if (FD_ISSET (SocketDescriptor[i], &ReadFileDescriptor))
@@ -153,7 +125,7 @@
 						printf ("Socket [%d]: Read %d Bytes\n", i, read_return);
 					
-						fwrite (Buffer, 1, (size_t) read_return, fhandle[i]);
+						fwrite (Buffer, 1, (size_t) read_return, outfile[i]);
 						// Important!!!
-						fflush (fhandle[i]);
+						fflush (outfile[i]);
 					}
 				}
@@ -167,9 +139,7 @@
 // close sockets and exit
 void exit_program (int exit_status)
-{
-	int i;
-	
+{	
 	printf ("\nClosing Sockets...");
-	for (i = 0; i < 8; i++)
+	for (int i = 0; i < SOCKETS_PER_FAD; i++)
 	{
 		close (SocketDescriptor[i]);
@@ -185,2 +155,25 @@
 	exit_program (EXIT_SUCCESS);
 }
+
+
+// note: verbose is not used, but anyway defined.
+SimpleDaqConfiguration *getConfig (char *path, int verbose) {
+FILE* ConfigFile;
+// try to open config file
+// if not exists return NULL
+ConfigFile = fopen (path, "r");
+if (ConfigFile == NULL) {
+	return NULL;
+}
+
+//create SimpleDaqConfiguration
+SimpleDaqConfiguration *conf = new SimpleDaqConfiguration();
+
+// read config data from file and fill in SimpleDaqConfiguration
+fscanf( ConfigFile , "%s" , conf->FADIPAddress );
+fscanf( ConfigFile , "%s" , conf->outfilepath );
+fscanf( ConfigFile , "%s" , conf->outfilename );
+fscanf( ConfigFile , "%s" , conf->outfileext );
+
+return conf;
+}
Index: tools/FAD/simple_daq/simple_daq.h
===================================================================
--- tools/FAD/simple_daq/simple_daq.h	(revision 255)
+++ tools/FAD/simple_daq/simple_daq.h	(revision 256)
@@ -13,8 +13,7 @@
 #define MAX_COM_SIZE 32000
 #define IP_ADDR_LENGTH 16
-//#define IP_ADDR_DEFAULT "192.33.99.225"
-#define IP_ADDR_DEFAULT "129.217.160.119"
 
 #define FIRST_DAQPORT 5000
+#define SOCKETS_PER_FAD 8
 
 // Commands for FAD
@@ -43,7 +42,18 @@
 #define MAX_DACVAL 65535
 
+#define CONFIG_FILE_PATH "config.txt"
+
+class SimpleDaqConfiguration {
+public:
+	char FADIPAddress[IP_ADDR_LENGTH];
+	char outfilepath[200];
+	char outfilename[50];
+	char outfileext[10];
+};
+
 void cmd_send (char* Buffer, int Socket); // Send commands to socket
 void int_handler (int sig); // Handle signal SIGINT (CTRL-C)
 void exit_program (int exit_status); // Cleanup and exit
+SimpleDaqConfiguration *getConfig (char *path, int verbose = 0);
 
 #endif /*SOCKETCLIENT_H_*/
