?
Solved

Write HEX DATA to serial port on the PC

Posted on 2003-02-24
7
Medium Priority
?
677 Views
Last Modified: 2013-11-13
I am just getting started with serial port via Win32 API and I am stuck on the following:

I need to write Hex data to the serial port. So far I can write ASCII characters using:

WriteFile(hComm, lpBuf, dwToWrite, &dwWritten, &osWrite)

but 'lpbuf' barks at me if I try anything else saying that it is expecting a "const void"

Hopefully this is cake for you experienced coders out there... I am working with C++ Builder6.
0
Comment
Question by:eceman
[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
  • 5
  • 2
7 Comments
 
LVL 3

Expert Comment

by:jlsjls
ID: 8015609
Just cast the pointer lpBuf to "const void"
WriteFile(hComm,(const void)lpBuf,dwToWrite,&dwWritten,&osWrite);
0
 

Author Comment

by:eceman
ID: 8016083
Did not work jlsjls...but I may not be following what you suggested.
0
 

Author Comment

by:eceman
ID: 8016100
To be more specific, if I do something like this:
WriteFile(hComm, 15 , 2 ,&iBytesWritten,NULL);

I get these errors:

[C++ Error] Unit1.cpp(59): E2034 Cannot convert 'int' to 'const void *'

[C++ Error] Unit1.cpp(59): E2342 Type mismatch in parameter 'lpBuffer' (wanted 'const void *', got 'int')
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 3

Accepted Solution

by:
jlsjls earned 240 total points
ID: 8016144
I suppose you intend to write 0x15 to the serial port (hComm).
You can do it as follow :
char buffer[1];
buffer[0] = 0x15;
WriteFile(hComm,(const void*)buffer,1,&iBytesWritten,NULL);
0
 

Author Comment

by:eceman
ID: 8024039
That works! Thanks for taking the time to answer my qwestion jlsjls. I increased the points to 100 now.
How would you convert a user input like a string to something that stores the 0x15? If I try to do something like this:

buffer[1] = Edit1->Text.c_str();

I get this error:

[C++ Error] Unit1.cpp(69): E2034 Cannot convert 'char *' to 'char'

The basic idea is to be able to type a Hex number into an Edit box on the main form to provide access to different commands. Something like a StrToHex would work, I think, but I can only find a HexToStr function :(
0
 

Author Comment

by:eceman
ID: 8029968
Help jlsjls !!!
0
 

Author Comment

by:eceman
ID: 8040412
He did not follow up to the question.... :(
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This is about my first experience with programming Arduino.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Progress

777 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