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!

Writing to Serial ports 1

Status
Not open for further replies.

Dandy1903

Programmer
Apr 7, 2008
3
GB
Hi,

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.
 
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,

Greg
 
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.
 
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.
Cheers
 
It is written on bottom of those MSDN pages:

Header
--------
Declared in WinBase.h; include Windows.h.

Library
-------
Use Kernel32.lib.

DLL
----
Requires Kernel32.dll.

Windows compilers usually link kernel.lib by default so you only have to #include <windows.h> and start using those APIs...
 
Thanks Monk, I'll have a bash at putting something together today, see what happens (or doesn't).....I may be back!
 
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,

Greg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top