Re: Switching from dialog based app to SDI



Why not just go to straight MDI? That way, if the computer has two serial ports, it can
control two devices, and you can see both displayed at once?

As to the "document" class, I treat the external device as the "document". The "document"
actually holds things like the serial port state, the DFSM that handles the communication,
etc.; all communication comes from the document. The view simply invokes methods of the
"document" to open the communication, to transmit commands, and to retrieve commands. The
advantage here was that when I needed to add a view which as a graph of the remote device
state over time, well, wow, it was just another view!

The suggestion about making a superclass that has common functions was a good one, and you
might want to read my essay on subclassing dialogs (it also applies to CFormViews). For
example, one app has an abstraction CFunction, and everything is a CFunction. Each view
is a specialized CFunction, and my problem resembled yours strongly (in fact, this
prompted me to figure out how to build derivable CDialogs to handle the tabbed dialog, and
then deriable CFormViews to build the multiple views for the multiple devices. Note that
all my devices have a common low-level interface, so there is actually only one CDocument
class that embodies all the communication. In fact, one way I handled this was to bring
up a "generic view", which had no meaningful controls; it only had enough smarts to be
able to query the device to discover its type (each device had a unique type code, so if I
did a MSG_QUERY_DEVICE_TYPE to my device, I got back a code which allowed me to create a
second view of the correct type. I arranged that this would be the same size and int he
same location as the generic view (it was a bit tricky if it was maximized...), then I
destroyed the generic view.
joe

On 28 May 2006 10:40:11 -0700, namlook@xxxxxx wrote:

Hi. I'm new to MFC. I've been programming a dialog based application
with VC 6.0. The application basically does the following:

- Connect via RS232 to an external device
- Send 16 bit values (8 Bit Command, 8 Bit data) to the device to
write/read register values of that device (only one register at a time)
- There are command bytes to read and write each register
- Provide the user with an interface to enter the values to write to
the registers/or read the register, when a specific button is pressed

I'm supposed to write similar programs now to control other devices.
The communication principle is always the same. Only the command values
(8 bit) change and the way the registers are displayed in the dialog.

My idea was to switch to an SDI application (since only one external
device can be connected at a time) with different CFormviews
representing the different external devices. The reason to choose the
SDI was not having to write the communication for each device again and
to provide the user with one program to control all devices. The
menubar is supposed to be the same for all programs, since only the
communication setup is made in the menu (choosing the COM- Port and
connecting/disconnecting the device). I started to write a program
which displays a dialog box before the MainFrame is created in which
the user selects the device to control.

Now to get finally to my problem: I've been trying to figure out how to
program it in such a way, that it is easy to add new devices with new
FormViews without having to write a lot of duplicate code. A lot of
functions are always the same, like sending/receiving values,
displaying the received values as bin,hex,dec strings or converting the
entered binary strings into decimal numbers (like 0010 -> 2).

I tried to apply the doc/view structure to my problem but I started to
doubt if this was the right way to do it. The register set of the
devices is always different , hence I cannot use one document class and
multiple views to display the data. In fact the document would not
really store any data but only forward it from the external device to
the view and the other way around.

Is it in my case better to put the data in the view class as well? Or
is there maybe a completely different concept?

I've been reading a lot in the msdn and in this group, but the more I
read the more confused I get of how to do it. I appreciate any help.
Thanks
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.