?? rs232transport.cpp
字號:
// Copyright (c) 2004 - 2007, Symbian Software Ltd. All rights reserved.
#include "rs232transport.h"
CRs232Transport::CRs232Transport(MTransportObserver& aObserver)
/**
This c'tor is defined to pass the supplied observer to the superclass.
@param aObserver Observer to notify about transport events.
This is managed by the CTransport superclass.
*/
: CTransport(aObserver)
{
// empty.
}
void CRs232Transport::ConstructL(
const TDesC& aCommModuleName, const TDesC& aPortName, TBool aInitListen)
/**
Attempt to open the described COMM port.
@param aCommModuleName COMM module (CSY) to load with comms server.
@param aPortName Port name to open with RComm.
@param aInitListen Whether the transport should listen for an incoming payload
after it has been created. If false, it should wait for its
owner to give it a payload to send.
*/
{
TRAN_LOG3(">CRs232Transport::ConstructL,mod=\"%S\",port=\"%S\",il=%d", &aCommModuleName, &aPortName, aInitListen);
TInt r;
// connect to the comms server
r = iCommServ.Connect();
TRAN_LOG1("-CRs232Transport::ConstructL,conn=%d", r);
if (r == KErrNone)
r = iCommServ.LoadCommModule(aCommModuleName);
TRAN_LOG1("-CRs232Transport::ConstructL,loadmod=%d", r);
if (r == KErrNone)
r = iComm.Open(iCommServ, aPortName, ECommExclusive, ECommRoleDTE);
TRAN_LOG1("-CRs232Transport::ConstructL,open=%d", r);
TCommConfig ccPckg;
if (r == KErrNone)
r = iComm.Config(ccPckg);
TRAN_LOG1("-CRs232Transport::ConstructL,getconfig=%d", r);
if (r == KErrNone)
{
TCommConfigV01& cc = ccPckg();
cc.iRate = EBps9600;
r = iComm.SetConfig(ccPckg);
}
TRAN_LOG1("-CRs232Transport::ConstructL,setconfig=%d", r);
User::LeaveIfError(r);
CTransport::ConstructL(aInitListen);
TRAN_LOG0("<CRs232Transport::ConstructL");
}
CRs232Transport::~CRs232Transport()
/**
Cancel any outstanding operations; close the connection
with the remote device, and free any resources used by
this transport.
*/
{
FreeResources();
}
void CRs232Transport::FreeResources()
/**
Cancel any outstanding operations; close the comm
subsession, and close the session to the comms server.
This functionality is provided separately to the
destructor in a derived class can call it before
freeing its own resources.
This function can safely be called multiple times.
*/
{
Cancel();
iComm.Close();
iCommServ.Close(); // unloads comm module
}
// -------- implement CTransport --------
void CRs232Transport::DoSendPayloadL()
/**
Implement CTransport by sending the supplied payload
to the remote device.
*/
{
iPayload8.Copy(iPayload);
iComm.Write(iStatus, iPayload8);
// SetActive is called by CTransport::SendPayload
}
void CRs232Transport::DoLaunchRead()
/**
Implement CTransport by waiting for an incoming payload.
*/
{
iComm.Read(iStatus, iPayload8);
// SetActive is called by CTransport::LaunchRead
}
// -------- implement CActive, override CTransport --------
void CRs232Transport::RunL()
/**
Implement CActive and override CTransport by copying
the received data into iPayload, widening the text.
*/
{
// if successful read then widen into iPayload
if (iStatus == KErrNone && iListening)
iPayload.Copy(iPayload8);
CTransport::RunL();
}
void CRs232Transport::DoCancel()
/**
Implement CActive by cancelling any outstanding read or write.
*/
{
iComm.Cancel();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -