Home > Software engineering >  MFC serial port communication, can open the serial port, but the driver to send an error...
MFC serial port communication, can open the serial port, but the driver to send an error...

Time:10-09

The story is this: just learn to use MFC, then asked me to write a serial program drive motor, of course, there is a driver card,

Using modbus Rs485 communication, is connected to the drive line RS232 to Rs485, even on the USb interface,

N have debugging assistant, the source code are many, but one can VS2015 compiled a no, were written before the old version, this to the MFC to

Fun, just shortly into the line, ability is limited, can't change, and then write their own, results are shown in the code below, connection debugging assistant, send instructions without any pressure,

But after connection driver card, instruction a card to send drive GG, a research is likely to be a serial port parameter setting problem, change and change, my incompetence!

Come to help!

Ps: are a long way to go!!!!!
 
/* * * * * * * * * button to trigger the program * * * * * * * * */
Bool CMy0902PortDlg: : OpenIo ()
{
Byte _Command []={0 x01, 0 x06, 0 x00 to 0 x7d, 0 x40, 0 x00 to 0 x28, 0 x12};
HMcom. OpenSerial (2, 115200);
HMcom. Write (_Command, 8);
return TRUE;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* * * * * * * * * * * part of the function call * * * * * * * * * * * */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

Bool CMyCom: : OpenSerial (DWORD dwPort, dwords dwBaudRate)
{
M_Port=dwPort;
Return the Open (dwPort dwBaudRate);
}
/* * * * * * * * * * * * * * * * * * * * * * * to open the serial port * * * * * * * * * * * * * * * * * * * */
Bool Open (DWORD dwPort, dwords dwBaudRate)
{
If (dwPort & lt; 1 | | dwPort & gt; 1024) return false.

BindCommPort (dwPort);

if (! OpenCommPort return false ());

if (! SetupPort return false ());

Return SetState (dwBaudRate);
}
/* * * * * * * * * * * * * * * * * * * set serial port * * * * * * * * * * * * * * * * * * */
Virtual bool SetupPort ()
{
if (! IsOpen return false ());

if (! : : SetupComm (_hCommHandle, 4096, 4096)) return false.

if (! : : GetCommTimeouts (_hCommHandle, & amp; _CO)) return false.

_CO. ReadIntervalTimeout=0;
_CO. ReadTotalTimeoutMultiplier=1;
_CO. ReadTotalTimeoutConstant=1000;
_CO. WriteTotalTimeoutMultiplier=1;
_CO. WriteTotalTimeoutConstant=1000;
if (! : : SetCommTimeouts (_hCommHandle, & amp; _CO)) return false.

if (! : : PurgeComm (_hCommHandle, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR))
return false;

return true;
}
/* * * * * * * * * * * * * * * * * * * * * * * segmentation * * * * * * * * * * * * * * * * * * * * * * */
Bool SetState (DWORD dwBaudRate, dwords dwByteSize=8, dwords dwParity=
NOPARITY, dwords dwStopBits=ONESTOPBIT)
{
If (IsOpen ())
{
If (: : GetCommState (_hCommHandle, & amp; _DCB)!=TRUE)
return false;
_DCB. BaudRate=dwBaudRate;
_DCB. ByteSize=(unsigned char) dwByteSize;
_DCB. Parity=(unsigned char) dwParity;
_DCB. StopBits=(unsigned char) dwStopBits;
Return: : SetCommState (_hCommHandle, & amp; _DCB)==TRUE;
}
return false;
}

CodePudding user response:

Captcha lost eight times!!!!!!!!!! It's 12306.

CodePudding user response:

Using a single step debugging, use serial caught software

CodePudding user response:

MSDN98_1. ISO http://pan.baidu.com/s/1dDF41ix, MSDN98_2. ISO http://pan.baidu.com/s/1bnGo0Vl
Download and install MSDN98 first,

Reference:
MSDN98 \ SAMPLES \ VC98 \ SDK \ WINBASE \ IO \ SERIAL \ TTY DSP
MSDN98 \ SAMPLES \ VC98 \ SDK \ WINBASE \ IO \ SERIAL \ TTY RES
MSDN98 \ SAMPLES \ VC98 \ SDK \ WINBASE \ IO \ SERIAL \ TTY RC
MSDN98 \ SAMPLES \ VC98 \ SDK \ WINBASE, IO, SERIAL, MAKEFILE
MSDN98 \ SAMPLES \ VC98 \ SDK \ WINBASE \ IO \ SERIAL \ VERSION H
MSDN98 \ SAMPLES \ VC98 \ SDK \ WINBASE \ IO \ SERIAL \ RESOURCE H
MSDN98 \ SAMPLES \ VC98 \ SDK \ WINBASE \ IO \ SERIAL \ TTY H
MSDN98 \ SAMPLES \ VC98 \ SDK \ WINBASE \ IO \ SERIAL \ TTY C
MSDN98 \ SAMPLES \ VC98 \ SDK \ WINBASE \ IO \ SERIAL \ README. TXT
MSDN98 \ SAMPLES \ VC98 \ SDK \ WINBASE \ IO \ SERIAL \ TTY ICO
MSDN98 \ SAMPLES \ VC98 \ SDK \ WINBASE \ IO \ SERIAL \ TTY BMP
MSDN98 \ SAMPLES \ VC98 \ SDK \ WINBASE \ IO \ SERIAL \ TTY DEF

CodePudding user response:

refer to the second floor chengbar response:
use single-step debugging, using serial port caught software

This is the day I step, supplier would haven't demo, very helpless

CodePudding user response:

reference zhao4zhong1 reply: 3/f
MSDN98_1. ISO http://pan.baidu.com/s/1dDF41ix, MSDN98_2. ISO http://pan.baidu.com/s/1bnGo0Vl
Download and install MSDN98 first,

Reference:
MSDN98 \ SAMPLES \ VC98 \ SDK \ WINBASE \ IO \ SERIAL \ TTY DSP
MSDN98 \ SAMPLES \ VC98 \ SDK \ WINBASE \ IO \ SERIAL \ TTY RES
MSDN98 \ SAMPLES \ VC98 \ SDK \ WINBASE \ IO \ SERIAL \ TTY RC
MSDN98 \ SAMPLES \ VC98 \ SDK \ WINBASE, IO, SERIAL, MAKEFILE
MSDN98 \ SAMPLES \ VC98 \ SDK \ WINBASE \ IO \ SERIAL \ VERSION H
MSDN98 \ SAMPLES \ VC98 \ SDK \ WINBASE \ IO \ SERIAL \ RESOURCE H
MSDN98 \ SAMPLES \ VC98 \ SDK \ WINBASE \ IO \ SERIAL \ TTY H
MSDN98 \ SAMPLES \ VC98 \ SDK \ WINBASE \ IO \ SERIAL \ TTY C
MSDN98 \ SAMPLES \ VC98 \ SDK \ WINBASE \ IO \ SERIAL \ README. TXT
MSDN98 \ SAMPLES \ VC98 \ SDK \ WINBASE \ IO \ SERIAL \ TTY ICO
MSDN98 \ SAMPLES \ VC98 \ SDK \ WINBASE \ IO \ SERIAL \ TTY BMP
MSDN98 \ SAMPLES \ VC98 \ SDK \ WINBASE \ IO \ SERIAL \ TTY DEF


MSDN98? 2015 all don't understand............
Also so much...
I am dead (manual)

CodePudding user response:

reference 5 floor qq_36054663 reply:
Quote: refer to the third floor zhao4zhong1 response:

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related