RS232 in Win2k using Visual C++

J

Thread Starter

jbf

Hello.

I am working with hardware that receives its commands serially over fiber. I have a bunch of RS232-to-fiber adapters, and would like to write some C/C++ code to send data over a serial port in the particular protocol I am using.

I have had a tough time finding a straight-forward article or resource on this topic.

I should mention I am using Visual C++ 6.0, running on Windows 2000. Is this version of C++ new enough?

It would seem to me there would exist some library to facilitate this function; I just don't know where to look. Any help would be greatly appreciated. Thank you.
 
Questions like this really make me feel my age.

It used to be that when you bought computer controlled hardware, you got sample code, at least in basic, and probably C. Often you got a floppy (what's a floppy?)
with driver software sources to add to your projects.

Talk to the vendor. If they don't have this, see if they have some customers that are doing a similar thing and talk to them (assuming they're not competitors).

What type of hardware is it? There might be appropriate newsgroups. If you have no newsreader, use google groups.

Otherwise, you're in the next best place (sometimes the best) for information right here on the automation list.

Oh, and yes, VC++ V. 6.0 is more than sufficient.

Rufus
 
Hi

I had to connect to a Forte system using RS-232 and useing C++ 6.0. I found the book Serial Communications developers guide (Mark Nelson) ideal. In short you treat the com port as a file, and you read and write to the file. I do suggest that you use a seperate thread for the com. port part of your program.

Hope this helps.
Dan Brown
 
Hello.

You must look for stuff relating to I/O streams and Asynchronous I/O. You write or read data from a serial port just as you are doing I/O with an ordinary file; just that you have to define COM1 or COM2 in your call to CreateFile() with particular settings of other parameters that you must look forward in a related text.
 
Hello,

Win2k/NT/98 etc all have a comman API which is used to program the serial port. It is called the Win32 Comm API. I must admit, its not so easy to get started with this straight away. The API is difficult to use.

There are several websites that provide, good resources on programming in VC++ 6.0 for the Comm API.

There are commercial libraries available that provide easy to use functions for programming the serial port. These libs hide the intricacies of the Win32 Comm API and provide easy to use functions like open_port(), read(), write().

For more details and help on programming serial ports in VC++, send me an email at [email protected].

regards
 
Hi

I used V C++ to use the serial port to comunicate with a Forte moisture measurment system. I used a book called Serial Communications developers's guide by Mark Nelson (M & T Books). You can contact me if you need any more info.
 
Hello Punita

Thank u for the kind suggestion made regarding the serial interfacing.

Could u please give me the details of the Commercial libraries u said about for the serial interfacing with VC++?

Thanking You

Gopi
 
hello,

I would like to ask on how to use VISUAL C++ to communicate with the RS-232 of the computer? I am trying to write a code for my RFID (from Texas instruement) and was planning to use the RS232 as my communication port from the host computer to the "reader".A sample program on how to access the serial port as an I/O would be a lot of help. Thank you very much.
 
// COM32.CPP
// -----------
// WIN32 communications library interface


hCom = ::Open_Comport (1, 9600);

::Close_Comport (hCom);

::Read_Comport (hCom, &BytesRead, BufferSize, Buffer);

::Write_Comport (hCom, buffer.GetLength(), buffer);
 
Hi, do you still have the code for communicating with the serial port? I currently need the pc to communicate with the serial port but I also can hardly find any book or article on this topic. If you still have the code, do you mind to tell me? Really thank you very much!
 
Top