|
|
Home » U++ Library support » U++ Library : Other (not classified elsewhere) » About RS232
|
|
|
|
|
|
|
Re: About RS232 [message #13411 is a reply to message #9309] |
Fri, 04 January 2008 17:37 |
nixnixnix
Messages: 415 Registered: February 2007 Location: Kelowna, British Columbia
|
Senior Member |
|
|
Is this still the present state of serial port communication under UPP?
Are there any examples?
I have to say that I would rather do imperfect serial port programming and stay within the confines of UPP than start incorporating 3rd party code.
I am trying to read NMEA sentences from a (bluetooth)GPS connected to (virtual) serial port (3). I don't care about data loss as the GPS streams sentences continually. So long as I catch at least one whole sentence each time I look at the GPS port, I'm good. With this in mind, can anyone tell me why the following does not work?
MyClass::MyClass()
{
CtrlLayout(*this, "Window title");
Zoomable().Sizeable();
SetTimeCallback(1000, callback(this, &MyClass::Timer));
}
void MyClass::Timer()
{
char cBuf[300];
void* ptr = (void*)0x2f8;
memcpy(cBuf,ptr,200);
m_s.SetText(cBuf);
}
GUI_APP_MAIN
{
MyClass().Run();
}
It throws an exception whenever I try to directly access the address 0x2f8
Any ideas or insults welcome
EDIT: ah ok so I've found that direct access of these addresses is outlawed under newer versions of windows - great!
I am finding freely available serial port classes but they are either pre 1995 or written to run under MSVC and use handles etc. If I find one that can be converted I will post it here.
If anyone knows how to get around the windows access exception, I would be very happy to hear it.
Nick
[Updated on: Fri, 04 January 2008 18:24] Report message to a moderator
|
|
|
Re: About RS232 [message #13414 is a reply to message #13411] |
Fri, 04 January 2008 23:48 |
Mindtraveller
Messages: 917 Registered: August 2007 Location: Russia, Moscow rgn.
|
Experienced Contributor |
|
|
Nick, your code will of course throw an exception.
Mistakes you`ve made:
1) You try to read 0x2f8 address instead of port 2f8, which is usually connected with one of RS232 ports.
2) You try to read from port in Windows, where direct working with hardware ports is prohibited (if you`re not kernel-mode device driver).
3) Virtual COM-ports like bluetooth ones are not physical RS-232 ports. So there is no way to read them with any physical port, like 2f8.
Instead, you should do following:
1) Open port with CreateFile
2) Do reading/writing with ReadFile/WriteFile
3) Close the port with CloseHandle.
Things you must consider:
1) Your application must be multithreaded. One thread works with COM-port, while other thread respond to users`s GUI input.
2) You should make some kind of options or config, where to change COM-port number and it`s settings (speed, timeouts, etc) without recompiling the program
I strongly recommend you reading these topics:
(basic)
MSDN: CreateFile, ReadFile, WriteFile (COM-ports)
MSDN: Threads
U++: Config
(intermediate)
MSDN: Threads synchronization
(advanced)
MSDN: Overlapped i/o
Recently I`ve written U++ class, which makes all the hard work with COM-port. You should only write appropriate callbacks. For now, it works only for Windows, since I`m just starting learning Linux. If it`s needed in current state of development - I`ll upload it here.
|
|
|
|
|
Re: About RS232 [message #18597 is a reply to message #18595] |
Fri, 10 October 2008 22:49 |
Mindtraveller
Messages: 917 Registered: August 2007 Location: Russia, Moscow rgn.
|
Experienced Contributor |
|
|
For now class is working good and only for Windows. It already was refactoried and tested in released application. The main drawback is lack of *nix support - this was the cause of not-publishing it into U++ (also I didn`t discuss it`s adding at all). If you need Windows-only version I`ll prepare it and post in this thread tomorrow.
[Updated on: Fri, 10 October 2008 22:51] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
Goto Forum:
Current Time: Fri Nov 01 01:38:13 CET 2024
Total time taken to generate the page: 0.01994 seconds
|
|
|