Click here to Skip to main content
15,905,144 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionInstallation for VC++ project Pin
Anonymous16-Oct-05 20:28
Anonymous16-Oct-05 20:28 
Questionhelp! why the compiler kept modifying my source file? Pin
ewighell16-Oct-05 19:29
ewighell16-Oct-05 19:29 
AnswerRe: help! why the compiler kept modifying my source file? Pin
Rage16-Oct-05 23:39
professionalRage16-Oct-05 23:39 
GeneralRe: help! why the compiler kept modifying my source file? Pin
ewighell17-Oct-05 1:00
ewighell17-Oct-05 1:00 
QuestionHow to find data encoding of received buffer with WSARecv Pin
Member 168985516-Oct-05 19:00
Member 168985516-Oct-05 19:00 
AnswerRe: How to find data encoding of received buffer with WSARecv Pin
ThatsAlok16-Oct-05 21:43
ThatsAlok16-Oct-05 21:43 
Questionunable to get all Messages from Clients using IOCP Pin
Member 168985516-Oct-05 18:58
Member 168985516-Oct-05 18:58 
QuestionC++ Serial Loopback port converting to char, where can I correct this Pin
ianfinlay_tyco16-Oct-05 18:19
ianfinlay_tyco16-Oct-05 18:19 
:->
Using VC++.NET2003

I have written serial routines (ported from Apollo) as follows:
but I am finding that with a serial loopback setup
the leading bit is reset on all chars (ie. transmit 0xff and receive only 0x7f)

I have a feeling its to do with binary vs text mode but I am unable to resolve.

Code:
CSerial::CSerial (LPCTSTR pszCommPort, LPCTSTR pszMode , char LineTerminator)
{
m_strCommsPort = pszCommPort;
m_strMode = pszMode;
m_LineTerminator = LineTerminator;
}

CSerial::~CSerial ()
{
ios_$close();
}

void CSerial::ios_$close(void)
{
if ( m_Port != INVALID_HANDLE_VALUE )
{
ios_$flush();
CloseHandle ( m_Port );
m_Port = INVALID_HANDLE_VALUE;
}
}

bool CSerial::ios_$open(void)
{
COMMTIMEOUTS lpCommTimeouts;
LPCOMMTIMEOUTS pPortTimeouts = &lpCommTimeouts;

m_Port = CreateFile( m_strCommsPort, GENERIC_READ |
GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);

if ( m_Port == INVALID_HANDLE_VALUE )
{
char szBuffer[256];
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL,
GetLastError(), MAKELANGID(LANG_NEUTRAL,
SUBLANG_DEFAULT),szBuffer, sizeof szBuffer, NULL );

strcat ( szBuffer, " opening " );
strcat ( szBuffer, m_strCommsPort );
MessageBox(NULL, szBuffer, "CIMW", MB_OK);
return false;
}

DCB dcb;
dcb.DCBlength = sizeof DCB;
GetCommState(m_Port, &dcb );

BuildCommDCB(m_strMode, & dcb);
dcb.fBinary = true;
dcb.fOutxDsrFlow = 0;
dcb.fOutxCtsFlow = 0;
dcb.fOutX = 0;
dcb.fInX = 0;
dcb.fDtrControl = DTR_CONTROL_ENABLE;
dcb.fRtsControl = RTS_CONTROL_ENABLE;

// Maximum time between read chars.
lpCommTimeouts.ReadIntervalTimeout = MAXDWORD;

// Multiplier of characters.
lpCommTimeouts.ReadTotalTimeoutMultiplier = 0;

// Constant in milliseconds.
lpCommTimeouts.ReadTotalTimeoutConstant =0;

// Multiplier of characters.
lpCommTimeouts.WriteTotalTimeoutMultiplier = 100;

// Constant in milliseconds.
lpCommTimeouts.WriteTotalTimeoutConstant = 1000;

SetCommTimeouts(m_Port, pPortTimeouts);

SetCommState(m_Port, & dcb);
return true;
}

bool CSerial::ios_$put ( const unsigned char *pszPacket, int iLen)
{
int iPut = 0;
for (int x=0; x < iLen; x++ )
{
ios_$putchar ( pszPacket[x] );
iPut++;
if (iPut >= iLen)
{
return true;
}
}
return true;
}

bool CSerial::ios_$putchar(unsigned char cByte)
{
DWORD bytesWritten;
bool bWrite;

bWrite = (bool)WriteFile ( m_Port, (void *)&cByte, 1,
&bytesWritten, NULL );
return bWrite;
}

int CSerial::ios_$get(unsigned char *cByte)
{
int iError;
int iCode;
DWORD bytesRead;
LPDWORD pBytesRead = &bytesRead;

iCode = ReadFile ( m_Port, (unsigned char *)cbyte,
1,pBytesRead, NULL);

if (bytesRead == 0)
{
return 0;
iError = GetLastError();
}
else
{
*cByte = x;
}
return 1;
}


void CSerial::ios_$flush()
{
PurgeComm ( m_Port, PURGE_RXCLEAR );
}




Ian
AnswerRe: C++ Serial Loopback port converting to char, where can I correct this Pin
stewartl17-Oct-05 0:11
stewartl17-Oct-05 0:11 
GeneralRe: C++ Serial Loopback port converting to char, where can I correct this Pin
ianfinlay_tyco18-Oct-05 12:53
ianfinlay_tyco18-Oct-05 12:53 
QuestionI have an error Pin
vhazell16-Oct-05 16:33
vhazell16-Oct-05 16:33 
AnswerRe: I have an error Pin
GflPower16-Oct-05 17:07
GflPower16-Oct-05 17:07 
GeneralRe: I have an error Pin
vhazell16-Oct-05 17:28
vhazell16-Oct-05 17:28 
AnswerRe: I have an error Pin
P-Rex16-Oct-05 21:32
P-Rex16-Oct-05 21:32 
GeneralRe: I have an error Pin
vhazell16-Oct-05 21:44
vhazell16-Oct-05 21:44 
GeneralRe: I have an error Pin
P-Rex16-Oct-05 22:07
P-Rex16-Oct-05 22:07 
GeneralRe: I have an error Pin
David Crow17-Oct-05 2:47
David Crow17-Oct-05 2:47 
Questionretrieve MSN messenger conversations Pin
smargada16-Oct-05 14:33
smargada16-Oct-05 14:33 
AnswerRe: retrieve MSN messenger conversations Pin
ThatsAlok16-Oct-05 19:05
ThatsAlok16-Oct-05 19:05 
QuestionRe: retrieve MSN messenger conversations Pin
David Crow17-Oct-05 8:02
David Crow17-Oct-05 8:02 
AnswerRe: retrieve MSN messenger conversations Pin
ThatsAlok17-Oct-05 18:02
ThatsAlok17-Oct-05 18:02 
Questionservices in xp Pin
Archer28216-Oct-05 13:25
Archer28216-Oct-05 13:25 
AnswerRe: services in xp Pin
GflPower16-Oct-05 17:11
GflPower16-Oct-05 17:11 
GeneralRe: services in xp Pin
Archer28216-Oct-05 17:16
Archer28216-Oct-05 17:16 
GeneralRe: services in xp Pin
l a u r e n16-Oct-05 18:46
l a u r e n16-Oct-05 18:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.