Click here to Skip to main content
15,890,512 members
Home / Discussions / C#
   

C#

 
GeneralRe: TabControl Pin
Furty15-Feb-03 9:42
Furty15-Feb-03 9:42 
GeneralRe: TabControl Pin
monrobot1320-Feb-03 17:35
monrobot1320-Feb-03 17:35 
QuestionIs it allowed to use the tag in Xml Summary Comment tag ? Pin
Chris Richner11-Feb-03 9:37
Chris Richner11-Feb-03 9:37 
AnswerRe: Is it allowed to use the <p></p> tag in Xml Summary Comment tag ? Pin
leppie11-Feb-03 9:42
leppie11-Feb-03 9:42 
GeneralRe: Is it allowed to use the <p></p> tag in Xml Summary Comment tag ? Pin
Chris Richner11-Feb-03 11:25
Chris Richner11-Feb-03 11:25 
AnswerRe: Is it allowed to use the tag in Xml Summary Comment tag ? Pin
James T. Johnson11-Feb-03 20:17
James T. Johnson11-Feb-03 20:17 
Questionknowing the client visible area of datagrid ? Pin
Paresh Gheewala11-Feb-03 9:18
Paresh Gheewala11-Feb-03 9:18 
GeneralSerial port baud rate programming Pin
moacirferreira11-Feb-03 4:36
moacirferreira11-Feb-03 4:36 
Hi,

I am trying to setup a custom baud rate of 12000 but when I use the SetCommState() I get an error message telling me to review my set. However, any custom baud rate below 10000 will be set and work properly.

What is wrong? I need to use custom baud rates above 10000!

I have attached a sample program that anyone can use to test it.

Thanks
<code>
// *********************************************************
// A program that demonstrate the custom baud rate problem *
// *********************************************************
#include <windows.h>
#include <stdio.h>
#include <lmerr.h>
#include <stdlib.h>

void DisplayErrorText(DWORD dwLastError); // show last error
// message
#define RTN_OK 0
#define RTN_USAGE 1
#define RTN_ERROR 13

int main(int argc, char *argv[])
{
DCB dcb; // structure that hold all COM parameters
HANDLE hCom; // handle for the COM port
BOOL fSuccess; // to hold fail/success results

// test if 2 parameters has been supplied in teh command line
if (argc <= 2)
{
printf ("Please enter a COM port and the new baud rate in the command line.\n\ni.e.: porta COM2 1000\n");
return (1);
}
// Open the COM port
hCom = CreateFile( argv[1], // open the COM specified on teh command line
GENERIC_READ | GENERIC_WRITE,
0, // must be opened with exclusive-access
NULL, // no security attributes
OPEN_EXISTING, // must use OPEN_EXISTING
0, // not overlapped I/O
NULL // hTemplate must be NULL for comm devices
);
// test if open COM was ok
if (hCom == INVALID_HANDLE_VALUE)
{
// Handle the error.
printf ("CreateFile failed with error %d. ", GetLastError());
DisplayErrorText(GetLastError());
return (2);
}

// Build on the current configuration, and skip setting the size
// of the input and output buffers with SetupComm.

fSuccess = GetCommState(hCom, &dcb);

// test if getting the com state was ok
if (!fSuccess)
{
// Handle the error.
printf ("GetCommState failed with error %d. ", GetLastError());
DisplayErrorText(GetLastError());
return (3);
}

// Print previous baud rate for the specified COM port
printf ("\nThe baud rate of %s was %d.\n", argv[1], dcb.BaudRate);

// Fill in DCB with supplied bps, 8 data bits, no parity, and 1 stop bit.
dcb.BaudRate = atol(argv[2]); // set the baud rate
dcb.ByteSize = 8; // data size, xmit, and rcv
dcb.Parity = NOPARITY; // no parity bit
dcb.StopBits = ONESTOPBIT; // one stop bit

// set the COM port with the new parameters
fSuccess = SetCommState(hCom, &dcb);

// test if setting COM port was ok
if (!fSuccess)
{
// Handle the error.
printf ("SetCommState failed with error %d. ", GetLastError());
DisplayErrorText(GetLastError());
return (4);
}

fSuccess = GetCommState(hCom, &dcb);
// check to see if new baud rate has been set
if (!fSuccess)
{
printf ("GetCommState failed with error %d. ", GetLastError());
DisplayErrorText(GetLastError());
return (5);
}

// Print current baud rate
printf ("\nNow it is %d.\n", dcb.BaudRate);

return (0);
}
// *******************************************************
// Simple routine to show the error messages description *
// that is really useless!!! *
// *******************************************************
void DisplayErrorText( DWORD dwLastError )
{
HMODULE hModule = NULL; // default to system source
LPSTR MessageBuffer;
DWORD dwBufferLength;

DWORD dwFormatFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_FROM_SYSTEM ;

//
// If dwLastError is in the network range,
// load the message source.
//

if(dwLastError >= NERR_BASE && dwLastError <= MAX_NERR) {
hModule = LoadLibraryEx(
TEXT("netmsg.dll"),
NULL,
LOAD_LIBRARY_AS_DATAFILE
);

if(hModule != NULL)
dwFormatFlags |= FORMAT_MESSAGE_FROM_HMODULE;
}

//
// Call FormatMessage() to allow for message
// text to be acquired from the system
// or from the supplied module handle.
//

if(dwBufferLength = FormatMessageA(
dwFormatFlags,
hModule, // module to get message from (NULL == system)
dwLastError,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // default language
(LPSTR) &MessageBuffer,
0,
NULL
))
{
DWORD dwBytesWritten;

//
// Output message string on stderr.
//
WriteFile(
GetStdHandle(STD_ERROR_HANDLE),
MessageBuffer,
dwBufferLength,
&dwBytesWritten,
NULL
);

//
// Free the buffer allocated by the system.
//
LocalFree(MessageBuffer);
}

//
// If we loaded a message source, unload it.
//
if(hModule != NULL)
FreeLibrary(hModule);
}

</code>
GeneralRe: Serial port baud rate programming Pin
perlmunger11-Feb-03 4:50
perlmunger11-Feb-03 4:50 
QuestionHow do I create a command window/console? Pin
se99ts11-Feb-03 3:54
se99ts11-Feb-03 3:54 
AnswerRe: How do I create a command window/console? Pin
perlmunger11-Feb-03 4:39
perlmunger11-Feb-03 4:39 
GeneralRe: How do I create a command window/console? Pin
se99ts11-Feb-03 5:05
se99ts11-Feb-03 5:05 
GeneralRe: How do I create a command window/console? Pin
perlmunger11-Feb-03 5:59
perlmunger11-Feb-03 5:59 
GeneralRe: How do I create a command window/console? Pin
jtmtv1811-Feb-03 9:29
jtmtv1811-Feb-03 9:29 
GeneralRe: How do I create a command window/console? Pin
se99ts11-Feb-03 10:00
se99ts11-Feb-03 10:00 
GeneralRe: How do I create a command window/console? Pin
se99ts11-Feb-03 9:59
se99ts11-Feb-03 9:59 
GeneralCurious about C# and desktop apps Pin
John Mautari11-Feb-03 3:45
John Mautari11-Feb-03 3:45 
GeneralRe: Curious about C# and desktop apps Pin
Stephane Rodriguez.11-Feb-03 4:14
Stephane Rodriguez.11-Feb-03 4:14 
GeneralRe: Curious about C# and desktop apps Pin
TigerNinja_11-Feb-03 8:18
TigerNinja_11-Feb-03 8:18 
GeneralRe: Curious about C# and desktop apps Pin
Stephane Rodriguez.11-Feb-03 8:44
Stephane Rodriguez.11-Feb-03 8:44 
GeneralRe: Curious about C# and desktop apps Pin
jpwkeeper11-Feb-03 9:01
jpwkeeper11-Feb-03 9:01 
GeneralRe: Curious about C# and desktop apps Pin
John Mautari11-Feb-03 9:34
John Mautari11-Feb-03 9:34 
GeneralRe: Curious about C# and desktop apps Pin
Furty12-Feb-03 19:59
Furty12-Feb-03 19:59 
GeneralError Creating Window Handle Pin
jpwkeeper11-Feb-03 1:51
jpwkeeper11-Feb-03 1:51 
GeneralRe: Error Creating Window Handle Pin
perlmunger11-Feb-03 5:00
perlmunger11-Feb-03 5:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.