genericopenlibs/cstdlib/TSTLIB/tser2r.c
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 /*
       
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <stdlib.h>	/* definition of exit() */
       
    21 #include <stdio.h>
       
    22 #include <errno.h>
       
    23 #include <string.h>
       
    24 #include <sys/unistd.h>
       
    25 #include <sys/ioctl.h>
       
    26 #include "CTEST.H"
       
    27 
       
    28 
       
    29 
       
    30 #define SIZE 10000
       
    31 
       
    32 
       
    33 
       
    34 void Writer(void)
       
    35 	{
       
    36 	int Port;
       
    37 	SerialConfig sc;
       
    38 	char *buffer;
       
    39 
       
    40 	Port = open("COM1:",0);
       
    41 	(void)ioctl(Port, COMMIOCTL_GETCONFIG, &sc);
       
    42 	sc.iRate = Bps115200;
       
    43 	sc.iParity = ParityNone;
       
    44 	(void)ioctl(Port, COMMIOCTL_SETCONFIG, &sc);
       
    45 	
       
    46 	buffer = (char*)malloc(SIZE);
       
    47 	memset(buffer, '*', SIZE);
       
    48 
       
    49 	write(Port, buffer, SIZE);
       
    50 	
       
    51 	close(Port);
       
    52 
       
    53 	}
       
    54 
       
    55 /**
       
    56 @SYMTestCaseID          SYSLIB-STDLIB-CT-1101
       
    57 @SYMTestCaseDesc	    Tests for reading from the serial port
       
    58 @SYMTestPriority 	    High
       
    59 @SYMTestActions  	    Tests for reading into a buffer of size 1000 bytes from the serial port
       
    60 @SYMTestExpectedResults Test must not fail
       
    61 @SYMREQ                 REQ0000
       
    62 */		
       
    63 void Reader(void)
       
    64 	{
       
    65 	int res;
       
    66 	int Port;
       
    67 	SerialConfig sc;
       
    68 	char *buffer, *p;
       
    69 	int x;
       
    70 
       
    71 
       
    72 	Port = open("COM2:",0);
       
    73 	res = ioctl(Port, COMMIOCTL_GETCONFIG, &sc);
       
    74 	sc.iRate = Bps115200;
       
    75 	sc.iParity = ParityNone;
       
    76 	res = ioctl(Port, COMMIOCTL_SETCONFIG, &sc);
       
    77 	
       
    78 	buffer = (char*)malloc(SIZE);
       
    79 
       
    80 	res = 0;
       
    81 	p = buffer;
       
    82 	
       
    83 
       
    84 	x = 5000;
       
    85 	res = ioctl(Port, COMMIOCTL_SETREADTIMEOUT, &x);
       
    86 
       
    87 	for(x = 0;;x++)
       
    88 		{
       
    89 		res = read(Port, p, 100);
       
    90 		if (res > 0)
       
    91 			{
       
    92 			printf("read block %d int addr %x, bytes %d\n",x,p,res);
       
    93 			p += res;
       
    94 			}
       
    95 
       
    96 		else
       
    97 			break;
       
    98 		}
       
    99 		
       
   100 		
       
   101 	x = 100;
       
   102 	res = ioctl(Port, COMMIOCTL_SETREADTHRESHOLD, &x);
       
   103 	p = buffer;
       
   104 
       
   105 	printf("And again with a threshold of 100\n");
       
   106 	
       
   107 	for(x = 0;;x++)
       
   108 		{
       
   109 		res = read(Port, p, 100);
       
   110 		if (res > 0)
       
   111 			{
       
   112 			printf("read block %d int addr %x, bytes %d\n",x,p,res);
       
   113 			p += res;
       
   114 			}
       
   115 
       
   116 		else
       
   117 			break;
       
   118 		}
       
   119 		
       
   120 	
       
   121 	close(Port);
       
   122 
       
   123 	}
       
   124 
       
   125 int main(void)
       
   126 	{
       
   127 	Reader();
       
   128 	return 0;
       
   129 	}
       
   130