Thank's
Now, It appears the following error:
xxxxx.cpp(88) : error C2065: 'setErrMsg' : undeclared identifier
(You say in the code "// NOTE: setErrMsg sets some error message for the class this code belongs to" but , how can I avoid it??)
Printable View
Thank's
Now, It appears the following error:
xxxxx.cpp(88) : error C2065: 'setErrMsg' : undeclared identifier
(You say in the code "// NOTE: setErrMsg sets some error message for the class this code belongs to" but , how can I avoid it??)
my 'NOTE:' was supposed to tell you, that setErrMsg is a function that i implemented somewhere in my class but did not post. you could for example replace each appearance of setErrMsg() with a call to AfxMessageBox().Quote:
Originally Posted by pachas
for example, instead of:
setErrMsg("Serial port could not be initialized. Error while setting communication timeouts.");
you could write:
AfxMessageBox(_T("serial port..."));
Thank's!!!!
It's beginin to run ........ (or that seems to be)
A lot of thank's!!!
you're welcome.Quote:
Originally Posted by pachas
Hi!
I need to read information from a serial device which downloads the information from barcode terminals. The serial mechanism (that is conected to the computer by the COM1 port) downloads the information (arrays of numbers) from the barcode terminal and I have to read it. This mechanism a old one. I'm using the WinCE emulator (and I have configured it).
So I change some lines in the code you (RESET-LEO) give us, but it doesn't read: the array where I read is empty.
I will be very grateful if someone can't find the possible error or give me some advice. The code I have is the following:
Quote:
HANDLE m_hComm; //Gets the operating system file handle for the file that the current FileStream object encapsulates.
// open interface to reader
m_hComm = CreateFile(_T("COM1:"), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if (m_hComm == INVALID_HANDLE_VALUE)
{
AfxMessageBox(TEXT("Serial port could not be opened. Wrong port number?"), MB_OK);
m_hComm = NULL;
return FALSE; // error opening com port
}
else
{
COMMTIMEOUTS noblock; //set and query the time-out parameters for a communications device
DCB dcb; //The DCB structure defines the control setting for a serial communications device.
GetCommTimeouts(m_hComm, &noblock); // get communication timeouts
noblock.ReadTotalTimeoutConstant = 50;// 50 milliseconds timeout
noblock.ReadTotalTimeoutMultiplier = MAXDWORD;
noblock.ReadIntervalTimeout = MAXDWORD;
if (SetCommTimeouts(m_hComm, &noblock) == 0) // set communication timeouts
{
AfxMessageBox(TEXT("Serial port could not be initialized. Error while setting communication timeouts."), MB_OK);
CloseHandle(m_hComm);
m_hComm = NULL;
return FALSE; // error opening com port
}
// Initialize the DCBlength member.
dcb.DCBlength = sizeof (DCB); //MSDN
// set communication state
GetCommState(m_hComm, &dcb);
dcb.BaudRate = 19200;
dcb.fBinary = TRUE;
dcb.ByteSize = 7;
dcb.fParity = TRUE;
dcb.fBinary = TRUE; //MSDN
dcb.Parity = ODDPARITY;
dcb.StopBits = ONESTOPBIT;
dcb.fDtrControl = DTR_CONTROL_ENABLE;//Enables the DTR line when the device is opened and leaves it on.
dcb.fRtsControl = RTS_CONTROL_DISABLE;//Disables the RTS line when the device is opened and leaves it disabled.
if (SetCommState(m_hComm, &dcb) == 0)
{
AfxMessageBox(TEXT("Serial port could not be initialized. Error while setting communication state."), MB_OK);
CloseHandle(m_hComm);
m_hComm = NULL;
return FALSE; // error opening com port
}
CHAR pcVersion[20];
memset(pcVersion, '\0', 20);
DWORD dwByteCount = 0;
if (ReadFile(m_hComm, pcVersion, 20, &dwByteCount, NULL) != 0) //Devuelve !=0 si tiene exito
{
AfxMessageBox(TEXT("Connection to reader established."), MB_OK);
CString str(pcVersion);
AfxMessageBox(str, MB_OK);//IT DOESN'T PRINT ANYTHING
}
}
the only thing i could imagine is that your DCB settings contain a wrong setting. i would suggest to try if you can receive any data using hyperterminal and then coding the settings you chose there into your program (the dcb settings).
Hi!
I am working at something similar.
My problem is this:
I am using the WinCE Emulator in eVC++. In "Platform Manager" I have set the following "Communications":
Ethernet: NAT (Outgoing only)
Serial Port 1: COM4
Serial Port 2: None
Parallel Port: None
I am also using something called "Virtual Serial Port Kit" which allows me to create two virtual serial ports that are connected to each other. These are called COM2 and COM4. By starting two "HyperTerminal" windows I can see that COM2 and COM4 really are connected and both COM2 and COM4 is listed under "ports" in "Device Manager". So I'm pretty sure that the "Virtual Serial Port Kit" works.
When I try to run your (reset-leo) code (or my own which is pretty much the same) using "COM1:" it works fine but not when I use "COM4:" like this:
m_hComm = CreateFile(_T("COM4:"), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_WRITE_THROUGH, NULL);
In this case all I get is:
"Serial port could not be opened. Wrong port number?"
But COM4 should exist!
Any idea what the problem might be?
Very thankful for any help!
hard to find any failure at first sight.
evaluate the error returned by GetLastError() after your call to createfile. maybe you can get some more information on what exactly went wrong.
i assume you did, but anyway i want to remind you that you have to close all existing connections to the serial port before you can open any new. so if you're running hyperterm on com4, close it.
Yes I did. The fact is that when I started eVC++ and the Emulator with the mentioned settings (Serial Port 1: COM4) and then started Hyperterm (COM4) I got the message from hyperterm that "another program is using the service" like I should.Quote:
Originally Posted by reset-leo
And still I get "Serial port could not be opened. Wrong port number?"...
I'll check GetLastError() and report the results.
Btw, thanks for answering so quick. :)
GetLastError():
(55) The specified network resource or device is no longer available, (ERROR_DEV_NOT_EXIST)
So here COM4 does not exist but to hyperterm it does...
oh! now i know what's wrong! :)
your hyperterm connects directly to the local com4 of your desktop machine (which obviously works). BUT the serial port you connect to from the pocket pc emulator is not directly com4, but com1 which is mapped to the local com4 by the platform manager. got it? so simply use the connection to "COM1:" in your eVC++ app.
I tried that but it did not work either. But you got me on a new track so I thought I could try setting "Serial Port 2" to COM4 instead and, like you suggested, use:
m_hComm = CreateFile(_T("COM1:"), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_WRITE_THROUGH, NULL);
And that worked!!!
I don't know why really, but I definently think that you are right about the fact that CreateFile should use the "local" COM1 (which in fact is the real COM4).
But why "Serial Port 1" as COM4 and CreateFile(_T("COM1:")... did not work I can not understand.
Maybe the conclusion is that "Serial Port 2" is "local" COM1, but what is then "Serial Port 1"?
-----
Thanks for all the help! I've struggled with this for quite some time and now I can go home relived! :D
sometimes programming is like a puzzle... good that it works now!Quote:
Originally Posted by LA Kings
And, how can I do this (try if I can receive any data using hyperterminal)?Quote:
Originally Posted by reset-leo
Thank's
runQuote:
Originally Posted by pachas
start->all programs->tools->communication->hyperterminal
if it is not there, install it using windows setup ("software" in control panel).
hyperterminal will then guide you through the steps to establish the communication. you can change the baudrate settings for testing at any time by clicking on the "properties" icon in hyperterminal.