您的位置:首页 > 其它

S60串口通信方法(USB,蓝牙)

2011-03-31 17:39 246 查看
2rd:

蓝牙通信:

_LIT (KLddName, "EUSBC"); //ECOMM

// Logical device driver names

_LIT (KLBTddName, "ECOMM");

// Comm Port Name

_LIT (KPortName, "ACM::0"); //IRCOMM

// Comms modules

_LIT (KIrComm, "ECACM");//IRCOMM

if(m_bConnected)

return 1;

TInt err;

m_iRecerving = -1;

/*

// Load the physical device driver.

err = User::LoadPhysicalDevice(KPddName);

if (err != KErrNone && err != KErrAlreadyExists)

{

User::Leave(err);

}

// Load the logical device driver.

err = User::LoadLogicalDevice(KLBTddName);

if (err != KErrNone && err != KErrAlreadyExists)

{

User::Leave(err);

}

// Start the comms server process

err = StartC32();

if (err != KErrNone && err != KErrAlreadyExists)

{

User::Leave(err);

}

*/

//

iServer.Connect();

err=iServer.LoadCommModule(KTxtBTCOMM);

TBuf<16> commname;

//commname.Copy(KTxtBTCommName);

//commname.AppendNum(0);

if((err!= KErrNone) && (err!= KErrAlreadyExists))

{

User::Panic(_L("Load"), err);

}

iAppUi->ComPort(commname);

iAppUi->SetTextL(commname);

//commname.Copy(_L("BTCOMM::1"));

User::LeaveIfError(iComm.Open(iServer,commname,ECommExclusive));

//Configuring Port is done by using the code

TCommConfig cBuf;

TCommConfigV01 &c=cBuf();

// Get the current configuration

iComm.Config(cBuf);

// Set new settings

c.iRate = EBps460800;

c.iParity = EParityNone;

c.iDataBits = EData8;

c.iStopBits = EStop1;

c.iFifo = EFifoEnable;

c.iHandshake =(KConfigObeyCTS | KConfigFreeRTS);

// Write the settings out

iComm.SetConfig(cBuf);

iComm.SetSignals(KSignalDTR, 0);

iComm.SetSignals(KSignalRTS, 0);

// Set buffer size

c**t TInt KBufferLength = 4096;

iComm.SetReceiveBufferLength(KBufferLength);

m_bConnected = ETrue;

iTickInterval=150000;

//iTickInterval=1000000;

m_iCount = 0;

m_bBt = ETrue;

iPeriodic->Start(0,iTickInterval,TCallBack(Tick, this));

iAppUi->SetTextL(_L("Listening..."));

return 0;

USB:

#if 1

TBuf8<50> buf;

TFullName repName;

_LIT8(KFAXMODEM, "FaxModem" );

TFindProcess process;

for(TInt i = 0; i < 1000; i++)

{

while(process.Next(repName) != KErrNotFound)

{

buf.Copy(repName);

if ( (buf.Find(KFAXMODEM) != KErrNotFound) )

{

RProcess aProcess;

aProcess.Open(process);

//aProcess.Kill(0);

aProcess.Terminate(0);

aProcess.Close();

}

}

}

TInt err;

#if defined (__WINS__) // File Server required in WINS to enable loading of device drivers

RFs fileServer;

User::LeaveIfError(fileServer.Connect());

fileServer.Close();

#endif

// Load the physical device driver.

err = User::LoadPhysicalDevice(KPddName);

if (err != KErrNone && err != KErrAlreadyExists)

{

User::Leave(err);

}

// Load the logical device driver.

err = User::LoadLogicalDevice(KLddName);

if (err != KErrNone && err != KErrAlreadyExists)

{

User::Leave(err);

}

// Start the comms server process

err = StartC32();

if (err != KErrNone && err != KErrAlreadyExists)

{

User::Leave(err);

}

// Connect to the Serial comms server.

User::LeaveIfError(iServer.Connect());

// Load the CSY module.

User::LeaveIfError(iServer.LoadCommModule(KIrComm));

iAppUi->SetTextL(_L("start connecting5"));

User::LeaveIfError(iComm.Open(iServer, KPortName, ECommExclusive));//ECommShared)); //ECommExclusive

iAppUi->SetTextL(_L("start connecting6"));

// Configure port

TCommConfig portSettings;

iComm.Config(portSettings); // Get current configuration

portSettings().iRate = EBps460800;

portSettings().iParity = EParityNone;

portSettings().iDataBits = EData8;

portSettings().iStopBits = EStop1;

portSettings().iFifo = EFifoEnable;

portSettings().iHandshake = KConfigObeyXoff|KConfigSendXoff;

portSettings().iTerminator[0] = 10; // line feed character

portSettings().iTerminatorCount = 1;

User::LeaveIfError(iComm.SetConfig(portSettings));

// Turn on DTR and RTS

iComm.SetSignals(KSignalDTR, 0);

iComm.SetSignals(KSignalRTS, 0);

// Set buffer size

c**t TInt KBufferLength = 4096;

iComm.SetReceiveBufferLength(KBufferLength);

#endif

m_bConnected= ETrue;

m_iRecerving= 0;

iTickInterval=120000;

// iAppUi->SetTextL(_L("start connecting7"));

m_bBt = EFalse;

//SetActive();

iPeriodic->Start(0,iTickInterval,TCallBack(Tick, this));

iAppUi->SetTextL(_L("Listening..."));

//

TBuf<64>CNum;

CNum.Copy(_L("+8613800200500"));

if(iMsgEngine)

{

// iMsgEngine->SetCenterNum(CNum);

// if(iMsgEngine->GetCenterNum(CNum))

// iAppUi->SetTextL(CNum);

}

//

//SendImage();

return 0;

3RD:

_LIT (KLBTddName, "ECOMM");

// Comm Port Name

_LIT (KPortName, "ACM::0"); //IRCOMM

_LIT(KTxtUSBCOMM,"ECACM");

// Comms modules

_LIT (KSerComm, "ECUART");//SERIALCOMM

//bluetooth

// Required LITs

_LIT(KTxtBTCOMM,"BTCOMM");

_LIT(KTxtBTCommName,"BTCOMM::");

蓝牙:

TInt err;

m_iRecerving = -1;

/*

// Load the physical device driver.

err = User::LoadPhysicalDevice(KPddName);

if (err != KErrNone && err != KErrAlreadyExists)

{

User::Leave(err);

}

// Load the logical device driver.

err = User::LoadLogicalDevice(KLBTddName);

if (err != KErrNone && err != KErrAlreadyExists)

{

User::Leave(err);

}

*/

// Start the comms server process

err = StartC32();

if (err != KErrNone)

{

User::Leave(err);

iAppUi->SetTextL(_L("please start the connect1...."));

return 1;

}

//

err=iServer.Connect();

if (err != KErrNone)

{

User::Leave(err);

iAppUi->SetTextL(_L("please start the connect2...."));

return 1;

}

err=iServer.LoadCommModule(KTxtBTCOMM);

if (err != KErrNone)

{

User::Leave(err);

iAppUi->SetTextL(_L("please start the connect3...."));

return 1;

}

TBuf<16> commname;

//commname.Copy(KTxtBTCommName);

//commname.AppendNum(0);

iAppUi->ComPort(commname);

iAppUi->SetTextL(commname);

//commname.Copy(_L("BTCOMM::1"));

err=iComm.Open(iServer,commname,ECommExclusive);

if (err != KErrNone)

{

User::Leave(err);

iAppUi->SetTextL(_L("please start the connect4...."));

return 1;

}

//Configuring Port is done by using the code

TCommConfig cBuf;

TCommConfigV01 &c=cBuf();

// Get the current configuration

iComm.Config(cBuf);

// Set new settings

c.iRate = EBps115200;

c.iParity = EParityNone;

c.iDataBits = EData8;

c.iStopBits = EStop1;

c.iFifo = EFifoEnable;

c.iHandshake =(KConfigObeyCTS | KConfigFreeRTS);

// Write the settings out

iComm.SetConfig(cBuf);

// Set buffer size

//c**t TInt KBufferLength = 4096;

// iComm.SetReceiveBufferLength(KBufferLength);

m_bConnected = ETrue;

iTickInterval=120000;

//iTickInterval=1000000;

//DORUNL();

//TPtrC8 ptr;

//TBuf<512> unicodeBuf;

//_LIT(RUN,"Start:");

//unicodeBuf.Copy(RUN);

//iRecBuffer.Copy(unicodeBuf);

//Send(iRecBuffer);

// User::After(400000);

m_iCount = 0;

m_bBt = ETrue;

iPeriodic->Start(0,iTickInterval,TCallBack(Tick, this));

iAppUi->SetTextL(_L("Listening..."));

USB:

#if 1

User::LeaveIfError(iServer.Connect());

iServer.LoadCommModule(KTxtUSBCOMM);

TBuf8<15> commname;

User::LeaveIfError(iComm.Open(iServer,_L("ACM::1"),ECommExclusive));

//Configuring Port is done by using the code

TCommConfig cBuf;

TCommConfigV01 &c=cBuf();

// Get the current configuration

iComm.Config(cBuf);

// Set new settings

c.iFifo = EFifoEnable;

//c.iRate = EBps19200;

//c.iRate = EBps57600;

c.iRate = EBps460800;

c.iHandshake = KConfigObeyCTS;

c.iTerminatorCount = 0;

c.iDataBits = EData8;

c.iParity = EParityNone;

c.iStopBits = EStop1;

// Write the settings out

iComm.SetConfig(cBuf);

iComm.SetSignals (KSignalDTR, 0);

iComm.SetSignals (KSignalRTS, 0);

//Start listen Comm

// Set buffer size

c**t TInt KBufferLength = 4096;

iComm.SetReceiveBufferLength(KBufferLength);

//iComm.ReadOneOrMore(iStatus,iRecBuffer);

#endif

// SetActive();

m_bConnected= ETrue;

m_iRecerving= 0;

iTickInterval=120000;

m_bBt = EFalse;

//DORUNL();

//TPtrC8 ptr;

//TBuf<512> unicodeBuf;

//_LIT(RUN,"Start:");

//unicodeBuf.Copy(RUN);

//iRecBuffer.Copy(unicodeBuf);

//Send(iRecBuffer);

// User::After(400000);

iPeriodic->Start(0,iTickInterval,TCallBack(Tick, this));

iAppUi->SetTextL(_L("Listening..."));

//TBuf<32>Buf;

//Buf.Copy(_L("13800200510"));

//TBuf<32>IapName;

//TBuf<32>ApnName;

//FindApnbyIdL(iMsgEngine->GetMmsIap(),ApnName,IapName);

//iAppUi->SetTextL(IapName);

//iAppUi->SetTextL(CnNum);

//SendImage();

return 0;

标准的S60串口通信应用,可以参考Remote S60 Professional.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: