Thread: Serial Programming

  1. #1
    Registered User
    Join Date
    Feb 2003

    Serial Programming

    I am trying to figure out how to program for a Serial port. I am not wanting to send and receive data. I have a device(footpedal for audio playback) that changes pin status. I just need to monitor for pin status changes and act according to that. The programs that I have written that need this functionality are written in C#, but I would be happy to figure this out in Visual C++. The closest I could get to accomplishing this is using a SetCommMask function to monitor the Com Port. It actually works great and detects two of the three actions that the footpedal gives. My footpedal commands are associated with the pins as follows:
    Rewind - Pin 1(Carrier Detect)
    Play - Pin 6(Data Set Ready)
    Fast Forward - Pin 8(Clear to Send)

    The SetCommMask function only allows me to monitor DSR and CTS. To my knowledge it will not allow me to monitor the Carrier Detect Pin. Please any suggestions??????????????????????????


  2. #2
    Registered User
    Join Date
    Feb 2003

    I have found out that RLSD(Receive Line Signal Detect) is the same as CD(Carrier Detect). The problem now is that when I set off the DSR pin, it sets off the RLSD routine and the DSR routine. Here is a code snippet:

    Play = DSR pin
    Rewind = CD or RLSD pin
    FFwd = CTS pin

      // Specify a set of events to be monitored for the port.
      SetCommMask (hPort, EV_CTS | EV_DSR | EV_RLSD
      while (hPort != INVALID_HANDLE_VALUE) 
        // Wait for an event to occur for the port.
        WaitCommEvent (hPort, &dwCommModemStatus, 0);
        // Re-specify the set of events to be monitored for the port.
        SetCommMask (hPort, EV_CTS | EV_DSR | EV_RLSD
        // Retrieve modem control-register values.
        if (dwCommModemStatus & EV_DSR)
           MessageBox(NULL,"PLAY has been pressed on the footpedal","PLAY",MB_OK);
        if (dwCommModemStatus & EV_RLSD)
           MessageBox(NULL,"REWIND has been pressed on the footpedal","REWIND",MB_OK);
        if (dwCommModemStatus & EV_CTS)
           MessageBox(NULL,"FAST FORWARD has been pressed on the footpedal","FFORWARD",MB_OK);
        GetCommModemStatus (hPort, &dwCommModemStatus);
    Everything works correctly except for when I hit play. When I hit play, The first messagebox and the second messagebox both display. Anyone know why??????????????????????????


    PS Why would the code loop twice every time I hit one of the controls once?????????????? ex. I hit Rewind = Rewind messagebox pops up twice.
    Last edited by gvector1; 07-15-2003 at 03:26 PM.

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Perhaps your bit masks for your EV_ constants are incorrect thus causing two of them to be true at once.

    The other problem probably has to do with timing. It's possible that the device does not reset until a certain time limit has passed. For instance after resetting a DSP you must wait like 3 milliseconds or something before you can send any commands to it.

    Maybe you need to reset the port or the device after each read - similar to resetting a DSP on a sound card. The REWIND bit pattern might reside in the port until you reset the device after which the bit pattern would be cleared.

    Just guesses.

  4. #4
    Registered User
    Join Date
    May 2003
    You may have a lot of problems with a serial port -- as the name implies, it's made to receive data serially -- one bit at a time until a whole frame has been read, then present the whole frame at once. And by using control signals, you'll probably initiate all kinds of handshaking.

    A parallel port would be much easier to poll the instantaneous status of one or more pins.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. serial port to poll on request
    By infineonintern in forum C++ Programming
    Replies: 2
    Last Post: 06-11-2009, 06:52 AM
  2. Lame null append cause buffer to crash
    By cmoo in forum C Programming
    Replies: 8
    Last Post: 12-29-2008, 03:27 AM
  3. Music Programming - Serial Matrix Display
    By CrazyHorse in forum C Programming
    Replies: 1
    Last Post: 11-12-2007, 04:16 PM
  4. Please help with serial communication problem - Long
    By spdylude in forum Windows Programming
    Replies: 3
    Last Post: 04-06-2005, 09:41 AM
  5. DOS, Serial, and Touch Screen
    By jon_nc17 in forum A Brief History of
    Replies: 0
    Last Post: 01-08-2003, 04:59 PM