Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Writing to Serial ports

Writing to Serial ports

Writing to Serial ports


I am currently doing a 10 week project which involves creating a package which will allow a lecturer to transmit an SMS via GSm modem to a group of students.  I am working on the development on my VISTA laptop using code::blocks 8.02 to edit and compile in C.

I'm at the stage where I just want to write a simple (ha) program to send a text message to the modem for transmission.  I want to use the AT commands that are standard and send them out over my serial port to the modem along with the sms text.

My problem is my mind is boggled with all the info I've found, I can't see much on using AT commands in C but I've found loads on serial port comms using "outport" command but then I've found contradictory stuff saying this is all old hat nowadays.  My C is begginer at best so if anyone knows of the commands and structure I should be looking at to acheive this I'd be greatful for the helping hand.

RE: Writing to Serial ports

Hi Dandy1903,

Sorry, don't know anything about Code::Blocks, but you could use Win32 API calls to talk to the serial ports. The CreateFile(), ReadFile() and WriteFile() functions would be the primary ones. Is the program intended to be GUI or console?

Good Luck,


RE: Writing to Serial ports

There is no standard (portable) way to deal with serial port. But for Windows you can use these API functions:


For opening, reading and writing to serial port, use same API as for dealing with files: CreateFile(Ex), ReadFile(Ex), WriteFile(Ex).


You only need to feed correct AT commands to port and then to analyze modem response.

RE: Writing to Serial ports

gregha and monkhandle,
Thanks both, I'll look through the API stuff today.  I think the final product will likely be console driven.
Before i trawl through it all can i confirm that these API functions can be called from a c Program?  Do you know which header file I need to include to cover these?
I may find this out as i'm reading the provided links.

RE: Writing to Serial ports

It is written on bottom of those MSDN pages:

Declared in WinBase.h; include Windows.h.

Use Kernel32.lib.

Requires Kernel32.dll.

Windows compilers usually link kernel.lib by default so you only have to #include <windows.h> and start using those APIs...

RE: Writing to Serial ports

Thanks Monk, I'll have a bash at putting something together today, see what happens (or doesn't).....I may be back!

RE: Writing to Serial ports

Hi Dandy1903,

In addition to the references suggested by monkhandle, you may want to review the Communications reference section on MSDN at


You might need to use some of the fuctions described there, such as SetCommState(), if you need to change the comm port transmission speed or format.

Good Luck,


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close