Re: Please help with this.
From: Ed (Ed_at_whyshouldItell.me)
Date: 02/19/05
- Next message: Al Koch: "How Use ShellExecute with a CMemFile"
- Previous message: Ed: "Re: Receiving single bytes with MSComm"
- In reply to: Bill Thompson: "Re: Please help with this."
- Next in thread: Bill Thompson: "Re: Please help with this."
- Reply: Bill Thompson: "Re: Please help with this."
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 19 Feb 2005 01:46:25 GMT
Hi,
I still cannot get the receive working.
This is the last thing I have tried and all I get is garbage back.
All I seem to get is 0x01 even when I am supposed to get text.
Please take a look and feel free to suggest. I really need binary to work.
void CPSMDlg::OnOnCommMscomm1()
{
Char ed[2048];
FILE *in;
COleVariant Value;
if (m_comm.GetCommEvent() == 2)
{
Value = m_comm.GetInput();
CString Buffer = V_BSTR(&Value);
ed[current]=Buffer[0];
ed[current+1]=0x00;
in = fopen("c:\\psm\\a1.dat", "wb");
fwrite(ed, current, 1, in);
fclose(in);
current++;
AfxMessageBox(Buffer);
}
}
current is a count thats reset before I request any data.
Thanks in advance,
Ed
-----------------------------------------------------------------------------
"Bill Thompson" <billt61@rgv.rr.com> wrote in message
news:uvGB4vXFFHA.3888@TK2MSFTNGP12.phx.gbl...
> "Ed" <Ed@whyshouldItell.me> wrote in message
> news:K28Rd.23829$ya6.12297@trndny01...
>> Please someone help me out with this.
>> I preferr not to change horses in mid race with this by switching serial
>> routines.
>>
>> I know I am doing something wrong. My transmit works just fine. I am set
> to
>> binary mode as I need to do transfer in binary. I cannot get any received
>> data. Here is parts of my code that apply.
>>
>> bool CPSMDlg::sendMicroProgram()
>> {
>> int a, b;
>> unsigned char ede[20000];
>> FILE *in;
>>
>> a=0;
>> b=0;
>> lop:
>> Sleep(10);
>>
>> if (rx1 == 0){
>> a++;
>> if (a <= 100)
>> goto lop;
>> }
>> if (rx1 == 1){
>> AfxMessageBox("rx1 = 1");
>> GetChar();
>> if (get == 0xee){
>> AfxMessageBox("Got EE");
>> return true;
>> }
>> rx1=0;
>> ede[b] = get;
>> a++;
>> b++;
>> if (a <= 100)
>> goto lop;
>> in = fopen("c:\\psm\\a1.dat", "wb");
>> fwrite (ede, b, 1, in);
>> fclose(in);
>> AfxMessageBox("Did Not Get EE");
>> }
>> AfxMessageBox("Did Not Get EE");
>> return;
>> }
>>
>> bool CPSMDlg::SendChar() // this routine works perfectly
>> {
>> CByteArray btArray;
>>
>> btArray.Add (DataByte);
>> COleVariant var(btArray);
>> m_comm.SetOutput(var);
>> return true;
>> }
>>
>> bool CPSMDlg::GetChar() // I know I am doing something wrong here
>> {
>> COleVariant myVar;
>> CString sBuffer;
>> myVar.Attach (m_comm.GetInput());
>> sBuffer = myVar.bstrVal;
>> get=sBuffer[0];
>> return true;
>> }
>>
>> void CPSMDlg::OnOnCommMscomm1()
>> {
>> // TODO: Add your control notification handler code here
>> rx1=1;
>> }
>>
>>
>> I need to send a program to my monitor within my microcontroller and that
>> works just fine and the program starts just fine so i know data is being
>> sent ok.
>> Please modify my code so I can receive single bytes to be evaluated .
>> Thanks in advance.
>>
>>
>
> Since nobody has replied, I'll take a shot.
>
> I'm assuming that m_comm is an instance of the CCommCtrl class. If not,
> read no further.
>
> Obviously you need something like an interrupt service routine to receive
> characters in a timely fashion. I have cut and paste this from code that
> I
> have laying around that I have not used in years (but was working);
> hopefully it may get you on the right track.
>
> // Add an eventsink map to hook the OnComm event:
>
> BEGIN_EVENTSINK_MAP(MyDialog, CDialog)
> ON_EVENT(MyDialog, ID_COMMCTRL, 1 /* OnComm */, OnCommEvent, VTS_NONE)
> END_EVENTSINK_MAP()
>
> // sample OnCommEvent handler:
>
> void MyDialog::OnCommEvent()
> {
> switch(m_comm.GetCommEvent())
> {
> case 2: // vbMSCommEvReceive:
> ProcessData(m_commctrl.GetInput());
> }
>
> void MyDialog::ProcessData(LPCTSTR pchData)
> {
> // do something with the data
> }
>
>
> //this goes in the .h file for the CPSMDlg:
> class CPSMDlg : public CDialog
> {
> ...
> protected:
> afx_msg void OnCommEvent();
> DECLARE_EVENTSINK_MAP()
> ...
> }
>
> // You probably already have code that looks like this somewhere:
>
> BOOL MyDialog::OnInitDialog()
> {
> ...
> // Create the MSCOMM32 OLE Control.
> if (!m_commctrl.Create(NULL,0,CRect(0,0,0,0),this,ID_COMMCTRL))
> {
> TRACE0("Failed to create OLE Communications Control\n");
> return -1; // fail to create
> }
>
> // Set RThreshold property to 1. The default RThreshold value (0)
> // causes the OnComm event to NOT fire when a character is detected
> // in the serial port.
> m_commctrl.SetRThreshold(1);
> ...
> }
>
>
>
>
- Next message: Al Koch: "How Use ShellExecute with a CMemFile"
- Previous message: Ed: "Re: Receiving single bytes with MSComm"
- In reply to: Bill Thompson: "Re: Please help with this."
- Next in thread: Bill Thompson: "Re: Please help with this."
- Reply: Bill Thompson: "Re: Please help with this."
- Messages sorted by: [ date ] [ thread ]