|
Hi!
I was wondering if you could help me with something. I have to write code on serial communication for my computing class, and I was hoping you could take a look at it for me?
I can't figure out what the problem is. It's impossible to read data while the program is executed - there's no data in que then - but debugging it, it works fine ...?! I've also used WaitCommEvent, but it works like crap, too. It seems that actually no data arrives, just why?. Isn't it possible to see how much data is present and read exactly that amount? The interface hooked up at Rs232 works faultlessly. What else could cause such problems I'm confronted with?
I hope this and my English did make any sense to you
Awaiting your response,
Pit
Maybe someone wanna take a closer look at my code. Here it is:
(Please let me know if I've made any terrible errors!)
<br />
#include "Com_Handle.h"<br />
<br />
unsigned char CRC(void);<br />
<br />
<br />
Com_Port::Com_Port()<br />
{<br />
Init_ELM();<br />
}<br />
<br />
Com_Port::~Com_Port()<br />
{<br />
Close_Comport(DriverHandle);<br />
}<br />
<br />
<br />
HANDLE Com_Port::Open_Comport (DWORD Comport)<br />
{ <br />
switch (Comport) <br />
{<br />
case 1:<br />
strcpy (Com_Name, "COM1");<br />
break;<br />
case 2:<br />
strcpy (Com_Name, "COM2");<br />
break;<br />
case 3:<br />
strcpy (Com_Name, "COM3");<br />
break;<br />
case 4:<br />
strcpy (Com_Name, "COM4");<br />
break;<br />
default:<br />
return 0;<br />
}<br />
<br />
<br />
DriverHandle = CreateFile (Com_Name,<br />
GENERIC_READ | GENERIC_WRITE,<br />
0,<br />
NULL,<br />
OPEN_EXISTING,<br />
0,<br />
NULL);<br />
<br />
<br />
if (DriverHandle == INVALID_HANDLE_VALUE) <br />
{<br />
Get_Error();<br />
return (FALSE);<br />
}<br />
return DriverHandle;<br />
}<br />
<br />
<br />
int Com_Port :: Config_ComPort(HANDLE DriverHandle, DWORD BaudRate)<br />
{<br />
cout << "Configuring ELM ..." << endl;<br />
<br />
switch (BaudRate)<br />
{<br />
case 110:<br />
DCB_Baud_Rate = CBR_110;<br />
break; <br />
case 300:<br />
DCB_Baud_Rate = CBR_300;<br />
break; <br />
case 600:<br />
DCB_Baud_Rate = CBR_600;<br />
break; <br />
case 1200:<br />
DCB_Baud_Rate = CBR_1200;<br />
break; <br />
case 2400:<br />
DCB_Baud_Rate = CBR_2400;<br />
break; <br />
case 4800:<br />
DCB_Baud_Rate = CBR_4800;<br />
break; <br />
case 9600:<br />
DCB_Baud_Rate = CBR_9600;<br />
break; <br />
case 14400:<br />
DCB_Baud_Rate = CBR_14400;<br />
break; <br />
case 19200:<br />
DCB_Baud_Rate = CBR_19200;<br />
break;<br />
case 38400:<br />
DCB_Baud_Rate = CBR_38400;<br />
break; <br />
case 56000:<br />
DCB_Baud_Rate = CBR_56000;<br />
break; <br />
default:<br />
return 0;<br />
}<br />
<br />
<br />
<br />
if(!SetupComm (DriverHandle, 1024, 1024))<br />
Get_Error();<br />
<br />
<br />
if(!GetCommState (DriverHandle, &ELM_DCB))<br />
Get_Error();<br />
<br />
ELM_DCB.BaudRate = DCB_Baud_Rate;<br />
ELM_DCB.fParity = 0;<br />
ELM_DCB.fOutxCtsFlow = 0;<br />
ELM_DCB.fOutxDsrFlow = 0;<br />
ELM_DCB.fDtrControl = DTR_CONTROL_DISABLE;<br />
ELM_DCB.fDsrSensitivity = FALSE;<br />
ELM_DCB.fTXContinueOnXoff = 0;<br />
ELM_DCB.fOutX = 0;<br />
ELM_DCB.fInX = 0;<br />
ELM_DCB.fErrorChar = 0;<br />
ELM_DCB.fNull = 0;<br />
ELM_DCB.fRtsControl = RTS_CONTROL_DISABLE;<br />
ELM_DCB.fAbortOnError = 0;<br />
ELM_DCB.ByteSize = 8;<br />
ELM_DCB.Parity = NOPARITY;<br />
ELM_DCB.StopBits = ONESTOPBIT;<br />
<br />
if(!SetCommState (DriverHandle, &ELM_DCB))<br />
Get_Error();<br />
<br />
<br />
if(!SetCommMask (DriverHandle, EV_TXEMPTY))<br />
Get_Error();<br />
<br />
COMMTIMEOUTS sTo;<br />
<br />
if(GetCommTimeouts(DriverHandle, &sTo))<br />
{<br />
sTo.ReadIntervalTimeout = 100;<br />
sTo.ReadTotalTimeoutConstant = 100 ;<br />
sTo.ReadTotalTimeoutMultiplier = 100;<br />
sTo.WriteTotalTimeoutConstant = 0;<br />
sTo.WriteTotalTimeoutMultiplier = 0;<br />
}<br />
else<br />
{<br />
return (FALSE);<br />
}<br />
<br />
if(!(SetCommTimeouts(DriverHandle, &sTo)))<br />
{<br />
Get_Error();<br />
}<br />
return 0; <br />
}<br />
<br />
<br />
<br />
<br />
int Com_Port :: Close_Comport (HANDLE DriverHandle)<br />
{<br />
<br />
if ((DriverHandle == 0) || (DriverHandle == INVALID_HANDLE_VALUE))<br />
{<br />
return FALSE; <br />
}<br />
<br />
CloseHandle (DriverHandle);<br />
<br />
<br />
return TRUE;<br />
}<br />
<br />
<br />
int Com_Port :: Write_Comport (HANDLE DriverHandle, DWORD NumBytes, void *Buffer)<br />
{<br />
DWORD BytesWritten; <br />
BOOL status;<br />
<br />
if ((DriverHandle == 0) || (DriverHandle == INVALID_HANDLE_VALUE)) {<br />
return FALSE;<br />
} <br />
<br />
<br />
status = WriteFile (DriverHandle, Buffer, NumBytes, &BytesWritten, 0);<br />
<br />
<br />
return TRUE;<br />
}<br />
<br />
<br />
<br />
<br />
<br />
int Com_Port :: Read_Comport (HANDLE DriverHandle,<br />
DWORD *BytesRead,<br />
DWORD BufferSize,<br />
void *Buffer)<br />
{<br />
COMSTAT Our_Comstat;<br />
<br />
if ((DriverHandle == 0) || (DriverHandle == INVALID_HANDLE_VALUE)) {<br />
return (FALSE);<br />
} <br />
<br />
<br />
ClearCommError (DriverHandle, &Com_Errors, &Our_Comstat);<br />
<br />
<br />
<br />
cout << "QUE: " << Our_Comstat.cbInQue << endl;<br />
<br />
if (Our_Comstat.cbInQue > 0) <br />
{<br />
if (Our_Comstat.cbInQue > BufferSize)<br />
{<br />
BytesToRead = BufferSize;<br />
} <br />
else<br />
{<br />
BytesToRead = Our_Comstat.cbInQue;<br />
}<br />
<br />
<br />
if (!ReadFile (DriverHandle, Buffer, BytesToRead, BytesRead, NULL))<br />
{<br />
cout << "Read FAIL!\n";<br />
}<br />
}<br />
else<br />
{<br />
*BytesRead = 0;<br />
}<br />
return TRUE;<br />
}<br />
<br />
int Com_Port::Get_Error()<br />
{<br />
Com_Errors = GetLastError();
cout << "An error occured: " << GetLastError() << endl << endl;<br />
return 0;<br />
}<br />
<br />
unsigned int Com_Port::Port_No = 0;<br />
<br />
int Com_Port :: Init_ELM ()<br />
{ <br />
cout << "Searching ComPort, please wait. \n\n";<br />
do<br />
{ <br />
Port_No ++;<br />
DriverHandle = Open_Comport (Port_No);<br />
}<br />
while(!DriverHandle && Port_No != 5);<br />
if (!DriverHandle)<br />
{<br />
cout << "Unable to open port" << endl;<br />
return 0;<br />
}<br />
cout << "Connected on " << Com_Name << endl;<br />
Config_ComPort(DriverHandle, 9600);<br />
ComHandle = DriverHandle;
return 0;<br />
}<br />
<br />
<br />
unsigned char CRC(void)<br />
{<br />
unsigned char msg_buf[20], nBytes=0;<br />
<br />
unsigned char CRC_Reg=0xff;<br />
unsigned char poly,i,j;<br />
unsigned char Checksum=0;<br />
unsigned char *Byte_point, Bit_point;<br />
<br />
for (i=0, Byte_point=msg_buf; i<nBytes; i++, Byte_point++)<br />
{<br />
for (j=0, Bit_point=0x80 ; j<8; j++, Bit_point>>=1)<br />
{<br />
if (Bit_point & *Byte_point)<br />
{<br />
if (CRC_Reg & 0x80)<br />
poly=1;<br />
<br />
else<br />
poly=0x1C;<br />
<br />
CRC_Reg= ( (CRC_Reg << 1) | 1)^poly;<br />
}<br />
else<br />
{<br />
poly=0;<br />
<br />
if (CRC_Reg & 0x80)<br />
poly=0x1D;<br />
<br />
CRC_Reg= (CRC_Reg << 1)^poly;<br />
}<br />
}<br />
}<br />
return ~CRC_Reg;
}<br />
<br />
|
|
|
|
|
I was having a hellova time trying to trace this without formatting so I took the liberty to format it so I could take a look. I figured I'd repost the code with the formattng preserved so others who want to take a look and try to help you find the problem won't have to spend the 5 or 10 minutes needed to indent and such.
#include "Com_Handle.h"
unsigned char CRC(void);
Com_Port::Com_Port()
{
Init_ELM();
}
Com_Port::~Com_Port()
{
Close_Comport(DriverHandle);
}
HANDLE Com_Port::Open_Comport (DWORD Comport)
{
switch (Comport) {
case 1:
strcpy (Com_Name, "COM1");
break;
case 2:
strcpy (Com_Name, "COM2");
break;
case 3:
strcpy (Com_Name, "COM3");
break;
case 4:
strcpy (Com_Name, "COM4");
break;
default:
return 0;
}
DriverHandle=CreateFile(Com_Name,GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
if (DriverHandle==INVALID_HANDLE_VALUE) {
Get_Error();
return (FALSE);
}
return DriverHandle;
}
int Com_Port::Config_ComPort(HANDLE DriverHandle,DWORD BaudRate) {
cout << "Configuring ELM ..." << endl;
switch (BaudRate) {
case 110:
DCB_Baud_Rate=CBR_110;
break;
case 300:
DCB_Baud_Rate=CBR_300;
break;
case 600:
DCB_Baud_Rate=CBR_600;
break;
case 1200:
DCB_Baud_Rate=CBR_1200;
break;
case 2400:
DCB_Baud_Rate=CBR_2400;
break;
case 4800:
DCB_Baud_Rate=CBR_4800;
break;
case 9600:
DCB_Baud_Rate=CBR_9600;
break;
case 14400:
DCB_Baud_Rate=CBR_14400;
break;
case 19200:
DCB_Baud_Rate=CBR_19200;
break;
case 38400:
DCB_Baud_Rate=CBR_38400;
break;
case 56000:
DCB_Baud_Rate=CBR_56000;
break;
default:
return 0;
}
if(!SetupComm (DriverHandle, 1024, 1024))
Get_Error();
if(!GetCommState (DriverHandle, &ELM_DCB))
Get_Error();
ELM_DCB.BaudRate = DCB_Baud_Rate;
ELM_DCB.fParity = 0;
ELM_DCB.fOutxCtsFlow = 0;
ELM_DCB.fOutxDsrFlow = 0;
ELM_DCB.fDtrControl = DTR_CONTROL_DISABLE;
ELM_DCB.fDsrSensitivity = FALSE;
ELM_DCB.fTXContinueOnXoff = 0;
ELM_DCB.fOutX = 0;
ELM_DCB.fInX = 0;
ELM_DCB.fErrorChar = 0;
ELM_DCB.fNull = 0;
ELM_DCB.fRtsControl = RTS_CONTROL_DISABLE;
ELM_DCB.fAbortOnError = 0;
ELM_DCB.ByteSize = 8;
ELM_DCB.Parity = NOPARITY;
ELM_DCB.StopBits = ONESTOPBIT;
if(!SetCommState (DriverHandle, &ELM_DCB))
Get_Error();
if(!SetCommMask (DriverHandle, EV_TXEMPTY))
Get_Error();
COMMTIMEOUTS sTo;
if(GetCommTimeouts(DriverHandle,&sTo)) {
sTo.ReadIntervalTimeout = 100;
sTo.ReadTotalTimeoutConstant = 100 ;
sTo.ReadTotalTimeoutMultiplier = 100;
sTo.WriteTotalTimeoutConstant = 0;
sTo.WriteTotalTimeoutMultiplier = 0;
} else {
return (FALSE);
}
if(!(SetCommTimeouts(DriverHandle, &sTo))) {
Get_Error();
}
return 0;
}
int Com_Port::Close_Comport(HANDLE DriverHandle)
{
if ((DriverHandle==0)||(DriverHandle==INVALID_HANDLE_VALUE)) {
return FALSE;
}
CloseHandle (DriverHandle);
return TRUE;
}
int Com_Port::Write_Comport (HANDLE DriverHandle, DWORD NumBytes, void *Buffer)
{
DWORD BytesWritten;
BOOL status;
if ((DriverHandle==0) || (DriverHandle==INVALID_HANDLE_VALUE)) {
return FALSE;
}
status=WriteFile(DriverHandle,Buffer,NumBytes,&BytesWritten,0);
return TRUE;
}
int Com_Port::Read_Comport(HANDLE DriverHandle,DWORD * BytesRead,DWORD BufferSize,void *Buffer)
{
COMSTAT Our_Comstat;
if ((DriverHandle==0) || (DriverHandle==INVALID_HANDLE_VALUE)) {
return (FALSE);
}
ClearCommError (DriverHandle,&Com_Errors,&Our_Comstat);
cout << "QUE: " << Our_Comstat.cbInQue << endl;
if (Our_Comstat.cbInQue > 0) {
if (Our_Comstat.cbInQue > BufferSize) {
BytesToRead=BufferSize;
} else {
BytesToRead=Our_Comstat.cbInQue;
}
if (!ReadFile (DriverHandle, Buffer, BytesToRead, BytesRead, NULL)) {
cout << "Read FAIL!\n";
}
} else {
*BytesRead = 0;
}
return TRUE;
}
int Com_Port::Get_Error()
{
Com_Errors= etLastError();
cout << "An error occured: " << GetLastError() << endl << endl;
return 0;
}
unsigned int Com_Port::Port_No=0;
int Com_Port::Init_ELM () {
cout << "Searching ComPort, please wait. \n\n";
do {
Port_No ++;
DriverHandle = Open_Comport (Port_No);
} while(!DriverHandle && Port_No != 5);
if (!DriverHandle) {
cout << "Unable to open port" << endl;
return 0;
}
cout << "Connected on " << Com_Name << endl;
Config_ComPort(DriverHandle, 9600);
ComHandle=DriverHandle;
return 0;
}
unsigned char CRC(void)
{
unsigned char msg_buf[20], nBytes=0;
unsigned char CRC_Reg=0xff;
unsigned char poly,i,j;
unsigned char Checksum=0;
unsigned char *Byte_point, Bit_point;
for (i=0,Byte_point=msg_buf;i {
for (j=0, Bit_point=0x80 ; j<8; j++, Bit_point>>=1) {
if (Bit_point & *Byte_point) {
if (CRC_Reg & 0x80)
poly=1;
else
poly=0x1C;
CRC_Reg= ( (CRC_Reg << 1) | 1)^poly;
} else {
poly=0;
if (CRC_Reg & 0x80)
poly=0x1D;
CRC_Reg= (CRC_Reg << 1)^poly;
}
}
}
return ~CRC_Reg;
}
|
|
|
|
|
Hello,
I have an activeX control project which contains several controls. When you start an AtiveX control project you are allowed to select how many components syou want the project to contain.
What happens now that I want to add more components to this project?Can't seem to find any information elsewhere.
Thanks!
|
|
|
|
|
hello,
I didn't know where to ask so I hope you can help me ...
I want to develop nokia series 60 applications ... and I am using sdk 2.1 with visual studio .net and I don't see a class wizard ... I have downloaded sdk 1.2 who has a wizard for visual studio 6 and it seems that class wizard is still not implemented... or I didn't figure out how to use it ... plizzz can anyone help me ... what IDE should I use to develop this kind of applications or ... what should I do to make visual studio 6 / visual studio.net class wizard works !
thank you ...
|
|
|
|
|
codewarrior with the symbian simulator for nokias...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Hi There,
Does anyone know of a third party software that allows me to do simple graphics (lines, polylines, text, etc...) in an EMF format and be able to drap/drop and edit the images?
I've looked into LEAD Technologies and MetaDraw but they're not exactly what I'm looking for. Ther former doesn't support editing and MetaDraw is a VB OCX, mainly with VB documentation.
Any help in this matter is greatly appreciated.
Thank,
A.
|
|
|
|
|
Hi All
if have a variable
m_e_date = COleDateTime::GetCurrentTime();
which equals the current time,
how do i get it so that its the current time plus 2 hours
similar to DATEADD in SQL
or how do i increase the current time by two hours
so 14:00 would be 16:00
hope that makes sense
|
|
|
|
|
Take a look at COleDateTimeSpan. This should do the trick
|
|
|
|
|
How about:
COleDateTime now = COleDateTime::GetCurrentTime();
now += COleDateTimeSpan(2, 0, 0, 0);
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
DavidCrow wrote:
COleDateTime now = COleDateTime::GetCurrentTime();now += COleDateTimeSpan(2, 0, 0, 0);
superb
|
|
|
|
|
IS there any way check if file exist without attempting to open the file? Just by looking at directory structure?
I am using MFC and trying to open 2 files simultaneously. Each one can't be open unless the other exist.
|
|
|
|
|
PathFileExists() will be helpfull to u.
-prakash
|
|
|
|
|
i use
BOOL bExist;
CFileFind finder;
bExist=finder.FindFile(strDirPath);
if(bExist)
{
finder.FindNextFile();
if(!finder.IsDirectory())
bExist=FALSE;
}
finder.Close();
|
|
|
|
|
There's always the good old CRT function access()....
onwards and upwards...
|
|
|
|
|
See here for a discussion on this common subject.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
hey David,
do you know your links still don't work ???
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
No I didn't. Thanks.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Hey all,
I've got a configuration app to write, and I think that the tree/grid control that the VS.NET 2003 IDE uses for Class properties would be a perfect fit. Anyone know what it's called, or where I can find it?
Here's what I'm talking about:
http://www.saxmanwebs.com/upload/./userfiles/Zin/PropControl.jpg
Thanks!
-Mike Zinni
"Don't take life too seriously, you'll never make it out alive"
- Van Wilder
|
|
|
|
|
I have made a class and I need to use it's subroutines in another class. How do I make these references?
|
|
|
|
|
derive the class from the class that you want to use the member functions is one option.
Depending on the design you can also create an instance of that class whose member function you want to use.
-prakash
|
|
|
|
|
Anonymous wrote:
How do I make these references?
By using either of the member-selection expressions: . or ->
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
tell the class that need to use the other that it is a friend...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Hello everybody,
I've created a dialog with some controls, the controls show a tooltip when hovered over by the mouse. Now when I put the controls in a groupbox, the tooltip is not shown, the program won't even break in debug into the event handler...
We've tried everything, transparent background, taborder, deriving a class from CStatic and so on...
(I use the ON_NOTIFY_EX message)
I also tried to add the groupbox first to the dialog and then the controls into the groupbox (like VC#), but still nothing.
Can somebody point me into the right direction (article or whatever )?
thank you very much for your help.
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
|
|
|
|
|
This same thing happened to me because the group box was obscuring the controls. In times past I've always put the group box in front of the controls, but now I put it behind the controls so that tooltips will work. Why this does not work for you is unclear. Have you examined the dialog template in the .rc file to make sure all of the controls are in the order in which you think they are?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
DavidCrow wrote:
Have you examined the dialog template in the .rc file to make sure all of the controls are in the order in which you think they are
do you mean the resource nr associated with the control name? Yes I did, else I don't really understand what you mean.
I was now looking in the direction of the z-order (SetWindowPos), but I don't seem to be able to understand really how it works (my control just dissappaers, which isn't my purpose)
tnx for the reply though.
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
|
|
|
|
|