Top.Mail.Ru
The C++ Community's Journal -- Day
? ?
The C++ Community's Journal -- Day [entries|friends|calendar]
The C++ Community

[ userinfo | livejournal userinfo ]
[ calendar | livejournal calendar ]

MFC, threads, and serial ports [03 Aug 2005|01:48pm]
Hi folks, I'm at a loss as to my problem here. Multithreading is new to me, but examples I've seen make me suspect this should work. I've been writing code to interface with a scientific instrument connected to the computer via serial. The nature of this device and our application structure suggested multithreading would be the way to go for solid support.

I am using Visual C++ 6.0 and MFC, as are the other engineers where I work. I realize the popularity of this platform is decreasing, but it's what I've got for now.

The problem I am having is my ReadFile on the serial port is returning a true value, yet the bytes read parameter is zero. I am using non-overlapped IO. After some reading I'd tried using SetCommMask and WaitCommEvent, to no avail. MFC documentation suggests that I'd see a true return value yet zero bytes read if I was using a named pipe, but I am not.

Here's the other part of the scenario, and it could likely be what's tripping things up. I have a decent serial port class I wrote that encapsulates what you'd expect, opening, closing, reading, writing. My main application thread creates an instance of the class, opens the serial port, and launches the writing/reading thread. It also stashes the serial instance in a global index so I can get at the object from the thread. In the thread, when there's a command for the serial device, I do my locks, then I send the command off to the serial port via my serial object's write function, and then get all set up to block on a read(also a member of the serial object). This is where ReadFile returns true and zero for the number of bytes read.

Any ideas? I can think of a couple of things that might be the case that I'm working on, but I'm a little stumped as most of the things I see suggest that this approach should work, though people aren't using objects like I have been. Thanks for your time.
4 comments|post comment

.net help [03 Aug 2005|11:17pm]
I am in need of some very basic advice regarding VCPP 7.0/.net. I seem to be missing out on something really obvious about the way the compiler works because I can't get any .cpp/.h object files to work in a main loop, the files will compile on their own but I always get either "cannot open include file so-and-so" or if it allows the include file then I try to make an object in the main loop like

obj a;

and I get "obj unknown, a unknown etc." I haven't had any problems getting this stuff going on Linux, but so far I have one .net project where one of my classes can be worked with inside of the main loop but... I have been unable to repeat this! I have a project where I can work with ONE of my classes. I have no idea how this happened. Just a link to some advice on working the .Net environment or somethign would be appreciated thanks.
5 comments|post comment

navigation
[ viewing | August 3rd, 2005 ]
[ go | previous day|next day ]
Image