BCB上API函数实现串口通讯显示接收内容有关问题
BCB下API函数实现串口通讯显示接收内容问题
编写完成后,在输出显示com传回来的值的时候,发现只有在receive函数内printf可以显示,但是在main()里把值显示就不可以。由于本人基础不好,还请大家看看。
代码如下
//---------------------------------------
#include <vcl.h>
//---------------------------------------
#pragma hdrstop
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include"Unit1.h"
//---------------------------------------
//HANDLE hComm;
//OVERLAPPED m_ov;
//COMSTAT comstat;
//DWORD m_dwCommEvents;
bool openport(char *portname)//open a com port
{
}
bool setupdcb(int rate_arg)
{
}
bool ReceiveChar(char *resp)
{
BOOL bRead = TRUE;
BOOL bResult = TRUE;
DWORD dwError = 0;
DWORD BytesRead = 0;
char RXBuff[5000];
for (;;)
{
bResult = ClearCommError(hComm, &dwError, &comstat);
if (comstat.cbInQue == 0)
continue;
if (bRead)
{
bResult = ReadFile(hComm, // Handle to COMM port
RXBuff, // RX Buffer Pointer
1, // Read one byte
&BytesRead, // Stores number of bytes read
&m_ov); // pointer to the m_ov structure
sprintf(resp,"%s",RXBuff);
//printf(resp);此处可显示
if (!bResult)
{
switch (dwError = GetLastError())
{
case ERROR_IO_PENDING:
{
bRead = FALSE;
break;
}
default:
{
break;
}
编写完成后,在输出显示com传回来的值的时候,发现只有在receive函数内printf可以显示,但是在main()里把值显示就不可以。由于本人基础不好,还请大家看看。
代码如下
//---------------------------------------
#include <vcl.h>
//---------------------------------------
#pragma hdrstop
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include"Unit1.h"
//---------------------------------------
//HANDLE hComm;
//OVERLAPPED m_ov;
//COMSTAT comstat;
//DWORD m_dwCommEvents;
bool openport(char *portname)//open a com port
{
}
bool setupdcb(int rate_arg)
{
}
bool ReceiveChar(char *resp)
{
BOOL bRead = TRUE;
BOOL bResult = TRUE;
DWORD dwError = 0;
DWORD BytesRead = 0;
char RXBuff[5000];
for (;;)
{
bResult = ClearCommError(hComm, &dwError, &comstat);
if (comstat.cbInQue == 0)
continue;
if (bRead)
{
bResult = ReadFile(hComm, // Handle to COMM port
RXBuff, // RX Buffer Pointer
1, // Read one byte
&BytesRead, // Stores number of bytes read
&m_ov); // pointer to the m_ov structure
sprintf(resp,"%s",RXBuff);
//printf(resp);此处可显示
if (!bResult)
{
switch (dwError = GetLastError())
{
case ERROR_IO_PENDING:
{
bRead = FALSE;
break;
}
default:
{
break;
}