00001 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). 00002 // All rights reserved. 00003 // This component and the accompanying materials are made available 00004 // under the terms of "Eclipse Public License v1.0" 00005 // which accompanies this distribution, and is available 00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html". 00007 // 00008 // Initial Contributors: 00009 // Nokia Corporation - initial contribution. 00010 // 00011 // Contributors: 00012 // 00013 // Description: 00014 // 00015 00016 00017 #include <e32base.h> 00018 #include <e32test.h> 00019 #include <e32svr.h> 00020 #include <c32comm.h> 00021 #include "f32file.h" 00022 00023 #include "CommonFiles.h" 00024 00025 // Device driver names 00026 #if defined (__WINS__) 00027 _LIT(PDD_NAME,"ECDRV"); 00028 _LIT(LDD_NAME,"ECOMM"); 00029 #else 00030 _LIT(PDD_NAME,"EUART1"); 00031 _LIT(LDD_NAME,"ECOMM"); 00032 #endif 00033 00034 _LIT8(DATA_STRING,"Symbian platform infra red printing\n\r"); 00035 00036 LOCAL_C void InitL(); 00037 00038 // Do the example 00039 LOCAL_C void doExampleL() 00040 { 00041 _LIT(KStatus0,"Connect to file server\n"); 00042 _LIT(KStatus1,"Connect to comm server\n"); 00043 _LIT(KStatus2,"Load IrCOMM.CSY\n"); 00044 _LIT(KStatus3,"Open IrCOMM::0\n"); 00045 _LIT(KStatus4,"Write to IrCOMM::0\n"); 00046 _LIT(KStatus5,"Close IrCOMM::0\n"); 00047 _LIT(KStatus6,"Close server connection\n"); 00048 _LIT(KIrCOMM,"IrCOMM"); 00049 _LIT(KIrCOMM0,"IrCOMM::0"); 00050 00051 const TTimeIntervalMicroSeconds32 KTimeOut(4000000); 00052 //time-out value 00053 00054 console->Printf(KStatus0); 00055 // force a link to the file server 00056 // so that we're sure the loader 00057 // will be present 00058 00059 RFs f; 00060 User::LeaveIfError(f.Connect()); 00061 f.Close(); 00062 // InitLialisation 00063 00064 InitL(); 00065 00066 RCommServ server; 00067 00068 // Connect to the comm server 00069 console->Printf(KStatus1); 00070 User::LeaveIfError(server.Connect()); 00071 00072 // Load the IrCOMM comm module 00073 // C32 will automatically search \System\Libs 00074 // on all drives for IrCOMM.CSY 00075 console->Printf(KStatus2); 00076 TInt ret=server.LoadCommModule(KIrCOMM); 00077 00078 //test(ret==KErrNone); 00079 User::LeaveIfError(ret); 00080 00081 RComm commPort; 00082 // Open the IrCOMM port unit 0 (the only one supported) 00083 // Open port in exclusive mode because we don't 00084 // have any access control code. 00085 console->Printf(KStatus3); 00086 ret=commPort.Open(server,KIrCOMM0,ECommExclusive); 00087 //test(ret==KErrNone); 00088 User::LeaveIfError(ret); 00089 00090 TRequestStatus status; 00091 // Write to the IrCOMM port - the first write 00092 // takes a long time as the IrDA connection is 00093 // set up in response to this request. Subsequent 00094 // writes to IrCOMM are very fast. 00095 console->Printf(KStatus4); 00096 commPort.Write(status,KTimeOut,DATA_STRING); 00097 User::WaitForRequest(status); 00098 00099 //test(status.Int()==KErrNone); 00100 00101 // Close port 00102 console->Printf(KStatus5); 00103 commPort.Close(); 00104 00105 console->Printf(KStatus6); 00106 server.Close(); 00107 } 00108 00109 00110 LOCAL_C void InitL() 00111 // 00112 // InitLialisation code - loads the serial LDD and PDD 00113 // starts the comm subsystem (for EPOC32 builds) 00114 // On a full Symbian platform implementation, this code would not 00115 // be required because higher level GUI components 00116 // automatically start the services. 00117 // 00118 { 00119 // Load the physical device driver 00120 // The OS will automatically append .PDD and 00121 // search /System/Libs on all drives. 00122 00123 TInt r=User::LoadPhysicalDevice(PDD_NAME); 00124 if (r != KErrNone && r!= KErrAlreadyExists) 00125 User::Leave(r); 00126 //test(r==KErrNone || r==KErrAlreadyExists); 00127 // Similarly for the Logical device driver 00128 r=User::LoadLogicalDevice(LDD_NAME); 00129 if (r != KErrNone && r != KErrAlreadyExists) 00130 User::Leave(r); 00131 //test(r==KErrNone|| r==KErrAlreadyExists); 00132 00133 #if defined (__EPOC32__) 00134 // For EPOC builds we need to start the comms subsystem 00135 // This call actually starts the comms server process 00136 r=StartC32(); 00137 if (r != KErrAlreadyExists) 00138 User::LeaveIfError(r); 00139 #endif 00140 } 00141 00142
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.