Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. problem in connection to serial port

problem in connection to serial port

Scheduled Pinned Locked Moved C / C++ / MFC
help
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    manju23reddy
    wrote on last edited by
    #1

    hi i have written the following code to receive data from mobile using bluetooth through serial communication. but it is not working #include <stdio.h> #include <conio.h> #include <windows.h> #include "stdafx.h" #include "bluetoothConnection.h" bool BluetoothConnection::openPort(char *portNum) { if (portNum != NULL) { hcomm = CreateFile((LPCWSTR)portNum, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, NULL, 0); if (hcomm == INVALID_HANDLE_VALUE) { return false; } else { return true; } } else { return false; } } bool BluetoothConnection::initPort() { dcb.fOutxCtsFlow = false; dcb.fOutxDsrFlow = false; dcb.fDtrControl = DTR_CONTROL_DISABLE; dcb.fOutX = false; dcb.fInX = false; dcb.fRtsControl = RTS_CONTROL_DISABLE; //time settings timeouts.ReadIntervalTimeout = 20; timeouts.ReadTotalTimeoutMultiplier = 10; timeouts.ReadTotalTimeoutConstant = 100; if (!SetCommTimeouts(hcomm, &timeouts)) { return false; } else { return true; } } void BluetoothConnection::ReadPort() { memset(chRead, '\x91', 250); Sleep(1000L); ReadFile(hcomm, chRead, 250, &dwRead, NULL); } void BluetoothConnection::display() { printf("%s\n", chRead); } int main() { BluetoothConnection *bth1 = new BluetoothConnection(); if (bth1 != NULL) { if (bth1->openPort("COM4")) { if (bth1->initPort()) { bth1->ReadPort(); printf("the data from com4 is ....\n"); bth1->display(); } else { printf("fail in init\n"); } } else { printf("unable to connect\n"); } } else { printf("unable to connect failed in initial state\n"); } Sleep(1000L); return 0; } its failing in CreateFile function coz its returns 0xffffff.. can this code be used for bluetooth coz i found such code for serial port comm and infrared. is there any configurations between mobile and pc before running this application if there please provide me the steps..

    C 1 Reply Last reply
    0
    • M manju23reddy

      hi i have written the following code to receive data from mobile using bluetooth through serial communication. but it is not working #include <stdio.h> #include <conio.h> #include <windows.h> #include "stdafx.h" #include "bluetoothConnection.h" bool BluetoothConnection::openPort(char *portNum) { if (portNum != NULL) { hcomm = CreateFile((LPCWSTR)portNum, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, NULL, 0); if (hcomm == INVALID_HANDLE_VALUE) { return false; } else { return true; } } else { return false; } } bool BluetoothConnection::initPort() { dcb.fOutxCtsFlow = false; dcb.fOutxDsrFlow = false; dcb.fDtrControl = DTR_CONTROL_DISABLE; dcb.fOutX = false; dcb.fInX = false; dcb.fRtsControl = RTS_CONTROL_DISABLE; //time settings timeouts.ReadIntervalTimeout = 20; timeouts.ReadTotalTimeoutMultiplier = 10; timeouts.ReadTotalTimeoutConstant = 100; if (!SetCommTimeouts(hcomm, &timeouts)) { return false; } else { return true; } } void BluetoothConnection::ReadPort() { memset(chRead, '\x91', 250); Sleep(1000L); ReadFile(hcomm, chRead, 250, &dwRead, NULL); } void BluetoothConnection::display() { printf("%s\n", chRead); } int main() { BluetoothConnection *bth1 = new BluetoothConnection(); if (bth1 != NULL) { if (bth1->openPort("COM4")) { if (bth1->initPort()) { bth1->ReadPort(); printf("the data from com4 is ....\n"); bth1->display(); } else { printf("fail in init\n"); } } else { printf("unable to connect\n"); } } else { printf("unable to connect failed in initial state\n"); } Sleep(1000L); return 0; } its failing in CreateFile function coz its returns 0xffffff.. can this code be used for bluetooth coz i found such code for serial port comm and infrared. is there any configurations between mobile and pc before running this application if there please provide me the steps..

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      First, are you sure the COM4 port exist ? Are you developping for winCE ? If yes, then if I remember well, you have to append a ':' after the port name (thus "COM4:"). Not sure anymore, try it and tell me if it works.

      Cédric Moonen Software developer
      Charting control [v1.5] OpenGL game tutorial in C++

      M 1 Reply Last reply
      0
      • C Cedric Moonen

        First, are you sure the COM4 port exist ? Are you developping for winCE ? If yes, then if I remember well, you have to append a ':' after the port name (thus "COM4:"). Not sure anymore, try it and tell me if it works.

        Cédric Moonen Software developer
        Charting control [v1.5] OpenGL game tutorial in C++

        M Offline
        M Offline
        manju23reddy
        wrote on last edited by
        #3

        iam not using for windows CE its PC to mobile VC++ 2005 and appending of : has not solved, plz give me some soln..

        C 1 Reply Last reply
        0
        • M manju23reddy

          iam not using for windows CE its PC to mobile VC++ 2005 and appending of : has not solved, plz give me some soln..

          C Offline
          C Offline
          Cedric Moonen
          wrote on last edited by
          #4

          Does this port exist at least ? Did you try to open it with hyperterminal ?

          Cédric Moonen Software developer
          Charting control [v1.5] OpenGL game tutorial in C++

          M 1 Reply Last reply
          0
          • C Cedric Moonen

            Does this port exist at least ? Did you try to open it with hyperterminal ?

            Cédric Moonen Software developer
            Charting control [v1.5] OpenGL game tutorial in C++

            M Offline
            M Offline
            manju23reddy
            wrote on last edited by
            #5

            no i am a begginer and i used AT command to test a while long back but now i dont remember it plz.. which is the command to type in and check for the status... and one thing when i open hyperterminal and select com4 and try to type some thing then my mobile disconnects the bluetooth connection...

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups