-
January 24th, 2011, 10:12 AM
#1
Help Needed for CSerialPort v1.27
I'm trying to get a C++ MFC SDI working using VS 2008 which takes a 6-bit binary value sent from a PIC16f877a through an RS232 line to a GUI. All I need the GUI to do is display the value sent to it, by an event handler on a button. I'm using Naughter's CSerialPort v1.27 (http://www.naughter.com/serialport.html).
So my code compiles ok, but doesn't display anything. I'm a complete beginner to C++ and MFC but this is the code I have for the event handler:
Code:
void CWECSGUI10View::OnBnClickedBtnVlt()
{
// TODO: Add your control notification handler code here
try
{
// opens comport 1
CSerialPort port;
port.Open(1, 115200, CSerialPort::NoParity, 8,
CSerialPort::OneStopBit,
CSerialPort::XonXoffFlowControl, TRUE);
// reads RS232 input
port.Read(m_Voltin,1);
// display data
CString strVoltage;
double voltage;
strVoltage.Format(_T("%.3f"), voltage);
this->m_Voltin.SetWindowTextW(strVoltage);
port.Flush();
port.Close();
}
catch (CSerialException* pEx)
{
TRACE(_T("Handle Exception, Message:%s\n"),
pEx->GetErrorMessage());
pEx->Delete();
}
}
What am I doing wrong and how can I correct it?
Just to make the information complete, on the PIC side of things I'm compiling with BoostC. My code has been verified with another app to send a 6-bit value through a 10-bit ADC module but here it is anyway:
Code:
#include <rs232_driver.h>
#include <adc.h>
.... default configuration etc ...
while( 1 )
{
voltage = adc_measure(0)>>4;
delay_ms( 250 );
uart_init(1,10);
putc(voltage);
}
Also to make the information complete, I added the m_Voltin variable to the form class as a public control edit variable.
Last edited by VictorN; May 27th, 2014 at 08:24 AM.
Reason: Added CODE tags
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|