NOVICE3 0 Newbie Poster

I am attempting to communicate with a FTDI module (UM245R). I can get to the point where the actual command to send a byte is made and then get a runtime error that says "Attempted to read or write protected memory." The code at this point is:

byte commandByte = baData[dataPointer];
ftStatus = FT_Write(m_hPort, commandByte, ref bytesToWrite);

The address of "m_hPort" was previously obtained earlier by the instruction:

ftStatus = FT_Open(0, ref m_hPort);

and the device opened, returning a value of 0 for ftStatus (which is correct).

The program compiles OK, but either in the DEBUG mode or actually running the program, I get the above error message.
What am I doing wrong?
NOVICE3

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.