Index: uspace/app/test_serial/test_serial.c
===================================================================
--- uspace/app/test_serial/test_serial.c	(revision bb864a054cda277111ac25d1509e68c165bf92a7)
+++ uspace/app/test_serial/test_serial.c	(revision ba95e8f41817124410b7cfa7c805434f83686dff)
@@ -28,5 +28,5 @@
 
 /** @addtogroup test_serial
- * @brief	test the serial port driver 
+ * @brief	test the serial port driver - read from the serial port
  * @{
  */ 
@@ -35,144 +35,22 @@
  */
 
+#include <errno.h>
+#include <stdlib.h>
 #include <stdio.h>
 #include <ipc/ipc.h>
 #include <sys/types.h>
-#include <atomic.h>
-#include <ipc/devmap.h>
 #include <async.h>
 #include <ipc/services.h>
-#include <ipc/serial.h>
-#include <as.h>
-#include <sysinfo.h>
-#include <errno.h>
-
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-
-#include <string.h>
-
-#define NAME 		"test serial"
-
-/*
-static int device_get_handle(const char *name, dev_handle_t *handle);
-static void print_usage();
-static void move_shutters(const char * serial_dev_name, char room, char cmd);
-static char getcmd(bool wnd, bool up);
-static bool is_com_dev(const char *dev_name);
-
-static int device_get_handle(const char *name, dev_handle_t *handle)
-{
-	int phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, DEVMAP_CLIENT, 0);
-	if (phone < 0)
-		return phone;
-	
-	ipc_call_t answer;
-	aid_t req = async_send_2(phone, DEVMAP_DEVICE_GET_HANDLE, 0, 0, &answer);
-	
-	ipcarg_t retval = ipc_data_write_start(phone, name, str_length(name) + 1); 
-
-	if (retval != EOK) {
-		async_wait_for(req, NULL);
-		ipc_hangup(phone);
-		return retval;
-	}
-
-	async_wait_for(req, &retval);
-
-	if (handle != NULL)
-		*handle = -1;
-	
-	if (retval == EOK) {
-		if (handle != NULL)
-			*handle = (dev_handle_t) IPC_GET_ARG1(answer);
-	}
-	
-	ipc_hangup(phone);
-	return retval;
-}
-
-static void print_usage()
-{
-	printf("Usage: \n test_serial comN count \n where 'comN' is a serial port and count is a number of characters to be read\n");	
-}
-
-
-// The name of a serial device must be between 'com0' and 'com9'.
-static bool is_com_dev(const char *dev_name) 
-{
-	if (str_length(dev_name) != 4) {
-		return false;
-	}
-	
-	if (str_cmp("com0", dev_name) > 0) {
-		return false;
-	}
-	
-	if (str_cmp(dev_name, "com9") > 0) {
-		return false;
-	}
-	
-	return true;
-}
-
-
-int main(int argc, char *argv[])
-{
-	if (argc != 3) {
-		printf(NAME ": incorrect number of arguments.\n");
-		print_usage();
-		return 0;		
-	}	
-
-	
-	const char *serial_dev_name = argv[1];
-	long int cnt = strtol(argv[2], NULL, 10);
-	
-	if (!is_com_dev(serial_dev_name)) {
-		printf(NAME ": the first argument is not correct.\n");
-		print_usage();
-		return 0;	
-	}
-	
-	dev_handle_t serial_dev_handle = -1;
-	
-	if (device_get_handle(serial_dev_name, &serial_dev_handle) !=  EOK) {
-		printf(NAME ": could not get the handle of %s.\n", serial_dev_name);
-		return;
-	}
-	
-	printf(NAME ": got the handle of %s.\n", serial_dev_name);
-	
-	int dev_phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, DEVMAP_CONNECT_TO_DEVICE, serial_dev_handle);
-	if(dev_phone < 0) {
-		printf(NAME ": could not connect to %s device.\n", serial_dev_name);
-		return;
-	}
-	
-	printf("The application will read %d characters from %s: \n", cnt, serial_dev_name);
-	
-	int i, c;
-	for (i = 0; i < cnt; i++) {
-		async_req_0_1(dev_phone, SERIAL_GETCHAR, &c);
-		printf("%c", (char)c);
-	}
-	
-	return 0;
-}*/
-
-
 #include <ipc/devman.h>
 #include <devman.h>
 #include <device/char.h>
 
+#define NAME 		"test serial"
+
 
 static void print_usage()
 {
-	printf("Usage: \n test_serial count \n where count is a number of characters to be read\n");	
+	printf("Usage: \n test_serial count \n where count is the number of characters to be read\n");	
 }
-
 
 int main(int argc, char *argv[])
@@ -195,5 +73,5 @@
 	}
 	
-	printf(NAME ": device handle is %d.\n", handle);	
+	printf(NAME ": trying to read %d characters from device with handle %d.\n", cnt, handle);	
 	
 	int phone;
@@ -212,17 +90,27 @@
 	}
 	
-	int read = read_dev(phone, buf, cnt);
-	if (0 > read) {
-		printf(NAME ": failed read from device, errno = %d.\n", -read);
-		ipc_hangup(phone);
-		devman_hangup_phone(DEVMAN_CLIENT);
-		return 4;
+	int total = 0;
+	int read = 0;
+	while (total < cnt) {		
+		read = read_dev(phone, buf, cnt - total);
+		if (0 > read) {
+			printf(NAME ": failed read from device, errno = %d.\n", -read);
+			ipc_hangup(phone);
+			devman_hangup_phone(DEVMAN_CLIENT);
+			free(buf);
+			return 4;
+		}		
+		total += read;
+		if (read > 0) {			
+			buf[read] = 0;
+			printf(buf);		
+		} else {	
+			usleep(100000);			
+		}	
 	}
-	
-	buf[cnt+1] = 0;
-	printf(NAME ": read data: '%s'.", buf);
 	
 	devman_hangup_phone(DEVMAN_CLIENT);
 	ipc_hangup(phone);
+	free(buf);
 	
 	return 0;
Index: uspace/lib/libc/generic/device/char.c
===================================================================
--- uspace/lib/libc/generic/device/char.c	(revision bb864a054cda277111ac25d1509e68c165bf92a7)
+++ uspace/lib/libc/generic/device/char.c	(revision ba95e8f41817124410b7cfa7c805434f83686dff)
@@ -47,11 +47,8 @@
 	async_serialize_start();
 	
-	printf("calling interface %d\n", DEV_IFACE_ID(CHAR_DEV_IFACE));
 	aid_t req = async_send_1(dev_phone, DEV_IFACE_ID(CHAR_DEV_IFACE), CHAR_READ_DEV, &answer);
 	
-	printf("async_data_read_start \n");
 	int rc = async_data_read_start(dev_phone, buf, len);
 	
-	printf("async_data_read_start, rc = %d\n", rc);
 	if (rc != EOK) {
 		ipcarg_t rc_orig;
@@ -66,7 +63,5 @@
 	}
 	
-	printf("async_wait_for(req, &rc);\n", rc);
 	async_wait_for(req, &rc);
-	printf("async_serialize_end();\n", rc);
 	async_serialize_end();
 	
@@ -75,5 +70,4 @@
 	}
 	
-	printf("IPC_GET_ARG1(answer);\n", rc);
 	return IPC_GET_ARG1(answer);
 }
Index: uspace/lib/libdrv/generic/remote_char.c
===================================================================
--- uspace/lib/libdrv/generic/remote_char.c	(revision bb864a054cda277111ac25d1509e68c165bf92a7)
+++ uspace/lib/libdrv/generic/remote_char.c	(revision ba95e8f41817124410b7cfa7c805434f83686dff)
@@ -58,7 +58,8 @@
 {	
 	char_iface_t *char_iface = (char_iface_t *)iface;
+	ipc_callid_t cid;
 	
 	size_t len;
-	if (!async_data_read_receive(&callid, &len)) {
+	if (!async_data_read_receive(&cid, &len)) {
 		// TODO handle protocol error
 		ipc_answer_0(callid, EINVAL);
@@ -67,5 +68,5 @@
 	
 	if (!char_iface->read) {
-		async_data_read_finalize(callid, NULL, 0);
+		async_data_read_finalize(cid, NULL, 0);
 		ipc_answer_0(callid, ENOTSUP);
 		return;
@@ -80,13 +81,11 @@
 	
 	if (ret < 0) { // some error occured
-		async_data_read_finalize(callid, buf, 0);
+		async_data_read_finalize(cid, buf, 0);
 		ipc_answer_0(callid, ret);
 		return;
 	}
 	
-	printf("remote_char_read - async_data_read_finalize\n");
-	async_data_read_finalize(callid, buf, ret);
-	printf("remote_char_read - ipc_answer_0(callid, EOK);\n");
-	ipc_answer_0(callid, EOK);	
+	async_data_read_finalize(cid, buf, ret);
+	ipc_answer_1(callid, EOK, ret);	
 }
 
@@ -117,5 +116,5 @@
 		ipc_answer_0(callid, ret);
 	} else {
-		ipc_answer_0(callid, EOK);
+		ipc_answer_1(callid, EOK, ret);
 	}
 }
