Comunication serial port help

Login to reply to this topic.
Fri, 2007-01-26 11:47
Joined: 2006-07-21
Forum posts: 151
Hi,
I need to tranfer data throw serial port with my nokia 6680, but not with bluethoot.
How to?
Thanks a lot
Silvia

Tue, 2007-01-30 17:21
Joined: 2006-07-21
Forum posts: 151
Re: Comunication serial port help
Hi,
I resolve problem tu sent data from phone to pc, but How to sent data from pc to phone?
I use this code but don't work fine, connection is rigth but not read:



// Class include
#include "IrSerialEngine.h"

// System includes
#include <e32def.h>
#include <e32std.h>
#include <aknnotewrappers.h>

// Physical device driver names
//#if defined (__WINS__)
//_LIT (KPddName, "ECDRV");   //"ECDRV"
//#else
_LIT (KPddName, "EUART1");
//#endif

// Logical device driver names
_LIT (KLddName, "EUSBC"); //ECOMM

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

// Comms modules
_LIT (KIrComm, "ECACM");//IRCOMM
CIrSerialEngine* CIrSerialEngine::NewL(TInt aPriority, CIrSerialAppUi* aAppUi)
    {
    CIrSerialEngine* self = new (ELeave) CIrSerialEngine(aPriority, aAppUi);
    CleanupStack::PushL(self);
    self->ConstructL();
    CleanupStack::Pop(); // self
    return self;
    }

CIrSerialEngine::~CIrSerialEngine()
    {
    Close();
    }

CIrSerialEngine::CIrSerialEngine(TInt aPriority, CIrSerialAppUi* aAppUi)
: CActive(aPriority), iAppUi(aAppUi)
    {
    }

void CIrSerialEngine::ConstructL()
    {
    CActiveScheduler::Add(this);
    }

void CIrSerialEngine::InitialiseL()
    {
    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(iCommServer.Connect());

    // Load the CSY module.
    User::LeaveIfError(iCommServer.LoadCommModule(KIrComm));
    }

void CIrSerialEngine::OpenL()
    {
      
    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.Close();
         }
      }
   }
   
   
    User::LeaveIfError(iCommPort.Open(iCommServer, KPortName, ECommShared)); //ECommExclusive
   
   
    // Configure port
    TCommConfig portSettings;
    iCommPort.Config(portSettings); // Get current configuration

   
    portSettings().iRate = EBps460800;
   portSettings().iParity = EParityNone;
   portSettings().iDataBits = EData8;
   portSettings().iStopBits = EStop1;
   portSettings().iFifo = EFifoEnable;
   portSettings().iHandshake =(KConfigObeyCTS | KConfigFreeRTS);
   
    User::LeaveIfError(iCommPort.SetConfig(portSettings));
 
    // Set buffer size
    const TInt KBufferLength = 4096;
    iCommPort.SetReceiveBufferLength(KBufferLength);
   
    }

void CIrSerialEngine::Transmit(const TDesC& aTxData)
    {
    // Timeout Value
    const TTimeIntervalMicroSeconds32 KTimeOut(4000000);
    Cancel();

    iDataBuf.Copy(aTxData);
    iCommPort.Write(iStatus, KTimeOut, iDataBuf);
    SetActive();
    }

void CIrSerialEngine::Close()
    {
    iCommPort.Close();
    iCommServer.Close();
    }

void CIrSerialEngine::RunL()
    {
    Close();
    TInt err = iStatus.Int();
    iAppUi->PrintResultDialogL(err);
    }

void CIrSerialEngine::DoCancel()
    {
    iCommPort.WriteCancel();
    }


void CIrSerialEngine::Read(TInt aLength)
{
   const TTimeIntervalMicroSeconds32 KTenthSecond(4000000);
   TBuf8 <200> iReadBuffer;
   iCommPort.Read(iStatus,KTenthSecond,iReadBuffer,aLength);
   TBuf <220> cc;
   cc.Copy(iReadBuffer);
   CEikonEnv::Static()->AlertWin(_L("letto"), cc);
   User::WaitForRequest(iStatus);
   TInt r = iStatus.Int ();
   User::LeaveIfError (r);
}

TInt CIrSerialEngine::ReadBlock()
{
   TBuf8 <200> localInputBuffer;
   TBuf8 <1> iReadBuffer1;
   iCommPort.ReadOneOrMore(iStatus,localInputBuffer);
   User::WaitForRequest(iStatus);
   if (iReadBuffer1.Length())
      return iReadBuffer1[0];
   else
      return -1;
}

When i tel this in my apui I write:
 iInfraredEngine->InitialiseL();
            iInfraredEngine->OpenL();
            iInfraredEngine->Read(200);

Where is the problem??
thanks
Silvia
Wed, 2007-01-31 12:47
Joined: 2006-07-21
Forum posts: 151
Re: Comunication serial port help
Any idea??
I use Hyperterminal to send string to phone, is rigth?
there is other method?
Help me please Sad
Best regard
Silvia
Thu, 2007-02-01 12:22
Joined: 2003-10-10
Forum posts: 32
Re: Comunication serial port help
I think you miss something in SetConfig. Try don't do this at all.
Thu, 2007-03-01 09:55
Joined: 2007-02-28
Forum posts: 12
Re: Comunication serial port help
I have the same problem, I keep in touch if I find something !
But I wonder why the User::WaitForRequest() return immediately with nothing in the read buffer ...
Fri, 2007-03-02 10:24
Joined: 2007-02-28
Forum posts: 12
Re: Comunication serial port help
Ok I finally managed to make it work but there are still some strange behaviours ... I made it work on a Nokia N70 connected with the DKU-2 cable on the USB port of my computer.

Here is the config. of the port :

Code:
#if defined (__WINS__)
_LIT (KPddName, "ECDRV");   //"ECDRV"
#else
_LIT (KPddName, "EUART1");
#endif

// Logical device driver names
_LIT (KLddName, "EUSBC");

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

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

//
// the init function :
//

void CSimKeyAppUi::InitCableLink(){
TInt err;

#if defined (__WINS__)
RFs fileServer;
User::LeaveIfError (fileServer.Connect ());
fileServer.Close ();
#endif

err = User::LoadPhysicalDevice (KPddName); // step 1
    if (err != KErrNone && err != KErrAlreadyExists)
        {
        User::Leave(err);
        }
err = User::LoadLogicalDevice (KLddName); // step 2
if (err != KErrNone && err != KErrAlreadyExists)
        {
        User::Leave(err);
        }
#if !defined (__WINS__)
    err = StartC32 (); // step 3
    if (err != KErrNone && err != KErrAlreadyExists){
        User::Leave(err);
    }
#endif
   
User::LeaveIfError(UsbServ.Connect());
UsbServ.LoadCommModule (KSerComm);
UsbClient.Open (UsbServ, KPortName, ECommExclusive); // step 6

#if !defined (__WINS__)
TCommConfig portSettings;
UsbClient.Config(portSettings); // Get current configuration

portSettings().iRate = EBps460800;
portSettings().iParity = EParityNone;
portSettings().iDataBits = EData8;
portSettings().iStopBits = EStop1;
portSettings().iHandshake =(KConfigFreeCTS | KConfigFreeRTS);
portSettings().iTerminator[0] = 10;
portSettings().iTerminatorCount = 1;

User::LeaveIfError(UsbClient.SetConfig(portSettings));
UsbClient.SetSignals (KSignalDTR, 0);
UsbClient.SetSignals (KSignalRTS, 0);
// Set buffer size
const TInt KBufferLength = 1024;
UsbClient.SetReceiveBufferLength(KBufferLength);
#endif
}

The Port Reading code :

Code:
TRequestStatus ReqInfo;
//Code for the UI message
iEikonEnv->InfoMsg(_L("Open"));
CAknInformationNote* note = new (ELeave) CAknInformationNote;

TBuf8<200> SerBuf;
TBuf<200> WriteBuf;

//Wait for an input of any length, return immediatly if there are unread stuff on the input port
UsbClient.ReadOneOrMore(ReqInfo,SerBuf);
User::WaitForRequest(ReqInfo);
User::LeaveIfError(ReqInfo.Int());
WriteBuf.Copy(SerBuf);
note->ExecuteLD(WriteBuf);

The strange thing is that I am unable to read the port with the Read() function (it doesn't read anything) and the QueryReceiveBuffer() function return alwawys 0 (even if there is some stuff on the port that ReadOneOrMore() can find)

Someone has an idea about this strange behaviour ?
Fri, 2007-03-23 11:15
Joined: 2007-03-23
Forum posts: 1
Re: Comunication serial port help
Hi, I don't speak very  well english and I'm sorry for this.
I have a problem with bluetooth serial comunication.
I want read nmea string from virtual serial port bluetooth and, for this reason, I have tried the code below but give me an error (-1=KErrNotFound).
Help me!
   _LIT(KMessage0,"Select S for RS232 Serial or R for InfraRed port : ");
   _LIT(KMessage1,"Select 0 for no handshaking, 1 for CTS/RTS and 2 for XON/XOFF :");
   _LIT(KMessage4,"Loading device drivers\n");
   _LIT(KMessage5,"Starting comms server\n");
   _LIT(KMessage6,"Connecting to comms server\n");
   _LIT(KMessage7,"Loading %S.CSY module\n");
   _LIT(KMessage8,"%S has %S available as %S::%u to %S::%u\n");
   _LIT(KMessage9,"Opened %S\n");
   _LIT(KMessage10,"Configuring Serial port for 115200 bps 8 bits no parity 1 stop\n");
   _LIT(KMessage11,"Powering up port\n");
   _LIT(KMessage12,"\nDisconnecting\n");
   _LIT(KMessage13,"\nWrite Failed %d\n");
   _LIT(KMessage16,"\nRead failed %d\n");
   _LIT(KMessage17,"Closed %S\n");
   _LIT(KMessage18,"Closing server connection\n");
   _LIT(KMessage19,"Comms server reports we have %u comms modules loaded\n");
   _LIT(KMessage20,"Using the lowest %S out of %S::%u to %S::%u\n");
   
   _LIT(KPanic,"StraySignal");
   _LIT(RS232,"ECUART");//
   _LIT(IRCOMM,"IRCOMM");

   TBuf16 < 6 > csyName;
   RComm commPort;
   TUint8 csyMode;
   const TUint8 mask=0xdf; // this mask 0xdf turns lower to upper case
   TInt r;


   csyName.Copy(RS232);

TInt ret =StartC32 ();
if ( ret != KErrNone && ret != KErrAlreadyExists )

        {

        User::Leave ( ret );

        }   

TInt result;


   // Load the physical device driver
   result = User::LoadPhysicalDevice(PDD_NAME);
   if (result != KErrNone && result != KErrAlreadyExists) User::Leave(result);
   
               
   // Similarly for the Logical device driver
   result = User::LoadLogicalDevice(LDD_NAME);
   if (result != KErrNone && result != KErrAlreadyExists) User::Leave(result);
   
   
   // Start comm server if necessary
   result = StartC32();
   if (result != KErrNone && result != KErrAlreadyExists) User::Leave(result);

   console->Printf (KMessage6);
   RCommServ server;
   User::LeaveIfError (server.Connect ());

   // Load the CSY module
   // Symbian OS will automatically search \System\Libs
   // on all drives starting from C:
// Load the comm module
   result = server.LoadCommModule(_L("BTCOMM"));
   if(result==-1)
   {
         console->Printf(_L("result=%d"),result);
         User::LeaveIfError(result);
   } 
   //---------------------------------------------------------------
   
               
   result = commPort.Open(server,_L("BTCOMM::1"),ECommExclusive);
   if(result==-1)
   {
         console->Printf(_L("result Open=%d"),result);
         User::LeaveIfError(result);
   } 
   
   TCommConfig cBuf;
   TCommConfigV01 &c=cBuf();
   
  // Get the current configuration
   commPort.Config(cBuf);
   
  // Set new settings
   c.iFifo = EFifoEnable;
   c.iRate = EBps19200;
   c.iHandshake = KConfigObeyCTS;
   c.iTerminatorCount = 0;
   c.iDataBits = EData8;
   c.iParity = EParityNone;
   c.iStopBits = EStop1;
   
  // Write the settings out
   commPort.SetConfig(cBuf);
     
Tue, 2007-04-10 10:40
Joined: 2007-02-28
Forum posts: 12
Re: Comunication serial port help
When does your program crash ?

It seems that you start the communication server 2 times ...

What is the content of the PDD and LDD constants ?

The commmodule for serial over bluetooth isn't RFCOMM instead of BTCOMM ?

And at last you should try to open the port BTCOMM::0

regards
Mon, 2007-04-23 15:23
Joined: 2007-04-23
Forum posts: 1
Re: Comunication serial port help
I also tried the above code but getting -21 on
err = iCommPort.Open (iCommServer, KPortName1, ECommExclusive); // step 6

But instead of trying for USB(ECACM), if I am opening port for IR(IrCOMM) and BT(BTCOMM), its working fine.

Its also giving err == -5 in the case of RS232( ECUART) Sad
  • Login to reply to this topic.