Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

comm port - Urgent

Status
Not open for further replies.

deepsheep

Programmer
Sep 13, 2002
154
CA
I don't know alot about c++ builder and I'm maintianing a 'Legacy' app, so please bear with me.
I'm reading binary data from a mscomm port. It seems if I read the data as a string into an AnsiString, it is cut off at the first null. If I read it into a OleVariant, I can't seem to get the data out. I want to be able to concatenate the new data to a unsigned char array containing any unprocessed data.
Here is the last version that I tried:
OleVariant BoxDataIn;
BoxDataIn=BoxPort->Input.ChangeType(varString) ;
BoxDataIn.ChangeType(varArray);
memcpy(tempbuf, BoxDataIn.VArray, size);
memcpy(drtBuf, tempbuf, size);

I don't have any preference to what I need to do to get the end result, I just know that everything I've tried hasn't worked. It's probably a really easy solution too.
 
This really isn't a C++ Builder issue, but a general programming concept issue. Of course if you read the data into an AnsiString it will be cut off at the first null, because AnsiStrings are null terminated. That doesn't mean that the data isn't in the string, it just includes a null character.

All you really need to do is read the data from the port directly into your buffer tempbuf (or even directly into drtBuf & avoid the memcpy). Just keep track of how many bytes of data you read into the buffer, then process it based on the amount of data read rather than as a string. So, if you read 50 bytes of data from the port into your buffer, you memcpy 50 bytes of data.

If this doesn't answer your question, post a followup.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top