Solved

Getting bytes from a memory that's dymanicly allocated.

Posted on 1997-07-18
11
177 Views
Last Modified: 2010-04-06
Hi!
Here is what I'm working with:
Buffpointer: Pointer;

GetMem( BuffPointer, 2048 );
ReadFile(hComm, BuffPointer^, 10, NbrRead, @overlappedRead)

The ReadFile is reading from the serial communications-port with a baudrate at 115200, and I know that the other computer is sending bytes containing information from an A/D-converter. Therefore I want to get the value on every byte(0 - 255) so I then can use it to draw a curve on the screen.

 If I do PChar(BuffPointer) the result is in Char and the information that I want is lost. Maybe You have another idea on how I should do?
Thanks!

Regards Linda.
0
Comment
Question by:Lillan061397
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
11 Comments
 

Author Comment

by:Lillan061397
ID: 1339137
Edited text of question
0
 

Author Comment

by:Lillan061397
ID: 1339138
Edited text of question
0
 
LVL 2

Expert Comment

by:icampbe1
ID: 1339139
Hi Linda,

Maybe if you tell more about your task.  Are you trying to read the file to get character pairs and then use these pairs to create a Unicode (Like Swedish) string ??

 Also, when you say holes in the ASCII chart, I assume you mean the values above 127.

Ian C.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:icampbe1
ID: 1339140
Most of the conversion routines (at least in D3) do this internally already.
0
 

Author Comment

by:Lillan061397
ID: 1339141
Edited text of question
0
 

Author Comment

by:Lillan061397
ID: 1339142
Edited text of question
0
 
LVL 2

Accepted Solution

by:
icampbe1 earned 50 total points
ID: 1339143
Use a typed pointer.

VAR
    BuffPointer: ^BYTE;

Type BYTE is just 8 bits of binary storage.  It does not have a Char personality.  Also, make sure to set up the Com port for binary transfers.

Ian C.

0
 

Author Comment

by:Lillan061397
ID: 1339144
Hi Ian!

I hope the editing of the question is better. If a bytes value is 97 I want to be able to get 97 as an integer and not an 'a'. I'm using this to draw a curve. Is this possible? I hope so!!

Regards Linda.
0
 
LVL 2

Expert Comment

by:icampbe1
ID: 1339145
Yes, use BYTE not CHAR.  A type of BYTE doesn't know about 'a' or 'b'.  It just is 8 binary bits of storage.  If you want it as a signed integer, use SHORTINT.

BYTE and SHORTINT are the 8 bit equivalents of WORD and INTEGER.

Does this help?

Ian C.
0
 

Author Comment

by:Lillan061397
ID: 1339146
Hi again!

I can only get the first byte! How do I do to get the second and so on? Otherwise it's working.

Regards
Linda.
0
 

Author Comment

by:Lillan061397
ID: 1339147
Hi Ian!

After about 10 sec I figured out how to read all the bytes!

Thanks for your help!

Linda.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Making delphi communicate with a c# service 16 124
Delphi Yen format 3 62
Need Help Delphi 2010 CheckBox1 Stored value in memo 13 81
How to convert memory stream to PDF file 6 188
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question