what is wrong with this, i'm stumped and gettin nowhere :-(
CPP FILE
// Serial.cpp
#include <stdio>
#include <stdexcept>
#include "Serial.h"
CSerial::CSeria l()
{
memset( &m_OverlappedRe ad, 0, sizeof( OVERLAPPED ) );
memset( &m_OverlappedWr ite, 0, sizeof( OVERLAPPED ) );
m_hIDComDev = NULL;
m_bOpened = false;
}
CSerial::~CSeri al()
{
Close(void);
}
BOOL CSerial::Open( int nPort, int nBaud )
{
if( m_bOpened ) return( true );
char szPort[15];
char szComParams[50];
DCB dcb;
wsprintf( szPort, "COM%d", nPort );
m_hIDComDev = CreateFile( szPort, GENERIC_READ | GENERIC_WRITE, 0, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_ NORMAL | FILE_FLAG_OVERL APPED, NULL );
if( m_hIDComDev == NULL ) return( false );
memset( &m_OverlappedRe ad, 0, sizeof( OVERLAPPED ) );
memset( &m_OverlappedWr ite, 0, sizeof( OVERLAPPED ) );
COMMTIMEOUTS CommTimeOuts;
CommTimeOuts.Re adIntervalTimeo ut = 0xFFFFFFFF;
CommTimeOuts.Re adTotalTimeoutM ultiplier = 0;
CommTimeOuts.Re adTotalTimeoutC onstant = 0;
CommTimeOuts.Wr iteTotalTimeout Multiplier = 0;
CommTimeOuts.Wr iteTotalTimeout Constant = 5000;
SetCommTimeouts ( m_hIDComDev, &CommTimeOut s );
wsprintf( szComParams, "COM%d:%d,n,8,1 ", nPort, nBaud );
m_OverlappedRea d.hEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
m_OverlappedWri te.hEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
dcb.DCBlength = sizeof( DCB );
GetCommState( m_hIDComDev, &dcb );
dcb.BaudRate = nBaud;
dcb.ByteSize = 8;
unsigned char ucSet;
ucSet = (unsigned char) ( ( FC_RTSCTS & FC_DTRDSR ) != 0 );
ucSet = (unsigned char) ( ( FC_RTSCTS & FC_RTSCTS ) != 0 );
ucSet = (unsigned char) ( ( FC_RTSCTS & FC_XONXOFF ) != 0 );
if( !SetCommState( m_hIDComDev, &dcb ) ||
!SetupComm( m_hIDComDev, 10000, 10000 ) ||
m_OverlappedRea d.hEvent == NULL ||
m_OverlappedWri te.hEvent == NULL ){
DWORD dwError = GetLastError();
if( m_OverlappedRea d.hEvent != NULL ) CloseHandle(
m_OverlappedRea d.hEvent );
if( m_OverlappedWri te.hEvent != NULL ) CloseHandle(
m_OverlappedWri te.hEvent );
CloseHandle( m_hIDComDev );
return( false );
}
m_bOpened = TRUE;
return( m_bOpened );
}
BOOL CSerial::Close( void )
{
if( !m_bOpened || m_hIDComDev == NULL ) return( TRUE );
if( m_OverlappedRea d.hEvent != NULL ) CloseHandle(
m_OverlappedRea d.hEvent );
if( m_OverlappedWri te.hEvent != NULL ) CloseHandle(
m_OverlappedWri te.hEvent );
CloseHandle( m_hIDComDev );
m_bOpened = FALSE;
m_hIDComDev = NULL;
return( true );
}
BOOL CSerial::WriteC ommByte( unsigned char ucByte )
{
BOOL bWriteStat;
DWORD dwBytesWritten;
bWriteStat = WriteFile( m_hIDComDev, (LPSTR) &ucByte, 1, &dwBytesWritten ,
&m_OverlappedWr ite );
if( !bWriteStat && ( GetLastError() == ERROR_IO_PENDIN G ) ){
if( WaitForSingleOb ject( m_OverlappedWri te.hEvent, 1000 ) ) dwBytesWritten
= 0;
else{
GetOverlappedRe sult( m_hIDComDev, &m_OverlappedWr ite, &dwBytesWritten ,
FALSE );
m_OverlappedWri te.Offset += dwBytesWritten;
}
}
return( true );
}
int CSerial::SendDa ta( const char *buffer, int size )
{
if( !m_bOpened || m_hIDComDev == NULL ) return( 0 );
DWORD dwBytesWritten = 0;
int i;
for( i=0; i<size; i++ ){
WriteCommByte( buffer[i] );
dwBytesWritten+ +;
}
return( (int) dwBytesWritten );
}
int CSerial::ReadDa taWaiting( void )
{
if( !m_bOpened || m_hIDComDev == NULL ) return( 0 );
DWORD dwErrorFlags;
COMSTAT ComStat;
ClearCommError( m_hIDComDev, &dwErrorFlag s, &ComStat );
return( (int) ComStat.cbInQue );
}
int CSerial::ReadDa ta( void *buffer, int limit )
{
if( !m_bOpened || m_hIDComDev == NULL ) return( 0 );
BOOL bReadStatus;
DWORD dwBytesRead, dwErrorFlags;
COMSTAT ComStat;
ClearCommError( m_hIDComDev, &dwErrorFlag s, &ComStat );
if( !ComStat.cbInQu e ) return( 0 );
dwBytesRead = (DWORD) ComStat.cbInQue ;
if( limit < (int) dwBytesRead ) dwBytesRead = (DWORD) limit;
bReadStatus = ReadFile( m_hIDComDev, buffer, dwBytesRead, &dwBytesRead ,
&m_OverlappedRe ad );
if( !bReadStatus ){
if( GetLastError() == ERROR_IO_PENDIN G ){
WaitForSingleOb ject( m_OverlappedRea d.hEvent, 2000 );
return( (int) dwBytesRead );
}
return( 0 );
}
return( (int) dwBytesRead );
}
HEADER FILE
// Serial.h
#ifndef __SERIAL_H__
#define __SERIAL_H__
#define FC_DTRDSR 0x01
#define FC_RTSCTS 0x02
#define FC_XONXOFF 0x04
#define ASCII_BEL 0x07
#define ASCII_BS 0x08
#define ASCII_LF 0x0A
#define ASCII_CR 0x0D
#define ASCII_XON 0x11
#define ASCII_XOFF 0x13
class CSerial
{
public:
CSerial();
~CSerial();
BOOL (Open( int nPort, int nBaud));
BOOL (Close( void ));
int ReadData( void *, int );
int SendData( const char *, int );
int ReadDataWaiting ( void );
BOOL (IsOpened( void ){return( m_bOpened )});
protected:
BOOL (WriteCommByte( unsigned char ));
HANDLE (m_hIDComDev);
OVERLAPPED ((m_OverlappedR ead)(m_Overlapp edWrite));
BOOL (m_bOpened);
};
#endif 7 3650
bex,
Could you give us a hint as to what you think is wrong? What problem
are you encountering?
David
On Mon, 26 Apr 2004 09:13:52 UTC, "bex" <be***@ppmsolut ions.co.uk> wrote: what is wrong with this, i'm stumped and gettin nowhere :-(
CPP FILE
// Serial.cpp
#include <stdio> #include <stdexcept> #include "Serial.h"
CSerial::CSeria l() {
memset( &m_OverlappedRe ad, 0, sizeof( OVERLAPPED ) ); memset( &m_OverlappedWr ite, 0, sizeof( OVERLAPPED ) ); m_hIDComDev = NULL; m_bOpened = false;
}
CSerial::~CSeri al() {
Close(void);
}
BOOL CSerial::Open( int nPort, int nBaud ) {
if( m_bOpened ) return( true );
char szPort[15]; char szComParams[50]; DCB dcb;
wsprintf( szPort, "COM%d", nPort ); m_hIDComDev = CreateFile( szPort, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_ NORMAL | FILE_FLAG_OVERL APPED, NULL ); if( m_hIDComDev == NULL ) return( false );
memset( &m_OverlappedRe ad, 0, sizeof( OVERLAPPED ) ); memset( &m_OverlappedWr ite, 0, sizeof( OVERLAPPED ) );
COMMTIMEOUTS CommTimeOuts; CommTimeOuts.Re adIntervalTimeo ut = 0xFFFFFFFF; CommTimeOuts.Re adTotalTimeoutM ultiplier = 0; CommTimeOuts.Re adTotalTimeoutC onstant = 0; CommTimeOuts.Wr iteTotalTimeout Multiplier = 0; CommTimeOuts.Wr iteTotalTimeout Constant = 5000; SetCommTimeouts ( m_hIDComDev, &CommTimeOut s );
wsprintf( szComParams, "COM%d:%d,n,8,1 ", nPort, nBaud );
m_OverlappedRea d.hEvent = CreateEvent( NULL, TRUE, FALSE, NULL ); m_OverlappedWri te.hEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
dcb.DCBlength = sizeof( DCB ); GetCommState( m_hIDComDev, &dcb ); dcb.BaudRate = nBaud; dcb.ByteSize = 8; unsigned char ucSet; ucSet = (unsigned char) ( ( FC_RTSCTS & FC_DTRDSR ) != 0 ); ucSet = (unsigned char) ( ( FC_RTSCTS & FC_RTSCTS ) != 0 ); ucSet = (unsigned char) ( ( FC_RTSCTS & FC_XONXOFF ) != 0 ); if( !SetCommState( m_hIDComDev, &dcb ) || !SetupComm( m_hIDComDev, 10000, 10000 ) || m_OverlappedRea d.hEvent == NULL || m_OverlappedWri te.hEvent == NULL ){ DWORD dwError = GetLastError(); if( m_OverlappedRea d.hEvent != NULL ) CloseHandle( m_OverlappedRea d.hEvent ); if( m_OverlappedWri te.hEvent != NULL ) CloseHandle( m_OverlappedWri te.hEvent ); CloseHandle( m_hIDComDev ); return( false ); }
m_bOpened = TRUE;
return( m_bOpened );
}
BOOL CSerial::Close( void ) {
if( !m_bOpened || m_hIDComDev == NULL ) return( TRUE );
if( m_OverlappedRea d.hEvent != NULL ) CloseHandle( m_OverlappedRea d.hEvent ); if( m_OverlappedWri te.hEvent != NULL ) CloseHandle( m_OverlappedWri te.hEvent ); CloseHandle( m_hIDComDev ); m_bOpened = FALSE; m_hIDComDev = NULL;
return( true );
}
BOOL CSerial::WriteC ommByte( unsigned char ucByte ) { BOOL bWriteStat; DWORD dwBytesWritten;
bWriteStat = WriteFile( m_hIDComDev, (LPSTR) &ucByte, 1, &dwBytesWritten , &m_OverlappedWr ite ); if( !bWriteStat && ( GetLastError() == ERROR_IO_PENDIN G ) ){ if( WaitForSingleOb ject( m_OverlappedWri te.hEvent, 1000 ) ) dwBytesWritten = 0; else{ GetOverlappedRe sult( m_hIDComDev, &m_OverlappedWr ite, &dwBytesWritten , FALSE ); m_OverlappedWri te.Offset += dwBytesWritten; } }
return( true );
}
int CSerial::SendDa ta( const char *buffer, int size ) {
if( !m_bOpened || m_hIDComDev == NULL ) return( 0 );
DWORD dwBytesWritten = 0; int i; for( i=0; i<size; i++ ){ WriteCommByte( buffer[i] ); dwBytesWritten+ +; }
return( (int) dwBytesWritten );
}
int CSerial::ReadDa taWaiting( void ) {
if( !m_bOpened || m_hIDComDev == NULL ) return( 0 );
DWORD dwErrorFlags; COMSTAT ComStat;
ClearCommError( m_hIDComDev, &dwErrorFlag s, &ComStat );
return( (int) ComStat.cbInQue );
}
int CSerial::ReadDa ta( void *buffer, int limit ) {
if( !m_bOpened || m_hIDComDev == NULL ) return( 0 );
BOOL bReadStatus; DWORD dwBytesRead, dwErrorFlags; COMSTAT ComStat;
ClearCommError( m_hIDComDev, &dwErrorFlag s, &ComStat ); if( !ComStat.cbInQu e ) return( 0 );
dwBytesRead = (DWORD) ComStat.cbInQue ; if( limit < (int) dwBytesRead ) dwBytesRead = (DWORD) limit;
bReadStatus = ReadFile( m_hIDComDev, buffer, dwBytesRead, &dwBytesRead , &m_OverlappedRe ad ); if( !bReadStatus ){ if( GetLastError() == ERROR_IO_PENDIN G ){ WaitForSingleOb ject( m_OverlappedRea d.hEvent, 2000 ); return( (int) dwBytesRead ); } return( 0 ); }
return( (int) dwBytesRead );
}
HEADER FILE
// Serial.h
#ifndef __SERIAL_H__ #define __SERIAL_H__
#define FC_DTRDSR 0x01 #define FC_RTSCTS 0x02 #define FC_XONXOFF 0x04 #define ASCII_BEL 0x07 #define ASCII_BS 0x08 #define ASCII_LF 0x0A #define ASCII_CR 0x0D #define ASCII_XON 0x11 #define ASCII_XOFF 0x13
class CSerial {
public: CSerial(); ~CSerial();
BOOL (Open( int nPort, int nBaud)); BOOL (Close( void ));
int ReadData( void *, int ); int SendData( const char *, int ); int ReadDataWaiting ( void );
BOOL (IsOpened( void ){return( m_bOpened )});
protected: BOOL (WriteCommByte( unsigned char ));
HANDLE (m_hIDComDev); OVERLAPPED ((m_OverlappedR ead)(m_Overlapp edWrite)); BOOL (m_bOpened);
};
#endif
"David" <Fl************ @United.Com> wrote in message
news:rOdGr40LMP U3-pn2-UhdE1wuJ65zy@lo calhost... bex,
Could you give us a hint as to what you think is wrong? What problem are you encountering?
David
C'mon David, its obvious what's wrong, it doesn't work.
john
bex wrote: what is wrong with this, i'm stumped and gettin nowhere :-(
You can do better than that. Read the welcome message and the posting
guidelines in the FAQ. Search the web for "C++ welcome message" and
"C++ FAQ". There's also an article about asking good questions on usenet
which you can find in the same way (it is by Eric Steven Raymond).
--
Regards,
Buster.
?? What's wrong where ? u didn't mention what problem u r facing ..
bex wrote: what is wrong with this, i'm stumped and gettin nowhere :-(
As implied in your post, I pressume that when you hit "compile",
custard is oozing out of your printer. This is most likely a problem
with Microsoft Windows, not specifically with your code.
If you have any other problems with your code, please feel free to
elaborate on them. Two kinds of problem I predict:
A) Compile/Link error. There's an error in your code, eg. syntax
error, type mismatch. You're not even getting an executable file.
B) You are getting an executable file, but your calls to the Win32API
aren't working as you would like.
In the case of A: People here will be glad to help you if you tell us
what errors you're getting.
In the case of B: Connect to the news server, "msnews.microso ft.com",
and go to the newsgroup "microsoft.publ ic.win32.progra mmer.kernel",
where experts will be more than happy to help.
-JKop
Buster wrote: bex wrote:
what is wrong with this, i'm stumped and gettin nowhere :-(
You can do better than that. Read the welcome message and the posting guidelines in the FAQ. Search the web for "C++ welcome message" and "C++ FAQ". There's also an article about asking good questions on usenet which you can find in the same way (it is by Eric Steven Raymond). http://www.catb.org/~esr/faqs/smart-questions.html -- Regards, Buster.
--
--- remove zees if contacting via email --- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Dave |
last post by:
After following Microsofts admonition to reformat my system before doing a
final compilation of my app I got many warnings/errors upon compiling an rtf
file created in word. I used the Help Workshop program: hcw.exe that's
included with Visual Basic. This exact same file compiled perfectly with no
notes, warnings or errors prior to...
|
by: Tom |
last post by:
A question for gui application programmers. . .
I 've got some GUI programs, written in Python/wxPython, and I've got
a help button and a help menu item. Also, I've got a compiled file
made with the microsoft HTML workshop utility, lets call it
c:\path\help.chm. My question is how do you launch it from the GUI?
What logic do I put behind...
|
by: wukexin |
last post by:
Help me, good men. I find mang books that introduce bit "mang header
files",they talk too bit,in fact it is my too fool, I don't learn it, I have
do a test program, but I have no correct doing result in any way. Who can
help me, I thank you very very much.
list.cpp(main program)...
|
by: Colin J. Williams |
last post by:
Python advertises some basic service:
C:\Python24>python
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
With numarray, help gives unhelpful responses:
|
by: Corepaul |
last post by:
Missing Help Files
When I enter "recordset" as the keyword and search the Visual Basic Help index,
I get many topics of interest in the resulting list. But there isn't any
information available from clicking on many of the available topics (mostly
methods but some properties are also unavailable). This same problem occurs
with many, if not...
| |
by: Steve |
last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp
My expectation is that a developer using my DLL would be able to access this help file during his development time using "F1" help within the VB IDE. Is this expectation achievable
In trying to test my help file in the IDE, I have a solution with 2 projects:...
|
by: Mark |
last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my
home computer has an abbreviated help screen not 2% of the help on my laptop.
All the settings look the same on both including search the internet for
help, but the help is worthless. Any ideas?
|
by: JonathanOrlev |
last post by:
Hello everybody,
I wrote this comment in another message of mine, but decided to post it
again as a standalone message.
I think that Microsoft's Office 2003 help system is horrible, probably
the worst I
ever seen.
I almost cannot find anything I need, including things I
|
by: trunxnirvana007 |
last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
'UPGRADE_WARNING: Couldn't resolve default property of object Label. Click for more:...
|
by: hitencontractor |
last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003.
I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About.
The application calls MS Excel, so the scenario is that I am supposed to see the Excel Menu bar,
FILE EDIT VIEW INSERT ... HELP.
I am able to see the menu bar, but in...
|
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...
| |
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...
|
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. ...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
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...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |