developing driver for serial port using VC++ 6

V

Thread Starter

Vijay

I want to develop a driver software for my serial port using VC++. i don't have any exposure of vc++. It has to be similar to HYPER TERMINAL in PCs.

Some one please guide me.

Name: vijay
email-id: [email protected]
 
<p>Sealevel Systems (http://www.sealevel.com) includes code samples on the software CD that ships with all serial products. This C++ code sample shows you how to open a COM port, and send & receive data. In this example, data is sent and read at 460K bps, but standard windows ports are limited to 115K bps.
<pre>
----- Begin Code Sample -----

#include "stdafx.h"
#include
#include
#include
int main(int argc, char* argv[])
{
char INBUFFER[500];
char OUTBUFFER[20];
DWORD bytes_read = 0; // Number of bytes read from port
DWORD bytes_written = 0; // Number of bytes written to the port
HANDLE comport = NULL; // Handle COM port
int bStatus;
DCB comSettings; // Contains various port settings
COMMTIMEOUTS CommTimeouts;
strcpy(&OUTBUFFER[0], "The quick brown fox jumped over the lazy dog. \n\r\0");
// Open COM port
if ((comport =
CreateFile("\\\\.\\COM5", // open com5:
GENERIC_READ | GENERIC_WRITE, // for reading and writing
0, // exclusive access
NULL, // no security attributes
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL)) == INVALID_HANDLE_VALUE)
{
// error processing code goes here
}
// Set timeouts in milliseconds
CommTimeouts.ReadIntervalTimeout = 0;
CommTimeouts.ReadTotalTimeoutMultiplier = 0;
CommTimeouts.ReadTotalTimeoutConstant = 100;
CommTimeouts.WriteTotalTimeoutMultiplier = 0;
CommTimeouts.WriteTotalTimeoutConstant = 100;
bStatus = SetCommTimeouts(comport,&CommTimeouts);
if (bStatus != 0)
{
// error processing code goes here
}
// Set Port parameters.
// Make a call to GetCommState() first in order to fill
// the comSettings structure with all the necessary values.
// Then change the ones you want and call SetCommState().
GetCommState(comport, &comSettings);
comSettings.BaudRate = 460800;
comSettings.StopBits = ONESTOPBIT;
comSettings.ByteSize = 8;
comSettings.Parity = NOPARITY;
comSettings.fParity = FALSE;
bStatus = SetCommState(comport, &comSettings);
if (bStatus == 0)
{
// error processing code goes here
}
while(!kbhit())
{
bStatus = WriteFile(comport, // Handle
&OUTBUFFER, // Outgoing data
48, // Number of bytes to write
&bytes_written, // Number of bytes written
NULL);
if (bStatus != 0)
{
// error processing code here
}
bStatus = ReadFile(comport, // Handle
&INBUFFER, // Incoming data
500, // Number of bytes to read
&bytes_read, // Number of bytes read
NULL);
if (bStatus != 0)
{
// error processing code goes here
}
// code to do something with the data goes here
}
CloseHandle(comport);
return 0;
}
</pre>
 
J

JohnDepp2005

Basically you can use it like any file (CreateFile, ReadFile, WriteFile), named "COM%d" or something like that. you can also look at MSDN, under "SetCommState".
for an actual implementation, search the web for CSerial.
 
H

Hardik Joshi (Videocon Nagmada Glass)

Hello Vijay,

It seems that you want to develop a serial driver desparately... Goto http://www.windriver.com instead of going with VC++.

VC is a tough language and takes time to learn..Try this tool called windriver it is a predisigned tool to develop drivers of your choice....

Best of luck.

If you have any problem with this or if you really want to develop the driver in vc++ you mail me on [email protected]
 
hi vijay...

vijay have u some source code about serial driver?
i want to build communication serial com port to!
my project is to control computer from serialport, so, via rs232?

may u gift me some reference what u get? please help me!
 
R

R.Taherkhani

Hi,

thanks. i used this source code and i was successful to send data by serial port in VC++. i haven't test receiving data yet.
 
Top