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. Serial project in Visual C++ problem

Serial project in Visual C++ problem

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpcomdebuggingquestion
2 Posts 1 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.
  • R Offline
    R Offline
    rmnowick
    wrote on last edited by
    #1

    Hello, I am in the process of implementing a serial interface in my existing Visual C++ project by using the CSerialWnd functions as described in great detail in Ramon de Klein's contributed source code: http://www.codeproject.com/system/serial.asp I am able to perform the CSerialWnd::Open function on the COM1 port, and then expect to receive window notifications back in my main windows notification handler routine. I'm not a veteran Windows programmer so I may not have all the terminology exactly right. The call that I use to set that up is as follows: lLastError = serial.Open ("COM1", hdlg, WM_NULL, 0, 2048, 2048); if (lLastError != ERROR_SUCCESS) here(0,"Error opening serial port"); lLastError = serial.Setup(CSerial::EBaud38400,CSerial::EData8,CSerial::EParNone,CSerial::EStop1); if (lLastError != ERROR_SUCCESS) here(0,"Error opening serial port"); lLastError = serial.SetupHandshaking(CSerial::EHandshakeSoftware); if (lLastError != ERROR_SUCCESS) here(0,"Error opening serial port"); lLastError = serial.SetupReadTimeouts(CSerial::EReadTimeoutNonblocking); if (lLastError != ERROR_SUCCESS) here(0,"Error opening serial port"); I have run this code in debug and verify that I can indeed open the COM1 port. When I had another application using the port the code would detect the error. Passing in WM_NULL as the 3rd parameter in the Open should cause Windows to use the default notification message number of CSerialWnd::mg_nDefaultComMsg. When I looked through the include files I never found an exact definition of what this was. That was how I intended to determine which messages in my notification handler came from the serial interface thread that gets created by the Open. I decided to step through the code and came across this section where it gets assigned: long lLastError = CSerialEx::Open(lpszDevice,dwInQueue,dwOutQueue); if (lLastError != ERROR_SUCCESS) return lLastError; // Save the window handle, notification message and user message m_hwndDest = hwndDest; m_nComMsg = nComMsg?nComMsg:mg_nDefaultComMsg; m_lParam = lParam; // Start the listener thread lLastError = StartListener(); When I looked at m_nComMsg it has a value of 49839 after it gets set. The problem is, when I look at all the messages coming into my notification handler I don't have any that are 49839. There are lots of messages coming in that I believe are the result of my sending a couple "hello world" messages into the Windows program. But they have message ID's of like 307,309,312.

    R 1 Reply Last reply
    0
    • R rmnowick

      Hello, I am in the process of implementing a serial interface in my existing Visual C++ project by using the CSerialWnd functions as described in great detail in Ramon de Klein's contributed source code: http://www.codeproject.com/system/serial.asp I am able to perform the CSerialWnd::Open function on the COM1 port, and then expect to receive window notifications back in my main windows notification handler routine. I'm not a veteran Windows programmer so I may not have all the terminology exactly right. The call that I use to set that up is as follows: lLastError = serial.Open ("COM1", hdlg, WM_NULL, 0, 2048, 2048); if (lLastError != ERROR_SUCCESS) here(0,"Error opening serial port"); lLastError = serial.Setup(CSerial::EBaud38400,CSerial::EData8,CSerial::EParNone,CSerial::EStop1); if (lLastError != ERROR_SUCCESS) here(0,"Error opening serial port"); lLastError = serial.SetupHandshaking(CSerial::EHandshakeSoftware); if (lLastError != ERROR_SUCCESS) here(0,"Error opening serial port"); lLastError = serial.SetupReadTimeouts(CSerial::EReadTimeoutNonblocking); if (lLastError != ERROR_SUCCESS) here(0,"Error opening serial port"); I have run this code in debug and verify that I can indeed open the COM1 port. When I had another application using the port the code would detect the error. Passing in WM_NULL as the 3rd parameter in the Open should cause Windows to use the default notification message number of CSerialWnd::mg_nDefaultComMsg. When I looked through the include files I never found an exact definition of what this was. That was how I intended to determine which messages in my notification handler came from the serial interface thread that gets created by the Open. I decided to step through the code and came across this section where it gets assigned: long lLastError = CSerialEx::Open(lpszDevice,dwInQueue,dwOutQueue); if (lLastError != ERROR_SUCCESS) return lLastError; // Save the window handle, notification message and user message m_hwndDest = hwndDest; m_nComMsg = nComMsg?nComMsg:mg_nDefaultComMsg; m_lParam = lParam; // Start the listener thread lLastError = StartListener(); When I looked at m_nComMsg it has a value of 49839 after it gets set. The problem is, when I look at all the messages coming into my notification handler I don't have any that are 49839. There are lots of messages coming in that I believe are the result of my sending a couple "hello world" messages into the Windows program. But they have message ID's of like 307,309,312.

      R Offline
      R Offline
      rmnowick
      wrote on last edited by
      #2

      Just wanted to let you all know that I figured out the problem in case someone comes upon this thread in the future. The problem that I was having is that my declaration: CSerialWnd serial; Was located in the InitDialogProc routine which would get called from the main dialog processing routine upon receipt of the WM_INITDIALOG notification. I moved that declaration to be global and I started receiving serial notifications in the main dialog processing routine. Now I will be able to write the code that handles the serial data stream. Good Luck, Robert

      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