Click here to Skip to main content
16,007,163 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Eqv of itoa() in shlwapi.h Pin
Suren10-Dec-02 1:40
Suren10-Dec-02 1:40 
GeneralProblem in frame window Pin
srisvs9-Dec-02 18:08
srisvs9-Dec-02 18:08 
GeneralTable format data Pin
vgkotha9-Dec-02 18:05
vgkotha9-Dec-02 18:05 
GeneralHTTP_HOST Pin
MadhuC9-Dec-02 14:54
MadhuC9-Dec-02 14:54 
Generalhelp with serial comm Pin
ski2sky9-Dec-02 14:42
ski2sky9-Dec-02 14:42 
GeneralRe: help with serial comm Pin
kc5zrs9-Dec-02 16:08
kc5zrs9-Dec-02 16:08 
GeneralRe: help with serial comm Pin
KarstenK9-Dec-02 21:31
mveKarstenK9-Dec-02 21:31 
GeneralRe: help with serial comm Pin
Roger Allen10-Dec-02 3:30
Roger Allen10-Dec-02 3:30 
This is some standard code I use with serial ports:

	DWORD					dwNumBytesRead ;
	DWORD					dwNumBytesWritten ;
	SECURITY_ATTRIBUTES		sa ;
	char					szInputBuffer[2] ;
	char					szString[80] ;
	int						iStringIndex = 0 ;
	int						lamp_warming_timer ;
	int						lamp_on_timer ;
	CString					text ;

	sa.nLength = sizeof(SECURITY_ATTRIBUTES) ;
	sa.lpSecurityDescriptor = NULL ;		// use default descriptor
	sa.bInheritHandle = true ;				// allow sub-threads to inherit handle

	// OPEN SERIAL PORT FOR COMMUNICATION
	m_hSerialPortHandle = CreateFile((LPCTSTR)m_csCommPortName,
		GENERIC_READ | GENERIC_WRITE,
		0,
		&sa,							// needed for inherit
		OPEN_EXISTING,
		0,
		0) ;

	if (m_hSerialPortHandle != INVALID_HANDLE_VALUE)
	{
		m_bOpen = true ;

		if (!GetCommState(m_hSerialPortHandle, &m_DCB))
		{
			text = "Serial port DCB failure." ;
			::SendMessage(m_hwndParent, UWM_UC_STATUS, (LONG)(LPCTSTR)text, 0) ;
		}
		else
		{
			// make sure we are using the correct settings
			m_DCB.BaudRate = CBR_9600 ;					// 9600 baud
			m_DCB.ByteSize = 8 ;						// 8 data bits
			m_DCB.Parity = NOPARITY ;					// no parity
			m_DCB.fParity = false ;						// parity checking off
			m_DCB.StopBits = ONESTOPBIT ;				// 1 stop bit
			m_DCB.fDtrControl = DTR_CONTROL_DISABLE ;	// no DTR input flow control
			m_DCB.fOutxCtsFlow = false ;				// don't monitor CTS
			m_DCB.fDsrSensitivity = false ;				// always read bytes received
			m_DCB.fTXContinueOnXoff = true ;			// don't wait for XONN / XOFF
			m_DCB.fOutX = false ;						// No XON / XOFF control
			m_DCB.fRtsControl = RTS_CONTROL_DISABLE ;	// don't use RTS comms control
			m_DCB.fAbortOnError = false ;				// don't quit on error

			// now apply the correct comm state to the device
			if (!SetCommState(m_hSerialPortHandle, &m_DCB))
			{
				text = "Serial port set com status failure." ;
				::SendMessage(m_hwndParent, UWM_UC_STATUS, (LONG)(LPCTSTR)text, 0) ;
			}
			// set the communication event flags
			if (!SetCommMask(m_hSerialPortHandle, EV_RXCHAR))
			{
				text = "Serial port set com mask failure." ;
				::SendMessage(m_hwndParent, UWM_UC_STATUS, (LONG)(LPCTSTR)text, 0) ;
			}
			COMMTIMEOUTS	timeouts ;

			// return immediately on reads
			// return after completion on writes
			timeouts.ReadIntervalTimeout = MAXDWORD ;
			timeouts.ReadTotalTimeoutConstant = 0 ;
			timeouts.ReadTotalTimeoutMultiplier = 0 ;
			timeouts.WriteTotalTimeoutConstant = 0 ;
			timeouts.WriteTotalTimeoutMultiplier = 0 ;

			SetCommTimeouts(m_hSerialPortHandle, &timeouts) ;
		}
	}
	else
	{
		text = "Unable to open serial port \"" + m_csCommPortName + "\"" ;
		::SendMessage(m_hwndParent, UWM_UC_STATUS, (LONG)(LPCTSTR)text, 0) ;
		m_bThreadDead = true ;
		return ;
	}
// read/write to port here using ReadFile() and WriteFile()



Roger Allen
Sonork 100.10016

In case you're worried about what's going to become of the younger generation, it's going to grow up and start worrying about the younger generation. - Roger Allen, but not me!
GeneralRe: help with serial comm Pin
ski2sky10-Dec-02 5:21
ski2sky10-Dec-02 5:21 
GeneralHelp with CSizingControlBar Pin
Steven M Hunt9-Dec-02 14:16
Steven M Hunt9-Dec-02 14:16 
GeneralRe: Help with CSizingControlBar Pin
Kannan Kalyanaraman9-Dec-02 23:56
Kannan Kalyanaraman9-Dec-02 23:56 
GeneralRe: Help with CSizingControlBar Pin
Maximilien10-Dec-02 3:02
Maximilien10-Dec-02 3:02 
GeneralNeed help with pointer in View Pin
E39-Dec-02 12:26
E39-Dec-02 12:26 
GeneralRe: Need help with pointer in View Pin
Christian Graus9-Dec-02 12:36
protectorChristian Graus9-Dec-02 12:36 
GeneralRe: Need help with pointer in View Pin
E39-Dec-02 13:20
E39-Dec-02 13:20 
GeneralRe: Need help with pointer in View Pin
Christian Graus9-Dec-02 13:26
protectorChristian Graus9-Dec-02 13:26 
GeneralRe: Need help with pointer in View Pin
E39-Dec-02 13:44
E39-Dec-02 13:44 
GeneralRe: Need help with pointer in View Pin
Christian Graus9-Dec-02 14:58
protectorChristian Graus9-Dec-02 14:58 
GeneralRe: Need help with pointer in View Pin
KarstenK9-Dec-02 21:37
mveKarstenK9-Dec-02 21:37 
GeneralRe: Need help with pointer in View Pin
Michael P Butler9-Dec-02 23:03
Michael P Butler9-Dec-02 23:03 
GeneralRe: Need help with pointer in View ( Got it working)... Pin
E310-Dec-02 4:40
E310-Dec-02 4:40 
GeneralWM_USER OR WM_APP How to Pin
tahirjhangvi9-Dec-02 11:21
tahirjhangvi9-Dec-02 11:21 
GeneralRe: WM_USER OR WM_APP How to Pin
jhwurmbach9-Dec-02 21:58
jhwurmbach9-Dec-02 21:58 
GeneralRe: WM_USER OR WM_APP How to Pin
tahirjhangvi10-Dec-02 3:47
tahirjhangvi10-Dec-02 3:47 
GeneralWord Wrap Pin
Dennis L9-Dec-02 10:45
Dennis L9-Dec-02 10:45 

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.