📄 syncserialengine.cpp
字号:
/*
* ============================================================================
* Name : CSyncSerialEngine from SyncSerialEngine.cpp
* Part of : SyncSerial
* Created : 23.02.2006 by ToBeReplacedByAuthor
* Implementation notes:
* Initial content was generated by Series 60 Application Wizard.
* Version :
* Copyright: ToBeReplacedByCopyright
* ============================================================================
*/
// INCLUDE FILES
#include "SyncSerialEngine.h"
_LIT(CSYMOD, "ECACM");
_LIT(KACMPort1, "ACM::1");
// ================= MEMBER FUNCTIONS =======================
// Two-phased constructor.
CSyncSerialEngine* CSyncSerialEngine::NewL()
{
CSyncSerialEngine* self = new (ELeave) CSyncSerialEngine;
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop();
return self;
}
CSyncSerialEngine::CSyncSerialEngine()
{
}
// Destructor
CSyncSerialEngine::~CSyncSerialEngine()
{
this->Close();
if ( iCommServ )
{
delete iCommServ;
iCommServ = NULL;
}
if ( iComm )
{
delete iComm;
iComm = NULL;
}
}
TInt CSyncSerialEngine::Send(const TDesC8& aData)
{
TRequestStatus stat;
iComm->Write(stat, aData);
User::WaitForRequest(stat);
return stat.Int();
}
TInt CSyncSerialEngine::Recv(TDes8& aData)
{
TRequestStatus stat;
iComm->ReadOneOrMore(stat, aData);
User::WaitForRequest(stat);
return stat.Int();
}
// ---------------------------------------------------------
// CSyncSerialEngine::ConstructL(const TRect& aRect)
// EPOC two phased constructor
// ---------------------------------------------------------
//
void CSyncSerialEngine::ConstructL()
{
iCommServ = new (ELeave) RCommServ;
iComm = new (ELeave) RComm;
}
// New functions
void CSyncSerialEngine::InitializeL()
{
// RComm is a client to the RCommServ Comms server
// Start this service before any connections are made.
TInt ret = StartC32();
if (ret != KErrNone && ret != KErrAlreadyExists)
{
User::Leave(ret);
}
// Connect to CommServer
User::LeaveIfError(iCommServ->Connect());
// Load CSY Module
User::LeaveIfError(iCommServ->LoadCommModule(CSYMOD));
}
void CSyncSerialEngine::OpenL()
{
TBuf16<KMaxPortName> portName;
portName.Copy(KACMPort1);
// Open the comm. port
User::LeaveIfError(iComm->Open(*iCommServ, portName, ECommShared));
}
void CSyncSerialEngine::ConfigurateL()
{
// Verify capabilities of the port and configure it
TCommCaps portCaps;
iComm->Caps(portCaps);
if (((portCaps().iRate & EBps115200) == 0) | ((portCaps().iDataBits
& KCapsData8) == 0) | ((portCaps().iStopBits & KCapsStop1) == 0)
| ((portCaps().iParity & KCapsParityNone) == 0))
{
User::Leave(KErrNotSupported);
}
TCommConfig portCfg;
iComm->Config(portCfg);
portCfg().iRate = EBps115200;
portCfg().iParity = EParityNone;
portCfg().iDataBits = EData8;
portCfg().iStopBits = EStop1;
portCfg().iHandshake = 0;
User::LeaveIfError(iComm->SetConfig(portCfg));
// now turn on DTR and RTS, and set our buffer size
iComm->SetSignals(KSignalDTR, 0);
iComm->SetSignals(KSignalRTS, 0);
TInt curlenth = iComm->ReceiveBufferLength();
iComm->SetReceiveBufferLength(4096);
}
void CSyncSerialEngine::Close()
{
if ( iComm )
{
iComm->Close();
}
if ( iCommServ )
{
iCommServ->Close();
}
}
void CSyncSerialEngine::InitSerial()
{
this->InitializeL();
this->OpenL();
this->ConfigurateL();
}
void CSyncSerialEngine::CloseSerial()
{
this->Close();
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -