473,386 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

GetCommState failed with error 87.

Hi,

i'm trying to set the serial port.(XP SP2, Visual Studio 2005). I use
the example code from MSDN "configuring a communications resource".

CreateFile pass through, however GetCommState return 0.With
GetLastError(), i get the error number 87, which means
"ERROR_INVALID_PARAMETER The parameter is incorrect. "
I'm sure the serial port works, because i can use another program to
read/write through it.

thx
Cheng

Jun 27 '08 #1
6 9787
On 14 Apr, 13:52, uvbaz <uv...@stud.uni-karlsruhe.dewrote:
i'm trying to set the serial port.(XP SP2, Visual Studio 2005). I use
the example code from MSDN "configuring a communications resource".

CreateFile pass through, however GetCommState return 0.With
GetLastError(), i get the error number 87, which means
"ERROR_INVALID_PARAMETER The parameter is incorrect. "
I'm sure the serial port works, because i can use another program to
read/write through it.
this isn't topical to comp.lang.c (even if your program
is written in C!). You need to ask on a Windows related news group.

Since you have an invalid parameter I strongly suggest
you post (to an appropriate ng) a short program that
illustrates your problem.
--
Nick Keighley

Jun 27 '08 #2
On 14 Apr., 15:47, Nick Keighley <nick_keighley_nos...@hotmail.com>
wrote:
On 14 Apr, 13:52, uvbaz <uv...@stud.uni-karlsruhe.dewrote:
i'm trying to set the serial port.(XP SP2, Visual Studio 2005). I use
the example code from MSDN "configuring a communications resource".
CreateFile pass through, however GetCommState return 0.With
GetLastError(), i get the error number 87, which means
"ERROR_INVALID_PARAMETER The parameter is incorrect. "
I'm sure the serial port works, because i can use another program to
read/write through it.

this isn't topical to comp.lang.c (even if your program
is written in C!). You need to ask on a Windows related news group.

Since you have an invalid parameter I strongly suggest
you post (to an appropriate ng) a short program that
illustrates your problem.

--
Nick Keighley
O.K.
Jun 27 '08 #3
On 14 Apr 2008 at 14:13, uvbaz wrote:
On 14 Apr., 15:47, Nick Keighley <nick_keighley_nos...@hotmail.com>
wrote:
>On 14 Apr, 13:52, uvbaz <uv...@stud.uni-karlsruhe.dewrote:
i'm trying to set the serial port.(XP SP2, Visual Studio 2005). I use
the example code from MSDN "configuring a communications resource".
CreateFile pass through, however GetCommState return 0.With
GetLastError(), i get the error number 87, which means
"ERROR_INVALID_PARAMETER The parameter is incorrect. "
I'm sure the serial port works, because i can use another program to
read/write through it.

Since you have an invalid parameter I strongly suggest
you post
[snip]
> a short program that illustrates your problem.

O.K.
You forgot to post the short program!

Jun 27 '08 #4
On 14 Apr., 19:14, Antoninus Twink <nos...@nospam.invalidwrote:
On 14 Apr 2008 at 14:13, uvbaz wrote:
On 14 Apr., 15:47, Nick Keighley <nick_keighley_nos...@hotmail.com>
wrote:
On 14 Apr, 13:52, uvbaz <uv...@stud.uni-karlsruhe.dewrote:
i'm trying to set the serial port.(XP SP2, Visual Studio 2005). I use
the example code from MSDN "configuring a communications resource".
CreateFile pass through, however GetCommState return 0.With
GetLastError(), i get the error number 87, which means
"ERROR_INVALID_PARAMETER The parameter is incorrect. "
I'm sure the serial port works, because i can use another program to
read/write through it.
Since you have an invalid parameter I strongly suggest
you post
[snip]
a short program that illustrates your problem.
O.K.

You forgot to post the short program!
Sorry.

#include <windows.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
DCB dcb;
HANDLE hCom;
BOOL fSuccess;
char *pcCommPort = "COM1";

hCom = CreateFile( pcCommPort,
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
);

if (hCom == INVALID_HANDLE_VALUE)
{
// Handle the error.
printf ("CreateFile failed with error %d.\n", GetLastError());
return (1);
}

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

fSuccess = GetCommState(hCom, &dcb);

if (!fSuccess)
{
// Handle the error.
printf ("GetCommState failed with error %d.\n", GetLastError());
return (2);
}

// Fill in DCB: 57,600 bps, 8 data bits, no parity, and 1 stop bit.

dcb.BaudRate = CBR_57600; // set the baud rate
dcb.ByteSize = 8; // data size, xmit, and rcv
dcb.Parity = NOPARITY; // no parity bit
dcb.StopBits = ONESTOPBIT; // one stop bit

fSuccess = SetCommState(hCom, &dcb);

if (!fSuccess)
{
// Handle the error.
printf ("SetCommState failed with error %d.\n", GetLastError());
return (3);
}

printf ("Serial port %s successfully reconfigured.\n", pcCommPort);
return (0);
}
Jun 27 '08 #5
uvbaz wrote:
On 14 Apr., 19:14, Antoninus Twink <nos...@nospam.invalidwrote:
>On 14 Apr 2008 at 14:13, uvbaz wrote:
>>On 14 Apr., 15:47, Nick Keighley <nick_keighley_nos...@hotmail.com>
wrote:
On 14 Apr, 13:52, uvbaz <uv...@stud.uni-karlsruhe.dewrote:
i'm trying to set the serial port.(XP SP2, Visual Studio 2005). I use
the example code from MSDN "configuring a communications resource".
CreateFile pass through, however GetCommState return 0.With
GetLastError(), i get the error number 87, which means
"ERROR_INVALID_PARAMETER The parameter is incorrect. "
I'm sure the serial port works, because i can use another program to
read/write through it.
Since you have an invalid parameter I strongly suggest
you post
[snip]
>>> a short program that illustrates your problem.
O.K.
You forgot to post the short program!

Sorry.

#include <windows.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
DCB dcb;
HANDLE hCom;
BOOL fSuccess;
char *pcCommPort = "COM1";

hCom = CreateFile( pcCommPort,
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
);

if (hCom == INVALID_HANDLE_VALUE)
{
// Handle the error.
printf ("CreateFile failed with error %d.\n", GetLastError());
return (1);
}

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

fSuccess = GetCommState(hCom, &dcb);

if (!fSuccess)
{
// Handle the error.
printf ("GetCommState failed with error %d.\n", GetLastError());
return (2);
}

// Fill in DCB: 57,600 bps, 8 data bits, no parity, and 1 stop bit.

dcb.BaudRate = CBR_57600; // set the baud rate
dcb.ByteSize = 8; // data size, xmit, and rcv
dcb.Parity = NOPARITY; // no parity bit
dcb.StopBits = ONESTOPBIT; // one stop bit

fSuccess = SetCommState(hCom, &dcb);

if (!fSuccess)
{
// Handle the error.
printf ("SetCommState failed with error %d.\n", GetLastError());
return (3);
}

printf ("Serial port %s successfully reconfigured.\n", pcCommPort);
return (0);
}
I compiled that, and I get
d:\lcc\mc71\test>tport
Serial port COM1 successfully reconfigured.

What is the problem?

Maybe you have a misconfiguration in your machine?
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Jun 27 '08 #6
uvbaz wrote, On 15/04/08 09:09:
On 14 Apr., 19:14, Antoninus Twink <nos...@nospam.invalidwrote:
>On 14 Apr 2008 at 14:13, uvbaz wrote:
>>On 14 Apr., 15:47, Nick Keighley <nick_keighley_nos...@hotmail.com>
wrote:
On 14 Apr, 13:52, uvbaz <uv...@stud.uni-karlsruhe.dewrote:
i'm trying to set the serial port.(XP SP2, Visual Studio 2005). I use
the example code from MSDN "configuring a communications resource".
CreateFile pass through, however GetCommState return 0.With
GetLastError(), i get the error number 87, which means
"ERROR_INVALID_PARAMETER The parameter is incorrect. "
I'm sure the serial port works, because i can use another program to
read/write through it.
Since you have an invalid parameter I strongly suggest
you post
[snip]
>>> a short program that illustrates your problem.
O.K.
You forgot to post the short program!

Sorry.

#include <windows.h>
<snip>

Now try posting it to a windows group as was suggested in the text that
Antoninus Twink snipped, something I'm sure he did deliberately to
misrepresent what Nick Keighley wrote.

If you post to a Windows group lots of people who know about Windows
specific problems will see you post and be able to answer, if you post
here there are far fewer experts on Windows.
--
Flash Gordon
Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bon | last post by:
Hello All I got "Tables are skipped or export failed" error when I used upsizing wizard on migrating MS Access 2000 to MS SQL Server 2000. I am changing my application backend database from MS...
0
by: QZ | last post by:
This one happens once in while and I would appreciates any help that I can get. We have a webservice that generate pdf invoice files. We use dataset as our Source. i.e. we use SetDataSource(data);...
3
by: shreedhar | last post by:
If I try to delete a record from my table which is giving following error Warning: PostgreSQL query failed: ERROR: pg_atoi: zero-length string in /xxx/database.inc on line 73 What might be...
3
by: ralphdepping | last post by:
Trying to get moinmoin wiki working on Windows 2000 using IIS and python. I get the following error when trying to view the start page after insalling moinmoin and python - key error seems to be...
0
by: t0nt0n | last post by:
i have an xp OS service pack 2 currently working on a project that uses ms access 2003 with mysql 5.0 backend... i get an odbc--call failed error when I manually changed the system date in my...
1
by: Don | last post by:
I'm getting the following exception displayed in the task list at design time for my project: "Code generation for property 'Controls' failed. Error was: 'Object reference not set to an...
0
by: jianxin9 | last post by:
Hi everyone, I don't have a lot of experience with ASP and I was hoping someone could help me. I want to use our ASP form along with some javascript code to create a form where our patrons can...
5
by: kchang | last post by:
I am trying to view my reports based on a linked table database. However both the reports and the queries they're based on give me a "odbc--call failed" error. When I click on help it cites error...
1
by: aurekha | last post by:
Hi All, Im newbie to Perl. My problem is that, when i run my script, It is showing the error like "DBI connect('blah','blah',...) failed: ERROR OCIEnvNlsCreate. Check ORACLE_HOME (Linux) env var...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.