examples/SerialComms/ServerClientSide/IRPrinting/IRPrinting.cpp

00001 /*
00002 Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008   list of conditions and the following disclaimer.
00009 * Redistributions in binary form must reproduce the above copyright notice,
00010   this list of conditions and the following disclaimer in the documentation
00011   and/or other materials provided with the distribution.
00012 * Neither the name of Nokia Corporation nor the names of its contributors
00013   may be used to endorse or promote products derived from this software
00014   without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 Description:  
00028 */
00029 
00030 
00031 
00032 #include <e32base.h>
00033 #include <e32test.h>
00034 #include <e32svr.h>
00035 #include <c32comm.h>
00036 #include "f32file.h"
00037 
00038 #include "CommonFiles.h"
00039 
00040 // Device driver names
00041 #if defined (__WINS__)
00042 _LIT(PDD_NAME,"ECDRV");
00043 _LIT(LDD_NAME,"ECOMM");
00044 #else
00045 _LIT(PDD_NAME,"EUART1");
00046 _LIT(LDD_NAME,"ECOMM");
00047 #endif
00048 
00049 _LIT8(DATA_STRING,"Symbian platform infra red printing\n\r");
00050 
00051 LOCAL_C void InitL();
00052 
00053 // Do the example 
00054 LOCAL_C void doExampleL()
00055     {
00056         _LIT(KStatus0,"Connect to file server\n");
00057         _LIT(KStatus1,"Connect to comm server\n");
00058         _LIT(KStatus2,"Load IrCOMM.CSY\n");
00059         _LIT(KStatus3,"Open IrCOMM::0\n");
00060         _LIT(KStatus4,"Write to IrCOMM::0\n");
00061         _LIT(KStatus5,"Close IrCOMM::0\n");
00062         _LIT(KStatus6,"Close server connection\n");
00063         _LIT(KIrCOMM,"IrCOMM");
00064         _LIT(KIrCOMM0,"IrCOMM::0");
00065 
00066         const TTimeIntervalMicroSeconds32 KTimeOut(4000000);
00067         //time-out value
00068 
00069         console->Printf(KStatus0);
00070                                 // force a link to the file server
00071                                 // so that we're sure the loader 
00072                                 // will be present
00073 
00074         RFs f;
00075         User::LeaveIfError(f.Connect());
00076         f.Close();
00077                                 // InitLialisation
00078 
00079         InitL();
00080                                 
00081         RCommServ server;
00082 
00083                                 // Connect to the comm server
00084         console->Printf(KStatus1);
00085         User::LeaveIfError(server.Connect());
00086 
00087                                 // Load the IrCOMM comm module
00088                                 // C32 will automatically search \System\Libs
00089                                 // on all drives for IrCOMM.CSY
00090         console->Printf(KStatus2);
00091         TInt ret=server.LoadCommModule(KIrCOMM);
00092         
00093         //test(ret==KErrNone);
00094         User::LeaveIfError(ret);
00095                 
00096         RComm commPort;
00097                                 // Open the IrCOMM port unit 0 (the only one supported)
00098                                 // Open port in exclusive mode because we don't 
00099                                 // have any access control code.
00100         console->Printf(KStatus3);
00101         ret=commPort.Open(server,KIrCOMM0,ECommExclusive);
00102         //test(ret==KErrNone);
00103         User::LeaveIfError(ret);
00104 
00105         TRequestStatus status;
00106                                 // Write to the IrCOMM port - the first write 
00107                                 // takes a long time as the IrDA connection is 
00108                                 // set up in response to this request. Subsequent 
00109                                 // writes to IrCOMM are very fast.
00110         console->Printf(KStatus4);
00111         commPort.Write(status,KTimeOut,DATA_STRING);
00112         User::WaitForRequest(status);
00113 
00114         //test(status.Int()==KErrNone);
00115 
00116                                 // Close port
00117         console->Printf(KStatus5);
00118         commPort.Close();
00119 
00120         console->Printf(KStatus6);
00121         server.Close();
00122         }
00123 
00124 
00125 LOCAL_C void InitL()
00126 //
00127 // InitLialisation code - loads the serial LDD and PDD
00128 // starts the comm subsystem (for EPOC32 builds)
00129 // On a full Symbian platform implementation, this code would not
00130 // be required because higher level GUI components  
00131 // automatically start the services.
00132 //
00133         {
00134         // Load the physical device driver
00135         // The OS will automatically append .PDD and 
00136         // search /System/Libs on all drives.
00137 
00138         TInt r=User::LoadPhysicalDevice(PDD_NAME);
00139         if (r != KErrNone && r!= KErrAlreadyExists)
00140                 User::Leave(r);
00141         //test(r==KErrNone || r==KErrAlreadyExists);
00142         // Similarly for the Logical device driver
00143         r=User::LoadLogicalDevice(LDD_NAME);
00144         if (r != KErrNone && r != KErrAlreadyExists)
00145                 User::Leave(r);
00146         //test(r==KErrNone|| r==KErrAlreadyExists);
00147 
00148 #if defined (__EPOC32__)
00149         // For EPOC builds we need to start the comms subsystem
00150         // This call actually starts the comms server process
00151         r=StartC32();
00152         if (r != KErrAlreadyExists)
00153                 User::LeaveIfError(r);
00154 #endif
00155         }
00156 
00157 

Generated by  doxygen 1.6.2