|
-
March 9th, 2005, 06:26 AM
#1
Serial Port Communication in WinCE Emulator using eVC++
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!
-
March 23rd, 2005, 08:39 AM
#2
Re: Serial Port Communication in WinCE Emulator using eVC++
 Originally Posted by Aravindan
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
-
March 25th, 2005, 12:33 AM
#3
Re: Serial Port Communication in WinCE Emulator using eVC++
Thanks ! but I want to know whether it is possible to access the serial ports through eVC++ code .
-
March 25th, 2005, 02:52 AM
#4
Re: Serial Port Communication in WinCE Emulator using eVC++
 Originally Posted by Aravindan
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):
Code:
// 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
-
March 30th, 2005, 12:19 AM
#5
Re: Serial Port Communication in WinCE Emulator using eVC++
Thanks a lot for ur effort. Unfortunately I am not using MFC here. Is there a way to accomplish that without using MFC ?
-
March 30th, 2005, 01:41 AM
#6
Re: Serial Port Communication in WinCE Emulator using eVC++
any more important details before i think about an answer to your question?
-
March 30th, 2005, 07:23 AM
#7
Re: Serial Port Communication in WinCE Emulator using eVC++
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.
-
March 30th, 2005, 07:28 AM
#8
Re: Serial Port Communication in WinCE Emulator using eVC++
 Originally Posted by Aravindan
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
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?
-
March 30th, 2005, 08:07 AM
#9
Re: Serial Port Communication in WinCE Emulator using eVC++
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.
Many people can only keep on fighting when they expect to win. I'm not like that, I always expect to lose. I fight anyway, and sometimes I win!
-
March 30th, 2005, 08:14 AM
#10
Re: Serial Port Communication in WinCE Emulator using eVC++
does this mean that you are satisfied with the code sample i gave you, or do you still need some more information
-
March 31st, 2005, 08:02 AM
#11
Re: Serial Port Communication in WinCE Emulator using eVC++
Thanks a lot mate! Ur code is fine!
Many people can only keep on fighting when they expect to win. I'm not like that, I always expect to lose. I fight anyway, and sometimes I win!
-
March 31st, 2005, 08:03 AM
#12
Re: Serial Port Communication in WinCE Emulator using eVC++
 Originally Posted by Aravindan
Thanks a lot mate! Ur code is fine!
you are welcome
-
March 31st, 2005, 08:05 AM
#13
Re: Serial Port Communication in WinCE Emulator using eVC++
Can u send me ur email id?
mine is : aravindtherock AT yahoo DOT com
Many people can only keep on fighting when they expect to win. I'm not like that, I always expect to lose. I fight anyway, and sometimes I win!
-
April 1st, 2005, 04:52 AM
#14
Re: Serial Port Communication in WinCE Emulator using eVC++
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!
-
April 1st, 2005, 05:17 AM
#15
Re: Serial Port Communication in WinCE Emulator using eVC++
 Originally Posted by pachas
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>.
Last edited by reset-leo; April 1st, 2005 at 05:22 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|