Source code for Serial communication in VC++

T
Sorry I don't have any advice (or source code).

I'm actually looking for some myself, please let me know if you have any luck !
 
Hello,

You can check comm sample (TTY). It is described in Samples\SDK Samples\WinBase Samples\Serial Sample in MSDN help contents.
It uses File functions to manipulate COM port.

Cheers,
Rado.
 
A

Anand Sharma

Dear Mr Narang, I have code written in pure C that will enable you to communicate to the pc using the com ports. If you are sure you can port the code to VC++ then i can send you the codes. Anand Reliance Petroleum Ltd.
 
R
> I am looking for sample Source code for Serial communication in VC++
> for learning purposes .Can somebody help me.

Use of serial ports is basically orientated around configuring the serial ports for the right behaviour, and this varies with the platform more than the C language, the basic techniques are the
same whatever variant you are using.

Also, platforms are **similiar**. Reading and writing to a serial port is like reading and writing from a sequential file, however, in order
to modify parameters you will need to access a data structure where factors such as baud rate and handshaking characteristics are defined.

As there are a lot of parameters, many of which will not be of interest to you, the normal way is to 'create' a file, get a default data structure, and then modify the parameters that are of interest to you before opening it.

The actual details of the parameters is the platform dependent bit, as it depends on facilities offered, for example the data structure is capable of accepting values that cannot be implemented by the underlying UART, whilst the platform itself may offer more or less
built in control features.

For example, just about all platforms will offer rudimentry RTS/CTS or XON/XOFF handshaking, but may offer different degrees of control over timeouts etc. Some features, such as the extensive
canonical mode controls offered on 'nix platforms, simply do not exist on others.

In the case of the windows API, the data structure in question, DCB, should be documented in the online help, more extensive coverage will be found in the MSDN.

I have some example files that show some low level routines using the Windows API to control a serial port that is talking to an Omron C200. This code was run under C++ builder but the API calls will be the same under VC++, the library derives from the Windows SDK. (Contact me for a copy of these files, at <[email protected]>)

Note that these facilities are not adequate to implement many of the protocols used in industrial communications. To do that you will
need code that is able to respond directly to the UART. On W9x this can be achieved by direct access to the hardware, but this is a messy non portable way of doing things.

The correct way is a device driver, but this will be different for each version of windows, and is by no means easy under NT and W2K.

If your study purpose is learning the implementation of the low end of serial interfacing protocols, may I suggest you use DOS (do what the hell you like with no interference from the OS), or you try Linux, were writing device drivers (or installable kernel modules) is
much simpler. Also, you may study and/or extended the existing source code for the serial port.
 
W

Wallinius Mattias

Look in MSDN for ReadFile and File I/O. The com ports are treated as file I/O in Windows environments.
 
Hi there Anand, I'm trying to figure out serial communication bck here in Delhi, using the VC++ compiler. Can you do me a favour and send the code you have authored across so that I can get some insight? Thanx Puneet [email protected]
 
I am looking for sample Source code for Serial communication in VC++ for project purposes. Can somebody help me. If u get it pls. send it to me too Prasanna Phatak Pune mail me at : [email protected]
 
S
Dear Mr Anand can u send me the source code about the serial comm in c.I am eagerly looking for the same. I will try to convert it into VC++. If you wish it to be converted into VC please send me. My contact address is [email protected] Thanking you ShijuFrancis
 
Anand, If you still have your codes for communicating to serial ports, please, can you email me: [email protected] Thanks > Dear Mr Narang, > I have code written in pure C that will enable you to communicate to the pc using the com ports. If you are sure you can port the code to VC++ then i can send you the codes. > Anand Reliance Petroleum Ltd. >
 
dear mr anand we r students of btech working on a project for sharing a communication port across a network. .We have a server prog. running which accepts client requests. we want to route data from the server to the COM port through MSCOMM control of vb.and try to connect to the modem. can u please tell us how to read data from the server program port. thanks please mail us at [email protected]usa.net or [email protected]
 
if u have solve ur problem pls help me i have same problem i am very much thankful to u manish saxena
 
Top