Re: VC6 serial port usage in a tabbed dialog application
On Fri, 26 Oct 2012 08:32:48 +0100, David Lowndes wrote:
How do I share the same handle?
It's just a variable - you access ("share") it the same way you would
any piece of data.
If you're currently storing the handle in one of your tabbed pages
classes, the obvious place to move it to would be the common parent of
each of those page classes (probably your dialog class).
Dave
Here is what I have recently tried.
//To use SerialCom, in the main Dialog's .h file I add:
#include "SerialCom.h"
//And under public: I add:
class CAdelphiX2Dlg : public CDialog
{
// Construction
public:
CAdelphiX2Dlg(CWnd* pParent = NULL); // standard constructor
Web1a m_dWeb1a;
Web2a m_dWeb2a;
Web3a m_dWeb3a;
CSerialCom port; //for the serial port access
//....
//the rest of the main Dialog .h file
}
//In the main Dialog's .cpp OnInitDialog() I add:
m_cTab.GetWindowRect(tabRect);
m_rSettingsRect.left = 2;
m_rSettingsRect.top = 40;
m_rSettingsRect.right = tabRect.Width() - 4;
m_rSettingsRect.bottom = tabRect.Height() - 40;
m_dWeb1a.Create(IDD_WEBX1, this); // Create the child windows
for the main window class
m_dWeb2a.Create(IDD_WEBX2, this);
m_dWeb3a.Create(IDD_WEBX3, this);
ShowWindowNumber(0);
TCITEM tabItem; // Set the titles for each tab
tabItem.mask = TCIF_TEXT;
tabItem.pszText = _T(" Web-1 ");
m_cTab.InsertItem(0, &tabItem);
tabItem.pszText = _T(" Web-2 ");
m_cTab.InsertItem(1, &tabItem);
tabItem.pszText = _T(" Options ");
m_cTab.InsertItem(2, &tabItem);
CString Comport = "com1"; //setup serial port
if(!(port.OpenPort(Comport))){
MessageBox("Cannot open Communication Port.\nPlease Check Options For
Proper Setting","Error",MB_OK+MB_ICONERROR);
return TRUE;
}
if(!(port.ConfigurePort(9600,8,0,NOPARITY,ONESTOPBIT))){
MessageBox("Cannot Configure Communication
Port","Error",MB_OK+MB_ICONERROR);
port.ClosePort();
}
else{
if(!(port.SetCommunicationTimeouts(0,260,0,0,0))){
MessageBox("Cannot Configure Communication
Timeouts","Error",MB_OK+MB_ICONERROR);
port.ClosePort();
}
//I have tried adding #include "SerialCom.h" and a function in Web1a.h to
//get port.
class Web1a : public CDialog
{
// Construction
public:
Web1a(CWnd* pParent = NULL); // standard constructor
void SetWeb1ComPort(CSerialCom pport);
CSerialCom port
//And I added to Web1a.cpp the following.
void SetWeb1ComPort(CSerialCom pport)
{
port = pport;
}
I get the following build errors
error C2664: 'SetWeb1ComPort' : cannot convert parameter 1 from 'class
CSerialCom' to 'class CSerialCom'
error C2065: 'port' : undeclared identifier