Crossware

Table of Contents        Previous topic       Next topic       

Using the Custom AppWizard or Project Template->Tutorial - Creating an Extension with the AppWizard->Adding a Dialog Box to your Extension->Sending Messages to your Program

We will now add code to your extension so that you can use this dialog box to send messages to the UART of your simulating 8051 program.

Return to the Microsoft Developer Studio.

Your dialog box needs to sent communicate with CExtensionState.

Add the line in bold:

#include "MessageDlg.h"
#include "ExtensionState.h"


Open MessageDlg.h and add the lines in bold:

//}}AFX_DATA
class CExtensionState* m_pExtensionState;
void  SetExtensionState(CExtensionState* pExtensionState)
    { m_pExtensionState = pExtensionState; }


Open MessageDlg.cpp and modify CMessageDlg::OnButtonSend()  adding the lines in bold:

void CMessageDlg::OnButtonSend()
{
 // TODO: Add your control notification handler code here
 if (UpdateData())
 {
   m_pExtensionState->SendMessage(m_strMessage);
 }
}

We will now add the SendMessage() function to CExtensionState.

Open ExtensionState.h and add the lines in bold:

DWORD m_nMachineCycles;
CString m_strMessage;
public:
 void SendMessage(CString& rstrMessage);
 void ResetState(void);

Open ExtensionState.cpp and add the function CExtensionState::SendMessage() to the end of the file as follows:

void CExtensionState::SendMessage(CString& rstrMessage)
{
 if (!m_strMessage.IsEmpty())
 {
   AfxMessageBox("Previous message still being transmitted");
 }
 else
 {
   m_strMessage = rstrMessage;
 }
}

Modify function CExtensionState::GetSerialInput() adding the lines in bold:

BOOL CExtensionState::GetSerialInput(BYTE nBuffAddress, BYTE* pnByte)
{
 if (nBuffAddress == 0X99)
 {
   // serial port 0
   if (!m_strMessage.IsEmpty())
   {
     *pnByte = m_strMessage[0];
     m_strMessage = m_strMessage.Mid(1);
     return TRUE;
   }
 }
 return FALSE;
}

Add the line in bold to CExtensionState::CExtensionState():

CExtensionState::CExtensionState()
{
 ResetState();
 nExtensionCount++;
 g_pMessageDlg = new CMessageDlg();
 g_pMessageDlg->SetExtensionState(this);
}