Hi,
I've posted earlier a question regarding the call to GetCommState.
Here is the code for the function.
The problem is that GetCommState always returns false!!
Why?
void Open()
{
// the DCB and COMMTIMEOUTS structure are declare a __value struct
DCB *dcbCommPort = __nogc new DCB();
COMMTIMEOUTS *ctoCommPort = __nogc new COMMTIMEOUTS();
// OPEN THE COMM PORT.
hComm = CreateFile("LPT 1",GENERIC_R EAD | GENERIC_WRITE,0 , 0,OPEN_EXISTING ,0,0);
// IF THE PORT CANNOT BE OPENED, BAIL OUT.
if(hComm == INVALID_HANDLE_ VALUE)
{
throw(new ApplicationExce ption("Comm Port Can Not Be Opened"));
}
// SET THE COMM TIMEOUTS.
GetCommTimeouts (hComm,ctoCommP ort);
ctoCommPort->ReadTotalTimeo utConstant = ReadTimeout;
ctoCommPort->ReadTotalTimeo utMultiplier = 0;
ctoCommPort->WriteTotalTime outMultiplier = 0;
ctoCommPort->WriteTotalTime outConstant = 0;
SetCommTimeouts (hComm,ctoCommP ort);
// SET BAUD RATE, PARITY, WORD SIZE, AND STOP BITS.
GetCommState(hC omm, dcbCommPort);
dcbCommPort->BaudRate=BaudR ate;
dcbCommPort->flags=0;
//dcb.fBinary=1;
dcbCommPort->flags|=1;
if (Parity>0)
{
dcbCommPort->flags|=2;
}
dcbCommPort->Parity=Parit y;
dcbCommPort->ByteSize=ByteS ize;
dcbCommPort->StopBits=StopB its;
if (!SetCommState( hComm, dcbCommPort)) // always returns false
{
throw(new ApplicationExce ption("Comm Port Can Not Be Opened"));
}
Opened = true;
}
Thanks! 5 5849
"CeZaR" <pa****@go.ro > wrote in message
news:fc******** *************** ***@posting.goo gle.com... I've posted earlier a question regarding the call to GetCommState. Here is the code for the function. The problem is that GetCommState always returns false!!
You shouldn't have to guess. _Immediately_ after the function returns, call
GetLastError().
Now, I haven't researched it, but if IJW is trampling on the thread's last
Win32 error by making some intervening Win32 API call, take a look at this: http://blogs.msdn.com/adam_nathan/ar.../25/56643.aspx
Just by the way, is the LPT port in question controlled by a printer driver?
Regards,
Will
I've stopped the spooler service before running the program.
Then i call CreateFile with "\\\\.\\NONSPOO LED_LPT1".
BTW GetLastError returns 2 -> Invalid function.
"William DePalo [MVP VC++]" <wi***********@ mvps.org> wrote in message news:<OG******* *******@TK2MSFT NGP12.phx.gbl>. .. "CeZaR" <pa****@go.ro > wrote in message news:fc******** *************** ***@posting.goo gle.com... I've posted earlier a question regarding the call to GetCommState. Here is the code for the function. The problem is that GetCommState always returns false!!
You shouldn't have to guess. _Immediately_ after the function returns, call GetLastError().
Now, I haven't researched it, but if IJW is trampling on the thread's last Win32 error by making some intervening Win32 API call, take a look at this:
http://blogs.msdn.com/adam_nathan/ar.../25/56643.aspx
Just by the way, is the LPT port in question controlled by a printer driver?
Regards, Will
And, finally i've fixed it!
The LPT port doesn't support all of the function in this code.
They all work for COM ports.
For LPT use just CreateFile, WriteFile.
"William DePalo [MVP VC++]" <wi***********@ mvps.org> wrote in message news:<OG******* *******@TK2MSFT NGP12.phx.gbl>. .. "CeZaR" <pa****@go.ro > wrote in message news:fc******** *************** ***@posting.goo gle.com... I've posted earlier a question regarding the call to GetCommState. Here is the code for the function. The problem is that GetCommState always returns false!!
You shouldn't have to guess. _Immediately_ after the function returns, call GetLastError().
Now, I haven't researched it, but if IJW is trampling on the thread's last Win32 error by making some intervening Win32 API call, take a look at this:
http://blogs.msdn.com/adam_nathan/ar.../25/56643.aspx
Just by the way, is the LPT port in question controlled by a printer driver?
Regards, Will
I've stopped the spooler service before running the program.
Then i call CreateFile with "\\\\.\\NONSPOO LED_LPT1".
BTW GetLastError returns 2 -> Invalid function.
"William DePalo [MVP VC++]" <wi***********@ mvps.org> wrote in message news:<OG******* *******@TK2MSFT NGP12.phx.gbl>. .. "CeZaR" <pa****@go.ro > wrote in message news:fc******** *************** ***@posting.goo gle.com... I've posted earlier a question regarding the call to GetCommState. Here is the code for the function. The problem is that GetCommState always returns false!!
You shouldn't have to guess. _Immediately_ after the function returns, call GetLastError().
Now, I haven't researched it, but if IJW is trampling on the thread's last Win32 error by making some intervening Win32 API call, take a look at this:
http://blogs.msdn.com/adam_nathan/ar.../25/56643.aspx
Just by the way, is the LPT port in question controlled by a printer driver?
Regards, Will
And, finally i've fixed it!
The LPT port doesn't support all of the function in this code.
They all work for COM ports.
For LPT use just CreateFile, WriteFile.
"William DePalo [MVP VC++]" <wi***********@ mvps.org> wrote in message news:<OG******* *******@TK2MSFT NGP12.phx.gbl>. .. "CeZaR" <pa****@go.ro > wrote in message news:fc******** *************** ***@posting.goo gle.com... I've posted earlier a question regarding the call to GetCommState. Here is the code for the function. The problem is that GetCommState always returns false!!
You shouldn't have to guess. _Immediately_ after the function returns, call GetLastError().
Now, I haven't researched it, but if IJW is trampling on the thread's last Win32 error by making some intervening Win32 API call, take a look at this:
http://blogs.msdn.com/adam_nathan/ar.../25/56643.aspx
Just by the way, is the LPT port in question controlled by a printer driver?
Regards, Will This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Guillaume Brocker |
last post by:
Hi !
I'm opening a socket to a web server on port 80 located on my LAN with
fsockopen. The socket creation fails and PHP returns
"php_network_getaddresses: getaddrinfo failed: Name or service not known"
But, a connection to the same web server through a browser works.
Has anybody some idea about that ?
|
by: Lizard King |
last post by:
Hi.
I have a computer running a third party software (POS). The thing is
this application opens the printer port and I need to use another
program while the first one is still running.
Since the other app has the printer port windows shows an error
(path/file access error).
Is there a way that two applications can share the printer port?
|
by: Martin Fuzzey |
last post by:
I am using xmlrpclib (based on httplib) in Python 2.3 on Mandrake
Linux.
When my client attempts to connect to a server using a
"http://localhost:port" style URL there is a long delay before the
connection is established (it finally works).
This certainly smells a name resolution problem but ping localhost,
telnet localhost etc all work fine.
|
by: Bryan Hahn |
last post by:
I would like to open our firewall to allow traffic from the w3c
validator in our development enviornment. I tried to open port 80
from 18.29.1.50 (validator.w3.org), but that didn't do the trick.
What ports/IP address(es) need to be opened in our firewall to allow
the validator through?
|
by: Alfons |
last post by:
Hello,
I have build a program that can do file transferring between a Windows
XP computer and a DOS computer via a serial port. The Windows program
I have build in C++ with Visual Studio 6.0. The DOS program I made in
Turbo C++ 3.0.
At this moment I am in a test phase of sending files and directories.
The code I am using in DOS to open a file for writing looks like this
(forgive me the typos, since I only have my source code at work...
| |
by: CeZaR |
last post by:
Hi,
I've posted earlier a question regarding the call to GetCommState.
Here is the code for the function.
The problem is that GetCommState always returns false!!
Why?
void Open()
{
// the DCB and COMMTIMEOUTS structure are declare a __value struct
DCB *dcbCommPort = __nogc new DCB();
|
by: David |
last post by:
I am having trouble with "ACCESS DENIED" error messages in a VB.NET 2003
application when attempting to open
serial comms ports.
The application has 2 ports that connect via serial cable to 2 different
hardware devices to transfer binary data to the application. The setup
screen enables the user to select COM1 -- COM8 via combo boax for each port.
Then they click "Apply" to open the ports.
The code that I have written to open the...
|
by: Luke Davis |
last post by:
I'm looking for an effective way to open and close TCP ports. Can I do
this through Tcpclient? And I know this is a potential security risk, so
what kind of permission must the person running the application possess to
handle it without errors?
--
Luke Davis, MCSE: Security
DEM Networks - Senior Systems Architect
7225 N First, Suite 105
Fresno, CA 93720
|
by: Suresh P |
last post by:
Hi All,
I tried to access the mysql database in ODBC using ip address and
username/password.
It returns, "cannot connect to MySQL server on IP ADDRESS(10060)".
This could be related to Firewall on the server.
Is there anyway to access MySQL database using ODBC without opening
port 3306?
|
by: cmdolcet69 |
last post by:
I have the following code: When i run this code it gieve me an error
saying the COM port isn;t opened?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If serialPort.IsOpen Then
serialPort.Close()
End If
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |