Search

Technical Discussion Group Forum

This forum is provided for user discussion. While Beacon EmbeddedWorks support staff and engineers participate, Beacon EmbeddedWorks does not guarantee the accuracy of all information within in the Technical Discussion Group (TDG).

The "Articles" forums provide brief Articles written by Beacon EmbeddedWorks engineers that address the most frequently asked technical questions.

To receive email notifications when updates are posted for a Beacon EmbeddedWorks product download, please subscribe to the TDG Forum of interest.

TDG Forum

PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 20 Jul 2004 02:47 PM by  pmains@aquameasure.com
ERROR_ACCESS_DENIED when writing to COM3
 2 Replies
Sort:
You are not authorized to post a reply.
Author Messages
pmains@aquameasure.com
New Member
New Member
Posts:


--
16 Jul 2004 03:53 PM
    I'm getting error 5 (ERROR_ACCESS_DENIED) when I try to write to the serial port (COM3:). There's no problem getting using CreateFile, or setting up the DCB and CTO. I can read from the port just fine having opened the port as GENERIC_READ | GENERIC_WRITE.

    I was able to read from the serial port before I modularized my program into about 4 .cpp files (and a bunch of .h files). I'm at a loss at to what exactly has changed, or what might be screwing up my ability to read from COM3:.
    Andreas
    New Member
    New Member
    Posts:


    --
    19 Jul 2004 10:26 AM
    If you are getting access denied error, chances are you have already opened the port, but then again I thought your CreateFile would fail. Double check your code to see if you are trying to open the file handle multiple times, and also make sure that your serial port file handle is still in scope and valid after splitting the source code up into files.

    Below are pieces of a class I use for echoing serial data sent to the dev. board (minus my actual data handling.) Check to see if this gives you some hints.

    the handleSerialData() function is supposed to be called repeatedly, polling for serial data.

    If the code below leaves out something critical let me know and I'll send more info.

    merry programming,

    Andreas


    class CSerialComms
    {
    public:
    char m_serialString[20];
    int m_serialRxCount;
    int handleSerialData(CTargetDevice *chipCorder);
    DCB m_dcb;
    HANDLE m_hComPort;
    CSerialComms();
    virtual ~CSerialComms();
    };

    CSerialComms::CSerialComms()
    {
    m_hComPort = CreateFile(TEXT("COM3:"),
    GENERIC_READ | GENERIC_WRITE, 0, NULL,
    OPEN_EXISTING, 0, NULL);
    m_dcb.DCBlength = sizeof(m_dcb);
    GetCommState(m_hComPort, &m_dcb);
    m_dcb.BaudRate = 115200;
    m_dcb.fParity= FALSE;
    m_dcb.fNull= FALSE;
    m_dcb.StopBits = ONESTOPBIT;
    m_dcb.Parity = NOPARITY;
    m_dcb.ByteSize = 8;
    SetCommState(m_hComPort, &m_dcb);

    m_serialRxCount = 0;
    }

    CSerialComms::~CSerialComms()
    {
    CloseHandle(m_hComPort);
    }

    int CSerialComms::handleSerialData(CTargetDevice *chipCorder)
    {
    BYTE charTX;
    DWORD countBytes;
    int rxCount;

    rxCount = ReadFile(m_hComPort, &charTX, 1, &countBytes, NULL);
    if(countBytes != 0)
    {
    // echo serial data
    rxCount = WriteFile(m_hComPort, &charTX, 1, &countBytes, NULL);
    }
    return 0;
    }
    pmains@aquameasure.com
    New Member
    New Member
    Posts:


    --
    20 Jul 2004 02:47 PM
    I found the problem. Just a matter of crossed wires, which confused the serial port.

    Thanks, Andreas.
    You are not authorized to post a reply.