Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Eisen

Serial port woes

This topic is 6419 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I need to send twelve byte instruction packets out of the serial port in the back of my computer and into a waiting peripheral that will send back an equal sized acknowledge packet. Would someone be kind enough to tell me how to access the port? I need: The name of the functions that read and write data to the serial port. The function prototypes and where they are located. I''m assuming one of the standard library files has these functions. Instructions on how to use these functions properly. or Directions on where to get this information. I''ve consulted my teachers, text, and my compiler''s help directory to no avail. I realize this is a lengthy and time consuming request but I would be much obliged if someone would take the time to help me out. If any part of my request is unclear or you have any questions about what I''m trying to do, feel free to ask. Thanks in advance, Andrew

Share this post


Link to post
Share on other sites
Advertisement
It would be rather handy if you told us what operating system you were using.

If it''s windows, use CreateFile, look it up in the MSDN and it gives examples of writing to a com port.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
My apologies.

OS - Windows98
Compiler - VC++

Share this post


Link to post
Share on other sites
Look in the MSDN
Platform SDK->WIndows Base Services->Files and IO->Communications

CreateFile, CloseHandle, ReadFile, WriteFile and so on..

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
remember the dos days? like outp or something? darn windows api, ugh.

Share this post


Link to post
Share on other sites
I''ve had no problems using outp in windows, but the headers in my windows compiler don''t have it. I just stold a chunk of code and put it in a header.

extern __inline__ unsigned char
inp (unsigned short _port)
{
unsigned char rv;
__asm__ __volatile__ ("inb %1, %0"
: "=a" (rv)
: "dN" (_port));
return rv;
}

extern __inline__ void
outp (unsigned short _port, unsigned char _data)
{
__asm__ __volatile__ ("outb %1, %0"
:
: "dN" (_port),
"a" (_data));
}

The address of LPT1 is 0x378.

I hope that helps.

Share this post


Link to post
Share on other sites
First, I appreciate the help I've received thus far.

smart_idiot,

Your suggestion seems the best as far as ease of implementation goes. However, are you sure that the header code is correct? Compiling as is, I get a ridiculous syntax error saying I should put a ';' before the 'unsigned char' in the first function declaration and an unexpected end of file error.

That aside, I looked at the code and am a little confused. Correct me if I'm wrong but aren't those keywords written '__asm' and '__inline' as opposed to '__asm__' and '__inline__'? If those aren't keywords, then where are they defined?

Lastly, isn't LPT1 the parallel port? I need the address of COM1 the serial port. Hopefully the addresses are universal. If not, I need a port address querying function.


Anyone's thoughts or input on the matter is welcome and appreciated,

Andrew


Edited by - Eisen on January 16, 2001 2:16:44 PM

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Try this link for a serialport class from codeguru.com
http://codeguru.earthweb.com/network/serialport.shtml
I have used this code to interface with a bunch of different
devices such as wireless modems, gps recievers, single board
computers and robotic control circuitry. This should be very straightforward to port into your app. I would suggest using an off the shelf serial component such as greenleaf''s COMMX or something like that as they are already debugged and ready to go.
For something simple like you are talking about, you may want
to write your own serial interrupt routines for writing and
reading from a particular port. I could send you some code
examples to do this in WIN/98 if you need.

Kris Herrera
Computer Engineer
Sparton Technology Inc.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!