Home > Software engineering >  CSerialPort problem: how to call in a dialog box, another dialog box to write a serial port function
CSerialPort problem: how to call in a dialog box, another dialog box to write a serial port function

Time:10-03

I did an MFC project, which contains multiple button pop-up dialog box, I put the CSerialPort class in one dialog box:
Create an object CSerialPort m_Port;
And add a serial port data receiving the response function afx_msg LONG OnCommunication (WPARAM ch, LPARAM port);
Now, I need another dialog box to write a serial port operation, the use of is m_Port WriteToPort strdata, strlen (); But always wrong? Could you tell me what predecessors the cause of the error? Starting with how to solve? Thank you very much!
An error condition is illustrated below:

CodePudding user response:

Do you want to look like this:
The class function
{
Class variables - & gt; Function () is, in fact is equal to this - & gt; Class variables - & gt; Function ();
}
Your second dialog box is not corresponding to this pointer,

Below is the pseudo code
Method one:
Class A
{


Public:
M_port;

};

A g_DlgA;


B: : Test
{

G_DlgA. M_port - & gt; WritePort ();

}


Method 2:

Class A
{


Private:
M_port;

Public WritePort ()
{
M_port. WritePort ();
}

};

A g_DlgA;


B: : Test
{

G_DlgA. WritePort ();

}

CodePudding user response:

CSerialPort m_Port;//do you use inside another class defined global!
You describe the inside of the code don't see issues with debugging information

CodePudding user response:

Define a pointer dialog, and then the corresponding dialog pointer into, again calling pointer call m_port write,
In addition, why do you want to put the writing to another dialog box inside, have what necessary?

CodePudding user response:

reference a393062456 reply: 3/f
definition dialog pointer, then the pointer to the corresponding dialog box, then call m_port write pointer call,
In addition, why do you want to put the writing to another dialog box inside, have what need?

All to the operation of the serial port on a dialog box is not good, there is communication, read the card, positioning, all kinds of read and write operations, it is as you say, the second floor?

CodePudding user response:

reference 1st floor tajon1226 response:
what do you want to look like this:
The class function
{
Class variables - & gt; Function () is, in fact is equal to this - & gt; Class variables - & gt; Function ();
}
Your second dialog box is not corresponding to this pointer,

Below is the pseudo code
Method one:
Class A
{


Public:
M_port;

};

A g_DlgA;


B: : Test
{

G_DlgA. M_port - & gt; WritePort ();

}


Method 2:

Class A
{


Private:
M_port;

Public WritePort ()
{
M_port. WritePort ();
}

};

A g_DlgA;


B: : Test
{

G_DlgA. WritePort ();

}

Thank you, I am a in the way you write, redefinition of mistakes,

CodePudding user response:

refer to the second floor SWWLLX response:
CSerialPort m_Port;//do you use inside another class defined global!
You describe the inside of the code don't see issues with debugging information

So, I have A function in A dialog box On_ICJC (); This function USES the CSerialPort class a WriteToPort write a serial port function, namely
I want to write a serial port operation in the dialog box to complete the same B, then the problem of error,

CodePudding user response:

A serial port is open in another dialog box to send, you need to in another dialog opens a serial port, serial port before it was shut off

CodePudding user response:

Problem, the problem of code for: m_hComm!=0; As shown in the figure below:

CodePudding user response:

reference 5 floor janehx reply:
Quote: refer to 1st floor tajon1226 response:

Do you want to look like this:
The class function
{
Class variables - & gt; Function () is, in fact is equal to this - & gt; Class variables - & gt; Function ();
}
Your second dialog box is not corresponding to this pointer,

Below is the pseudo code
Method one:
Class A
{


Public:
M_port;

};

A g_DlgA;


B: : Test
{

G_DlgA. M_port - & gt; WritePort ();

}


Method 2:

Class A
{


Private:
M_port;

Public WritePort ()
{
M_port. WritePort ();
}

};

A g_DlgA;


B: : Test
{

G_DlgA. WritePort ();

}

Thank you, I am a in the way you write, redefinition of mistakes,

Redefine the problem has been solved, or problems now or m_hComm!=0; The problem of

CodePudding user response:

reference 4 floor janehx response:
Quote: reference a393062456 reply: 3/f

Define a pointer dialog, and then the corresponding dialog pointer into, again calling pointer call m_port write,
In addition, why do you want to put the writing to another dialog box inside, have what need?

All to the operation of the serial port on a dialog box is not good, there is communication, read the card, positioning, all kinds of read and write operations, it is as you say, the second floor?

Not, such as a single document procedure, your view and doc pointer object is defined in CMainFrame is, if you are in a different view to operate in view of the inside of the other variables to do, you can get the main window of the pointer, accessed through the main window of the pointer you want the pointer to the view of operation, you through the pointer to the view you want operation variables,

Here, too, you're going to be another dialog operation you m_port, that you will visit the m_port, and define the m_port you in another dialog box, you put the handle obtained m_port dialog box, and then through the handle operating m_port variables in this dialog you sent is ok,

CodePudding user response:

A serial port is not open

CodePudding user response:

That I just pseudo code, just as an example, you can't copy, I speak detailed dot
If you have A dialog box is the main dialog box (the) is the first pop up

DlgA. CPP file============

DlgA * g_pDlg=NULL;

OnitDialog ()
{
G_pDlg=this;
}

DlgA. H file=====================
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related