Click to See Complete Forum and Search --> : Serial Port Communication in WinCE Emulator using eVC++


Aravindan
March 9th, 2005, 05:26 AM
Here's my doubt! Iam working on Embedded VC++ and I need to access my
systems Serial Port through Standard SDK WinCE Simulator.
Is it possible? Can you help me out?
Thanks in advance!

reset-leo
March 23rd, 2005, 07:39 AM
Here's my doubt! Iam working on Embedded VC++ and I need to access my
systems Serial Port through Standard SDK WinCE Simulator.
Is it possible? Can you help me out?
Thanks in advance!

here we go:
- select "Configure Platform Manager..." from studio's "tools" menu
- in the treeview (pops up), select the emulator device you are using
- click "Properties..."
- in the "Device Properties" dialog, click "Configure..." next to the "Startup Server" dropdown (strange caption, isn't it? ;) )
- in the "Emulation Configuration Settings" dialog you can configure which serial ports are to be used

Aravindan
March 24th, 2005, 11:33 PM
Thanks ! but I want to know whether it is possible to access the serial ports through eVC++ code .

reset-leo
March 25th, 2005, 01:52 AM
Thanks ! but I want to know whether it is possible to access the serial ports through eVC++ code .

sorry, misunderstood your question...

here is some code that contains everything you need (i assume you're using mfc):


// NOTE: setErrMsg sets some error message for the class this code belongs to

handle m_hComm;

// open interface to reader
m_hComm = CreateFile(_T("COM1:"), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_WRITE_THROUGH, NULL);
if (m_hComm == INVALID_HANDLE_VALUE)
{
setErrMsg("Serial port could not be opened. Wrong port number?");
m_hComm = NULL;
return; // error opening com port
}
else
{
COMMTIMEOUTS noblock;
DCB dcb;

// set communication timeout
GetCommTimeouts(m_hComm, &noblock); // get communication timeouts
// get answer (ReadFile waits for answer until timeout)
// i used this timeouts in this example, because it is easier to handle
// (i do not need any timer)
noblock.ReadTotalTimeoutConstant = 50; // 50 milliseconds timeout
noblock.ReadTotalTimeoutMultiplier = MAXDWORD;
noblock.ReadIntervalTimeout = MAXDWORD;
if (SetCommTimeouts(m_hComm, &noblock) == 0) // set communication timeouts
{
setErrMsg("Serial port could not be initialized. Error while setting communication timeouts.");
CloseHandle(m_hComm);
m_hComm = NULL;
return; // error opening com port
}

// set communication state
GetCommState(m_hComm, & dcb);
dcb.BaudRate = 9600;
dcb.ByteSize = 8;
dcb.fParity = FALSE;
dcb.StopBits = ONESTOPBIT;
dcb.fDtrControl = DTR_CONTROL_ENABLE;
dcb.fRtsControl = RTS_CONTROL_DISABLE;

if (SetCommState(m_hComm, &dcb) == 0)
{
setErrMsg("Serial port could not be initialized. Error while setting communication state.");
CloseHandle(m_hComm);
m_hComm = NULL;
return; // error opening com port
}

CHAR pcVersion[20];
memset(pcVersion, '\0', 20);
DWORD dwByteCount = 0;
if (ReadFile(m_hComm, pcVersion, 20, &dwByteCount, NULL) != 0)
{
setErrMsg("Connection to reader established.");
}

WriteFile(m_hComm, "S", 1, &dwByteCount, NULL); // stop the scanmode ????
ReadFile(m_hComm, pcVersion, 20, &dwByteCount, NULL); // read the firmware version

if (strncmp(pcVersion, "ISO", 3) != 0)
{
setErrMsg("An der angegebenen Schnittstelle ist kein Reader angeschlossen.");
CloseHandle(m_hComm);
m_hComm = NULL;
return; // error opening com port
}
}


i think setting the timeouts is not necessary, but it may be helpful if your communicating with slow devices or whatever.

most important for the serial communication:
- CreateFile (don't forget the ":" in "COM1:")
- SetCommState
- ReadFile
- WriteFile
- CloseHandle

look them up in msdn to see what they do exactly

Aravindan
March 29th, 2005, 11:19 PM
Thanks a lot for ur effort. Unfortunately I am not using MFC here. Is there a way to accomplish that without using MFC ?

reset-leo
March 30th, 2005, 12:41 AM
any more important details before i think about an answer to your question? ;)

Aravindan
March 30th, 2005, 06:23 AM
HI Leo!

What does "An der angegebenen Schnittstelle ist kein Reader angeschlossen." mean?
Its given in the final version check in your code.

Thanks,
Aravind.

reset-leo
March 30th, 2005, 06:28 AM
HI Leo!

What does "An der angegebenen Schnittstelle ist kein Reader angeschlossen." mean?
Its given in the final version check in your code.

Thanks,
Aravind.

oops... that's german and it means "There's no reader connected to the given interface" where reader means the device i'm trying to communicate with.

i hope this helps :p

i did not yet have the time to look for a non-mfc way of using the com-port, sorry for that. maybe there's some kind of stream (like the standard-streams "cin" and "cout") for that?

Aravindan
March 30th, 2005, 07:07 AM
Hi Leo,

Thanks for your quick response man!
MFC is fine.
All i need to do is to access the computers serial port in a WCE application created through eMbedded VC++.
The program is run in 'Win32(WCE emulator) Debug ' in
"STANDARDSDK Emulator"

Regards,
Aravind.

reset-leo
March 30th, 2005, 07:14 AM
does this mean that you are satisfied with the code sample i gave you, or do you still need some more information :confused:

Aravindan
March 31st, 2005, 07:02 AM
Thanks a lot mate! Ur code is fine!

reset-leo
March 31st, 2005, 07:03 AM
Thanks a lot mate! Ur code is fine!

you are welcome :wave:

Aravindan
March 31st, 2005, 07:05 AM
Can u send me ur email id?
mine is : aravindtherock AT yahoo DOT com

pachas
April 1st, 2005, 03:52 AM
Hi!
I'm trying to do something similar in eMbedded Visual C++.
Is it the same code?
Where must I put it??? In wich class (xxxxxxApp or xxxxxxDlg)??? (I want to create a dialog).

I'm compiling it but it gives me a lot of errors beginning for the 'handle' expresion.
Please, reply ASAP. A lot of Thanks!

reset-leo
April 1st, 2005, 04:17 AM
Hi!
I'm trying to do something similar in eMbedded Visual C++.
Is it the same code?
Where must I put it??? In wich class (xxxxxxApp or xxxxxxDlg)??? (I want to create a dialog).

I'm compiling it but it gives me a lot of errors beginning for the 'handle' expresion.
Please, reply ASAP. A lot of Thanks!

the code i posted is for embedded vc++.

in order to get this code running, it is necessary, that your project supports MFC! you should enable mfc support while you create the project using the project wizard. of course, you could add mfc support at any time, but don't ask me which includes and libraries you need...

concerning your 'handle' problem: i just had a look into my code and recognized, that i wrote 'HANDLE' (capital letters). try it.
if this doesn't help, you may be missing mfc (HANDLE is defined in winnt.h which is included with the mfc support - as far as i remember...).

to answer your question where to put the code: it depends. i would suggest to put all functions which deal with communication through the serial port into one class and then including and instantiating that one whenever you need it.
for example, i put all my functions to connect to, read from, write to, close the connection to my serial device into one class. then i added an object of that class to my App as a public member, so i can access the device from anywhere in my code using AfxGetApp()->m_myDeviceObject.<any function>.

pachas
April 1st, 2005, 04:48 AM
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??)

reset-leo
April 1st, 2005, 04:53 AM
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().

for example, instead of:
setErrMsg("Serial port could not be initialized. Error while setting communication timeouts.");
you could write:
AfxMessageBox(_T("serial port..."));

pachas
April 1st, 2005, 05:12 AM
Thank's!!!!
It's beginin to run ........ (or that seems to be)
A lot of thank's!!!

reset-leo
April 1st, 2005, 06:02 AM
A lot of thank's!!!

you're welcome.

pachas
April 4th, 2005, 11:26 AM
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:


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
}

}

reset-leo
April 5th, 2005, 03:45 AM
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).

LA Kings
April 6th, 2005, 08:03 AM
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!

reset-leo
April 6th, 2005, 08:30 AM
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.

LA Kings
April 6th, 2005, 08:45 AM
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.

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. :)

LA Kings
April 6th, 2005, 09:00 AM
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...

reset-leo
April 6th, 2005, 09:10 AM
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.

LA Kings
April 6th, 2005, 09:52 AM
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

reset-leo
April 6th, 2005, 10:33 AM
Maybe the conclusion is that "Serial Port 2" is "local" COM1, but what is then "Serial Port 1"?

sometimes programming is like a puzzle... good that it works now!

pachas
April 6th, 2005, 11:33 AM
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).

And, how can I do this (try if I can receive any data using hyperterminal)?
Thank's

reset-leo
April 6th, 2005, 11:43 AM
And, how can I do this (try if I can receive any data using hyperterminal)?
Thank's

run
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.

chaps5555
April 7th, 2005, 07:09 AM
Sir,
I had an query on this program, I tried to execute this program onto my device but it is not working , is this only meant for emulators?

Regards

Naveen

reset-leo
April 7th, 2005, 07:27 AM
Sir,
I had an query on this program, I tried to execute this program onto my device but it is not working , is this only meant for emulators?

Regards

Naveen

not only for emulators, but should also work on any windows ce based device. what exactly is happening?

chaps5555
April 7th, 2005, 07:44 AM
First i want to tell u it is working fine with emulator. I have got pocket pc 2002 which has got serial port with its cradle.I want to acces the serial port and send and receive data from my hardware device . when i am debugging it on my device it is not able to read any thing.wht reallt hapeens if i senpto my device it responds with p back that shows transmission has occured . but when i am sending p it is not returning anyhting.but if i use it with emulator it is working fine.

What can be the problem.

Regards

Naveen

reset-leo
April 7th, 2005, 07:54 AM
it's hard to tell what's wrong as i know nothing about the devices you're using.

again, i suggest to check all the settings in the code (DCB, ...) as well as the settings of the devices. i also recommend in such cases, to download some terminal application for wince and try how that one is behaving (search google for "vxHpc", there's a free trial download).

i could also imagine that there's some hardware incompatibility between the handheld and you device...

chaps5555
April 7th, 2005, 08:02 AM
what is vxHpc? how will it help me.Can you tell me in my program i am opening Com1 that is com1 for my cpu that i through emulator.I attach me harware with a serial cable between my transreceiver and my pc ' Com1 which i am am opening through the program.But when i am downloading same program on real device wht should be the port number how will it recognise the cradles serial port.As i tried com1 to com40

UI am sending u piece of code

port.OpenPort("com1");
port.ConfigurePort(CBR_38400,8,0,NOPARITY ,ONESTOPBIT );
unsigned char data;
label1:


port.WriteByte('p');
port.WriteByte('q');
port.WriteByte('r');
::Sleep(5);
port.ReadByte(data);
port.ReadByte(data);
port.ReadByte(data);


at open .port i am opening com1 what should i write for pocket pc device 2002.

Regards

Naveen

reset-leo
April 7th, 2005, 08:14 AM
first of all, your code did not help me much, as you seem to be using some (custom) software components that i don't know. what i'm trying to say is: what kind of object is your "port"????? :confused:

which com port you should use on your handheld device depends on the device itself! i dealt with devices where the port was no. 1, on others it was 6...

vxHpc is a terminal program that let's you connect via serial interface and send/receive characters (i.e. you type "p" and see what the other device returns).

!!!!!!!!! generally spoken, and that's true for everyone who's dealing with serial communication, YOU WILL NEED A TERMINAL PROGRAM AND MUST KNOW HOW TO USE IT! otherwise, finding errors will be very very hard at certain points. !!!!!!!!

finally, did you connect the device you're trying to communicate with directly to your handheld (or it's cradle), or did you try to connect to the device while it is connected to your cpu?

/miaou :sick:

chaps5555
April 7th, 2005, 08:21 AM
i tried to connect the device ( it is juz a transreceiver with serial port with it.)directly to the cradle which has got serial port .My handheld dont have serial port its cradle has. i am not able to check wht is it number also is it com1 2 , or anyhting.

Regards

Naveen

reset-leo
April 7th, 2005, 08:29 AM
i tried to connect the device ( it is juz a transreceiver with serial port with it.)directly to the cradle which has got serial port .My handheld dont have serial port its cradle has. i am not able to check wht is it number also is it com1 2 , or anyhting.

Regards

Naveen

again: try to connect to the device using a terminal program. when you were able to connect with the terminal program, continue testing with you self-written app.

chaps5555
April 7th, 2005, 08:46 AM
i am trying to connect the device through terminal program , it is juz showing intializing and not moving ahead .

regards

naveen

reset-leo
April 7th, 2005, 09:01 AM
i am trying to connect the device through terminal program , it is juz showing intializing and not moving ahead .

regards

naveen

well, then there's something wrong in your serial connection.

unfortunately, i don't think i can help you with this as i don't have the hardware you're using on my desk... consult the documentation of your devices for any further hints or search the web for some info on your transmitter.

sorry that i can not help you on that issue, but feel free to ask anything when you've got any questions concerning the code.

chaps5555
April 7th, 2005, 11:37 PM
can i use the terminal program with my pocket pc and another pc wich does not have active sync.


regards

naveen

chaps5555
April 8th, 2005, 01:29 AM
hey it worked

the code is really good but u require an additional hardware i.e null modem cable between pda serial port and the device .

http://www.waterlog.com/App%20Notes/Pocket%20PC/Pocket_PC_Introduction.html


i am posting that this thread helps guyz in future.

And thanks to reset -leo for his generous help and support.

Regards

Naveen

reset-leo
April 8th, 2005, 02:15 AM
hey it worked

the code is really good but u require an additional hardware i.e null modem cable between pda serial port and the device .

http://www.waterlog.com/App%20Notes/Pocket%20PC/Pocket_PC_Introduction.html


i am posting that this thread helps guyz in future.

And thanks to reset -leo for his generous help and support.

Regards

Naveen

i knew that there was something wrong with the serial connection... :cool:

your welcome!

V3N7UR4
April 26th, 2005, 04:56 PM
Hi,

I have a similar problem., but with some changes.

I need to comunicate through the serial connection of my PPC.
But i dont want to comunicate with the COM port of any PC or device.

I will have one switch (on/off, open/close) connected into my PPC (qtek 2020) through it's serial connection.

I just want to know if the switch is opened or closed.

Will i have to use the same code?? Open, read, write, close the COM port???

If i understood what all you had been saying, when you say Open, read, write, close the COM port you are talking about the PC COM port, not the PPC COM port, right???

Any one can help??

Thanks in advance,

Ventura

reset-leo
April 27th, 2005, 02:50 AM
I need to comunicate through the serial connection of my PPC.
But i dont want to comunicate with the COM port of any PC or device.

I will have one switch (on/off, open/close) connected into my PPC (qtek 2020) through it's serial connection.

I just want to know if the switch is opened or closed.

Will i have to use the same code?? Open, read, write, close the COM port???

If i understood what all you had been saying, when you say Open, read, write, close the COM port you are talking about the PC COM port, not the PPC COM port, right???


we were talking about the com (serial) port of the ppc. using mfc, there is no difference in the function calls to open, read, write, ... between pc and ppc.

i think what may work is to connect one side of the switch to the tx pin of the serial port and the other side to the rx pin. then you send one character on the serial port (using Write()) and immediately call Read(). if read returns the character you sent, the switch is closed. if nothing is received, the switch is open!

i can in no way guarantee that this works, but it's the easiest thing i can imagine. of course, you may need some more electronics to connect the switch to the serial port, but i can not help you with that... don't blame me if you blow up your ppc's com port with such experiments ;)

V3N7UR4
April 27th, 2005, 08:56 AM
Hi,

Many thanks for your quick reply reset-leo.

What i will have to trigger is something like this: http://www.beyondlogic.org/serial/serial.htm

I supose those values are for a desktop PC. If someone known the same values but for PPC, i'll be gratefull.

Ventura

reset-leo
April 27th, 2005, 09:34 AM
if you only want to connect a switch, then (according to the document you sent) you should simply build a loopback plug where you put the switch into the connection between the send- and the receive cable.
i don't know what is your final goal in this, but for testing only, i would suggest to build this loopback device from scratch using a plug and some wires. then leave the ends of the wires connected to the rx and tx pin open (the switch is open) or put the open ends together (the switch is closed).
as i said, and as the document sais, if you put the wire-ends together to close the loop, you should be able to receive what you've sent immediately.

as long as you don't connect any power supplies to some of the pins in your cabeling, there should also be no damage to the com port...

btw: how would you connect to the device? does it offer a sub-d plug on a cradle or will you use the cf-slot? or something else?

V3N7UR4
April 28th, 2005, 09:04 AM
Well, i'll try to explain the final goal.

I need to develop one dll using evc++. This dll will have to trigger the beavoir of one or to switches connected to my Qteck 2020 throught it's serial port.
I think DTR or CTS have one property like "enable" or "true" which means that some voltage are supplied to that pin.
I think i just have to develop a thread to continually watch some pins.
If the switch is closed, there are voltage. If the switch is open no voltage at that pin.

Something like i found here: http://www.control.com/1026195756/index_html

Clear??? Or not?? :)

reset-leo
May 2nd, 2005, 06:15 AM
sorry for the late reply...

through DTR and CTS it may be possible as well. if your switches are connected to that pins (mind the correct voltage as described in the first link you posted!), you could continously call GetCommState() and check the values of the DCB structure.

V3N7UR4
May 9th, 2005, 08:31 PM
OK,

Many thanks for your replys reset-leo.

Now... another not expected realy BIG PROBLEM.
Unfortunely i was stolen!! My Qtek 2020 has now another owner... Shuinf!! :.(

Forget it!!

Is it possible to simulate the open/close state of the switches in the emulator???
Should i connect the switch to the COM port of my desktop and use it to simulate with de emulator of the evc++???

Will it work??

Many thanks!!!

Ventura

reset-leo
May 10th, 2005, 02:58 AM
Is it possible to simulate the open/close state of the switches in the emulator???
Should i connect the switch to the COM port of my desktop and use it to simulate with de emulator of the evc++???

yes, that should work. refer to my very first reply to this thread, where i explain how to configure the emulator to use the pc's com ports.

i would also suggest to put a spell on the evil minded hardware-napper!!!

switcher
May 17th, 2005, 01:31 PM
Hi

I am having some problems working with the WinCe emulator.
I need it to communicate over serial interface RS232.
The basic communication works fine, readfile/writefile.
The problem is that I need the functionality of waitComEvent, this works fine with comEventMask set to EV_RXCHAR, but I need the mask to be EV_BREAK.
I cant get this to work, the waitComEvent will not return.

Anybody have any ideas or suggestions?

/switcher

gulamehind
June 21st, 2005, 09:30 PM
Hello,

I using wince 4.2 device terminal, an bluetooth usb adapter and a bluetooth enabled mobile printer device. I am using c#.net, coredll.dll(p/invoke). The mobile printer is running serial port service(standard serial port (SPP)device via bluetooth link).

I want to connect to the mobile printer from the device using bluetooth USB adapter.

I checked the boot peripheral setup settings. There are onboard 3 serial ports and all the three are being used.

OnBoard Serial Port1 2F8h/COM2
OnBoard Serial Port2 3F8h/COM1
OnBoard Serial Port3 3E8h/COM4

Available options for OnBoard Serial Port assignment are:
Auto
Disabled
3F8h/COM1
2F8h/COM2
3E8h/COM3
2E8h/COM4

1) I want to figure out if i can connect from the device terminal to printer using Bluetooth USB adapter on serial port. The device does not support active sync. It does not have any input/output for serial cable. It has two USBs to connect keyboard etc. I am using one of these USB for the Bluetooth USB adapter. There is a scale down version of bluetooth monitor which only allows me to serach the bluetooth devices around and creating a bond. There is not software feature which allows to connect serially to bluetooth enable printer device.

2) From c#.net i make calls to coredll.dll functions CreateFile, WriteFile and ReadFile

CreateFile returns me the handle, but WriteFile returns runtime error 1359(unable to write to COM3).

3) Opening ports and writing on these is second step. I am unable to figure out how to connect to the device to the printer(on serial port).

I used RegisterDevice function call(coredll.dll) and passed the printer address with COM7(no other COM# returns handle). This properly returns an handle.

Please help me.

Thanks and regards,

Gulame

reset-leo
June 22nd, 2005, 02:27 AM
hi!

first of all, i don't have any experience in programming for bluetooth devices. but i could imagine that there is some special api for accessing devices in the bluetooth network and would suggest to search msdn for such things.
also, i would search the internet if there are any apis for the usb bluetooth device you are using, or if there is a "virtual com port" driver for your combination of printer/bluetooth enabled device.

gulamehind
June 22nd, 2005, 07:40 PM
Hello,

Thanks for your reply and suggestion.
I will search msdn for the api.
If you find any apis, please write to me.

With best regards,

Gulame

santoshvoonna
September 24th, 2005, 06:35 AM
Hi Reset leo,
I , Santosh kumar here with sending the problem with serial port programming using eVC.

Problem ::
Using CreateFile, SetCommTimeouts, GetCommstate, setCommstate, Writefile.

IDE : EVC 4.0 (witn SP2)

I cant able to read from the other side with Hiperterminal. One PC is running with the application which is written using EVC IDE and communicating with the other PC, which is using hiperterminal.

Project settings :: WINCE Emulator debug
Project is MFC application wizard(EXE)

reset-leo
September 26th, 2005, 04:21 AM
Hi Reset leo,
I , Santosh kumar here with sending the problem with serial port programming using eVC.

Problem ::
Using CreateFile, SetCommTimeouts, GetCommstate, setCommstate, Writefile.

IDE : EVC 4.0 (witn SP2)

I cant able to read from the other side with Hiperterminal. One PC is running with the application which is written using EVC IDE and communicating with the other PC, which is using hiperterminal.

Project settings :: WINCE Emulator debug
Project is MFC application wizard(EXE)

hi!

there are a few things you may check:
- is your configuration of the emulator com-ports correct
- you must use a cross-over serial cable (= "null-modem" cable) to connect the two pc's
- you must set the same settings for baudrate, data bits, stop bits and parity in both, you embedded app (setcommstate) and on hyperterminal

i hope this helps.

santoshvoonna
September 26th, 2005, 05:05 AM
Hi,
Thanks for your quick reply.

- I checked with 2 hipertrminals connected with null modem cable (Working fine)
- I changed the platform manager settings to use COM1

- I am giving the code that I am using ::


void ReadFromCom()
{
// NOTE: setErrMsg sets some error message for the class this code belongs to
HANDLE m_hComm;
// open interface to reader
m_hComm = CreateFile(_T("COM1:"), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_WRITE_THROUGH, NULL);
if (m_hComm == INVALID_HANDLE_VALUE)
{
//setErrMsg("Serial port could not be opened. Wrong port number?");
m_hComm = NULL;
return; // error opening com port
}
else
{
COMMTIMEOUTS noblock;
DCB dcb;

// set communication timeout
GetCommTimeouts(m_hComm, &noblock); // get communication timeouts
// get answer (ReadFile waits for answer until timeout)
// i used this timeouts in this example, because it is easier to handle
// (i do not need any timer)
noblock.ReadTotalTimeoutConstant = 50; // 50 milliseconds timeout
noblock.ReadTotalTimeoutMultiplier = MAXDWORD;
noblock.ReadIntervalTimeout = MAXDWORD;
if (SetCommTimeouts(m_hComm, &noblock) == 0) // set communication timeouts
{
//setErrMsg("Serial port could not be initialized. Error while setting communication timeouts.");
CloseHandle(m_hComm);
m_hComm = NULL;
return; // error opening com port
}

// set communication state
GetCommState(m_hComm, & dcb);
dcb.BaudRate = 9600;
dcb.ByteSize = 8;
dcb.fParity = FALSE;
dcb.StopBits = ONESTOPBIT;
dcb.fDtrControl = DTR_CONTROL_ENABLE;
dcb.fRtsControl = RTS_CONTROL_DISABLE;

if (SetCommState(m_hComm, &dcb) == 0)
{
//setErrMsg("Serial port could not be initialized. Error while setting communication state.");
CloseHandle(m_hComm);
m_hComm = NULL;
return; // error opening com port
}

CHAR pcVersion[20];
DWORD dwByteCount = 0;
#if 0

memset(pcVersion, '\0', 20);

while(1)
{
if (ReadFile(m_hComm, pcVersion, 20, &dwByteCount, NULL) != 0)
{
if(dwByteCount)
{
//Success case
//setErrMsg("Connection to reader established.");
int i;
AfxMessageBox(_T("Connection to reader established."));
i = GetLastError();
i++;
}
}
}
#endif


if(!WriteFile(m_hComm, "S", 1, &dwByteCount, NULL)) // stop the scanmode ????
{
//Failure case
int i;
i = GetLastError();
}
#if 0
ReadFile(m_hComm, pcVersion, 20, &dwByteCount, NULL); // read the firmware version
#endif

if (strncmp(pcVersion, "ISO", 3) != 0)
{
//setErrMsg("An der angegebenen Schnittstelle ist kein Reader angeschlossen.");
CloseHandle(m_hComm);
m_hComm = NULL;
return; // error opening com port
}
}
}

Everything is getting succeeded. But the problem is that I cant able to receive the data at the other PC which is opened with hiperterminal.

- Is there any problem with the code ???
- Do I need to change any preconfiguration settings??
- Can I access serial port using evc and this MFC project ???
Please test it if it is possible for u.
Awaiting yor reply,
Santosh Kumar Voona(santu_voonna@yahoo.com)

reset-leo
September 26th, 2005, 06:10 AM
well, the only thing i can imagine is that you may have to set

dcb.fDtrControl = DTR_CONTROL_DISABLE;

(this is something i did because of the device i am using)

i'm sorry i can't test you code. i'm too busy...

santoshvoonna
September 26th, 2005, 07:16 AM
Hi Reset Leo,
I tried out all possibilities with the code. But it is not working.
Do I need to install platform builder for serial port communication.
Bye,
Santosh Kumar Voonna.

reset-leo
September 26th, 2005, 07:27 AM
your code seems all right. still, i think that something in your hyperterminal configuration might be wrong.
did you already step through your code using the debugger? if writefile is executed without errors, then it's likely that there is a problem with the hyperterminal. you could also try using a terminal program which is capable of showing hex-formatted data (check out http://www.der-hammer.info/terminal/). maybe something is corrupted while communication and hyperterminal can't display it... that's only speculations.

on my machine, it works without platform builder.

santoshvoonna
September 26th, 2005, 10:14 PM
Hi Leo,
Here in my machine, i selected com1 for emulator configuration settings.
When wince emulator is coming up it is wrting some data in to com port. But if I execute my program WriteFile is getting succeeded by setting the number of bytes written to proper value. But at the other side it is not displaying anything.
Please let me know if any preconfiguration settings are required for this. Please give your mail id if there is no problem, so that I can send my entire project to there.

Regards,
Santosh Kumar Voonna.

santoshvoonna
September 26th, 2005, 10:35 PM
Hi Leo,
Here in my machine, i selected com1 for emulator configuration settings.
When wince emulator is coming up it is wrting some data in to com port. But if I execute my program WriteFile is getting succeeded by setting the number of bytes written to proper value. But at the other side it is not displaying anything.
Please let me know if any preconfiguration settings are required for this. Please give your mail id if there is no problem, so that I can send my entire project to there.

Regards,
Santosh Kumar Voonna.

reset-leo
September 27th, 2005, 03:51 AM
Hi Leo,
Here in my machine, i selected com1 for emulator configuration settings.
When wince emulator is coming up it is wrting some data in to com port. But if I execute my program WriteFile is getting succeeded by setting the number of bytes written to proper value. But at the other side it is not displaying anything.
Please let me know if any preconfiguration settings are required for this. Please give your mail id if there is no problem, so that I can send my entire project to there.

Regards,
Santosh Kumar Voonna.

try to set the emulator com port 1 to "file:" and see if something is written then. if that works, there must be something wrong in the serial port configuration settings you specify in hyperterminal.
still, i'm quite sure that there actually IS something wrong with those settings. maybe you could post a screenshot of the hyperterminal properties-screen?

don't be angry, but i don't have the time to debug your project...

santoshvoonna
September 28th, 2005, 05:23 AM
Hi Leo,
Since this is the fist time, I am not sure whether the way I am creating and executing the application is correct or not. Anyhow I am explaining the way I am creating the project and executing it. Please check and let me know if there is any problem in the process.

- Creating empty MFC project(Document based).
- Creating one menu item (ConfigAndReadFromComm) using resource.
- Adding the code as a handler for the menu item
- Building the project (With WINCE emulator debug option)
- Directly executing.

- Main thing is that every API is returning success and Write file is setting no of bytes written correctly.

- If I configure the platform mgr com settings to COM1
Whenever WINCE .NET image is coming up some data it is writing to comm port. Same behaviour I can observe if I click/move my mouse pointer on the document of the WIN CE application. Some data which i cant able to understand at all

- Finally
If I set the serial conf option to "file:" then I can see some statements over there. But those statements also I cant able to understand. Please look at the first few lines of the file


Debug Serial Init

SysInit: GDTBase=808b0040 IDTBase=808b94a0 KData=808c1800
Windows CE Kernel for i486 Built on Dec 16 2001 at 18:18:13
g_PageDir = 808c2000
RTC - Status Reg B - 0x02
X86Init done.
Checking if CPU = emulator...
Yes - CPU = emulator
Checking if CPU = emulator...
Yes - CPU = emulator
SENDING command id 0xE100 to CWinApp target.
SENDING command id 0xE100 to CWinApp target.
SENDING command id 0xE101 to CWinApp target.
SENDING command id 0xE103 to CSerTest4Doc target.
No handler for command ID 0xE123, disabling it.
No handler for command ID 0xE122, disabling it.
No handler for command ID 0xE125, disabling it.
SENDING command id 0xE140 to CWinApp target.
SENDING command id 0xE100 to CWinApp target.
SENDING command id 0xE101 to CWinApp target.
SENDING command id 0xE103 to CSerTest4Doc target.
No handler for command ID 0xE123, disabling it.
No handler for command ID 0xE122, disabling it.
No handler for command ID 0xE125, disabling it.
SENDING command id 0xE140 to CWinApp target.
SENDING command id 0xE100 to CWinApp target.
SENDING command id 0xE101 to CWinApp target.
SENDING command id 0xE103 to CSerTest4Doc target.
No handler for command ID 0xE123, disabling it.
No handler for command ID 0xE122, disabling it.
No handler for command ID 0xE125, disabling it.
SENDING command id 0xE140 to CWinApp target.
SENDING command id 0xE100 to CWinApp target.
SENDING command id 0xE101 to CWinApp target.

Awaiting your reply.

Regards,
Santosh Kumar Voonna.

reset-leo
September 28th, 2005, 06:02 AM
santosh, i'm sorry that i have to say that i have no idea of what could be wrong except that you could still be having a problem in the communication settings of hyperterminal... i still got no information from you on which settings you are actually using!

santoshvoonna
September 28th, 2005, 06:21 AM
Hi Leo,
Since this is the fist time, I am not sure whether the way I am creating and executing the application is correct or not. Anyhow I am explaining the way I am creating the project and executing it. Please check and let me know if there is any problem in the process.

- Creating empty MFC project(Document based).
- Creating one menu item (ConfigAndReadFromComm) using resource.
- Adding the code as a handler for the menu item
- Building the project (With WINCE emulator debug option)
- Directly executing.

- Main thing is that every API is returning success and Write file is setting no of bytes written correctly.

- If I configure the platform mgr com settings to COM1
Whenever WINCE .NET image is coming up some data it is writing to comm port. Same behaviour I can observe if I click/move my mouse pointer on the document of the WIN CE application. Some data which i cant able to understand at all

- Finally
If I set the serial conf option to "file:" then I can see some statements over there. But those statements also I cant able to understand. Please look at the first few lines of the file


Debug Serial Init

SysInit: GDTBase=808b0040 IDTBase=808b94a0 KData=808c1800
Windows CE Kernel for i486 Built on Dec 16 2001 at 18:18:13
g_PageDir = 808c2000
RTC - Status Reg B - 0x02
X86Init done.
Checking if CPU = emulator...
Yes - CPU = emulator
Checking if CPU = emulator...
Yes - CPU = emulator
SENDING command id 0xE100 to CWinApp target.
SENDING command id 0xE100 to CWinApp target.
SENDING command id 0xE101 to CWinApp target.
SENDING command id 0xE103 to CSerTest4Doc target.
No handler for command ID 0xE123, disabling it.
No handler for command ID 0xE122, disabling it.
No handler for command ID 0xE125, disabling it.
SENDING command id 0xE140 to CWinApp target.
SENDING command id 0xE100 to CWinApp target.
SENDING command id 0xE101 to CWinApp target.
SENDING command id 0xE103 to CSerTest4Doc target.
No handler for command ID 0xE123, disabling it.
No handler for command ID 0xE122, disabling it.
No handler for command ID 0xE125, disabling it.
SENDING command id 0xE140 to CWinApp target.
SENDING command id 0xE100 to CWinApp target.
SENDING command id 0xE101 to CWinApp target.
SENDING command id 0xE103 to CSerTest4Doc target.
No handler for command ID 0xE123, disabling it.
No handler for command ID 0xE122, disabling it.
No handler for command ID 0xE125, disabling it.
SENDING command id 0xE140 to CWinApp target.
SENDING command id 0xE100 to CWinApp target.
SENDING command id 0xE101 to CWinApp target.

Awaiting your reply.

Regards,
Santosh Kumar Voonna.

zzipp
May 25th, 2006, 09:30 AM
Hi,

I have some problems with my WinCe Pocket PC PDA: I must connect a USB device to the PDA to get some information from it by sending an AT command and reading the response.

The first problem is that the USB device manufacturer provides several driver DLL's and I am not sure which is the correct one for my iPAQ (ARM, MIPS, PPC, SHx and x86 are the possibilities, I have chosen PPC, 403 instead of 821, two more possibilities, but I don't really know about them).

Once I have copied the DLL to the PDA '/Window' directory, I plug in the USB device to the PDA and a dialog is supposed to appear to ask me for the DLL the PDA needs, the one copied before. No dialog appears, the PDA seems not to recognize the USB device, should it show anything when you plug in a USB device? May it be because the USB device need some power supply that the PDA can not give?

Another problem is to access to the COM port, I have installed a 'registry manager' and the USB serial port seems to be 'COM5:', so use the code given here to access to this port in CreateFile.

In the code appears:
-------------------------------------------------------------------------------------
CHAR pcVersion[20];
memset(pcVersion, '\0', 20);
DWORD dwByteCount = 0;
if (ReadFile(m_hComm, pcVersion, 20, &dwByteCount, NULL) != 0)
{
setErrMsg("Connection to reader established.");
}

WriteFile(m_hComm, "S", 1, &dwByteCount, NULL); // stop the scanmode ????
ReadFile(m_hComm, pcVersion, 20, &dwByteCount, NULL); // read the firmware version
-------------------------------------------------------------------------------------
The message "Connection to reader established" appears, but dwByteCount = 0. I have tried to modify the code to send an AT command and read the response:
------------------------------------------------------------------------------------
int writeOK = WriteFile(m_hComm, _T("at+L4"), 4, &dwByteCount, NULL);
int readOK = ReadFile(m_hComm, pcVersion, 4, &dwByteCount, NULL);
------------------------------------------------------------------------------------
writeOK != 0 (so it writes ok, doesn't it?) and dwByteCount = 4
readOK != 0 but dwByteCount = 0, so no data is read!!!!

I don't know if my PDA recognizes the USB device, if it can open the USB port and write but not read, or the device is not recognized and the write is wrong, so no read is possible...

I have installed the vxHpc in the PDA, and connected it to the USB port. I have tried to write something to see the response, but nothing seems to happen when I use the keyboard (nothing on screen and the cursor does not move!!!)

I would be greatful with any help, 'cause I am really stuck on it...

Thanks in advance