Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

[Index] [Glossary] [Previous] [Next]



How to implement a simple IR printing application

The following code illustrates a simple program that pipes data chunks read from a file to the EPOC implementation of IrCOMM.

When the first write is queued, internally, an IrLAP connection is established and an IAS query made on the class “IrDA:IrCOMM” and attribute “Parameters”.

The course of action taken by the IrCOMM module is then determined by the level of IrCOMM support found in the remote device. If a cooked service is supported remotely, then the next IAS query is on class “IrDA:IrCOMM”, attribute “IrDA:TinyTP:LsapSel”. If 3WireRaw is supported remotely, the class remains the same but the attribute changes to “IrDA:IrLMP:LsapSel”. If no IrCOMM implementation is found, then a query is made on class “IrLPT” and attribute “IrDA:IrLMP:LsapSel” as IrCOMM assumes the remote device must be a printer. If that fails, the IrCOMM CSY tries to go ahead and connect to port 2 anyway (which gets around the Extended Systems JetEye 9580 miscapitalisation stack bug). The write does not successfully complete until the corresponding MUX connection succeeds and the data is transmitted as either a TinyTP data frame (if the level of service is cooked) or an LM-MUX data frame (if the level of service is raw).

_LIT8(KTxtIRCOMM,"IRCOMM");
_LIT8(KTxt0,"IrCOMM::0");
TInt ret;
TRequestStatus stat;
RCommServ cs;
//
// CONNECT TO COMMSERV
//
cs.Connect();

//
// LOAD IRCOMM.CSY
//
cs.LoadCommModule(KTxtIRCOMM); // Should return KErrNone

//
// OPEN IrCOMM SERIAL PORT
//
RComm irlpt;
ret = irlpt.Open(cs,KTxt0,ECommExclusive);
if (ret!=KErrNone && ret!=KErrAlreadyExists)
 {
 cs.Close(); // Open failed
 return;
 }

//
// CONNECT TO FILE SERVER
//
RFs fs;
ret = fs.Connect();
if (ret!=KErrNone)
 {
                                       // Connect failed
 }

//
// OPEN DEFAULT FILE CALLED IRCOMM.CPP
//
file.Open(fs,TEST_FILE_NAME,EFileStreamText);
TInt filelen=0;
ret=file.Size(filelen); // Should return KErrNone

//
// READ 2000 BYTE CHUNKS FROM THIS FILE
//
TBuf<2000> abuf;
TInt len=0;
while ((file.Read(abuf)==KErrNone))
 {
 irlpt.Write(stat,abuf); // write chunks to IrCOMM
 User::WaitForRequest(stat);
 if (stat.Int()!=KErrNone)
  {
  goto finished; // Failed
  }
 len+=abuf.Length();
 if (len>=filelen)
  break;
 }
_LIT8(KTxtF,"\f");
irlpt.Write(stat,KTxtF);
User::WaitForRequest(stat);
finished:

//
// CLOSE FILE
//
file.Close();

//
// CLOSE FILE SERVER SESSION
//
fs.Close();

//
// CLOSE IrCOMM PORT
//
irlpt.Close();

//
// CLOSE COMM SERVER CONNNECTION
//
cs.Close();