|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Re: About RS232 [message #18640 is a reply to message #18639] |
Mon, 13 October 2008 23:25   |
Mindtraveller
Messages: 917 Registered: August 2007 Location: Russia, Moscow rgn.
|
Experienced Contributor |

|
|
Of course. Since 2008.1 there where big number of improvements (thanx to Mirek) and QTF as well as TheIDE Help system is upgraded. I recommend to use Projects > SVN synchronize ability to obtain latest sources and recompile TheIDE.
I use latest SVN sources and manual was developed under latest version.
[Updated on: Mon, 13 October 2008 23:26] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Re: About RS232 [message #24633 is a reply to message #24408] |
Tue, 26 January 2010 04:39   |
nlneilson
Messages: 644 Registered: January 2010 Location: U.S. California. Mojave &...
|
Contributor |
|
|
I would also like something in U++ to work with serial ports.
The example for sockets is very good and I will be using that.
If something similar for serial ports could be done that would be great.
I have worked with serial ports for GPS data using:
Python with PySerial
Java with rxtx
Windows with:
#using <System.dll>
using namespace System;
using namespace System::IO::Ports;
using namespace System::Threading;
using namespace System::IO;
using namespace std;
I have tried and have the code for wxTerminal but digging through the code and trying to get something to work with U++ is something I have not tried.
Something to work with serial ports for Win and Linux in U++ would be a real plus.
[Updated on: Tue, 26 January 2010 04:46] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Re: About RS232 [message #25671 is a reply to message #25665] |
Sun, 07 March 2010 12:58   |
nlneilson
Messages: 644 Registered: January 2010 Location: U.S. California. Mojave &...
|
Contributor |
|
|
Reini: The code I use just follows after the connection.
For the connection on Win it's System::IO::Ports
With Java it's rxtx
With Python it's PySerial
With your experience and what Nick has maybe something can
be put together that Mirek and others can check and possibly have that included in Upp.
I will look closer at Nick's code, I couldn't find termios.h, is that included in C++ ?
Neil
[Updated on: Sun, 07 March 2010 13:14] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|