| |

VerySource

 Forgot password?
 Register
Search
View: 838|Reply: 4

I use the serial port receiving program written by mscomm control. It can be received between two computers. I have a qu

[Copy link]

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-25 22:20:01
| Show all posts |Read mode
Experiment between two computers, the software can receive the data sent from the serial port of the other computer (use the serial debugging tool to send manually or automatically).
But when sending data with a single-chip microcomputer, the software can receive a little bit of data and directly pop up an error saying that the program should be closed; or there is no response and no data is received.
The serial event source is:
void CSerialView :: OnOnCommMscomm1 ()
{
   // TODO: Add your control notification handler code here
Ranch
    VARIANT variant_inp;
    COleSafeArray safearray_inp;
    LONG len, k;
    BYTE rxdata [2048]; // Set BYTE array An 8-bit integerthat is not signed.
    CString strtemp;

    
if (m_comm.GetCommEvent () == 2) // Event value 2 means there are characters in the receive buffer
    {///////// Add processing code below
        variant_inp = m_comm.GetInput (); // Read buffer
        safearray_inp = variant_inp; // VARIANT type variables are converted to ColeSafeArray type variables
        len = safearray_inp.GetOneDimSize (); // Get effective data length
        for (k = 0; k <len; k ++)
            safearray_inp.GetElement (&k, rxdata + k); // Convert to BYTE type array and save it to a file later
        for (k = 0; k <len; k ++) // Convert an array to a Cstring variable
{
            BYTE bt = * (char *) (rxdata + k); // character
            strtemp.Format ("% c", bt); // Send characters to the temporary variable strtemp to store
Ranch
            m_strRXData + = strtemp; // Add the corresponding string to the receive edit box
}
FILE * pFile = fopen ("ecg.dat", "ab +"); // Append to open a binary (b) file
fwrite (rxdata, 1, len, pFile); // write file
fflush (pFile);
    }
    UpdateData (FALSE); // Update edit box content

}
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-3-17 15:00:01
| Show all posts
My program is also a reference to the debugging assistant, but there are problems. Will there be similar bugs with controls? The data sent by my microcontroller is 512byte / s
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-6-29 09:15:01
| Show all posts
Please help yourself, what is the reason?
Reply

Use magic Report

0

Threads

17

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-8-22 10:45:01
| Show all posts
See if the serial port settings of the microcontroller are the same as the PC, baud rate, parity bit, stop bit, etc.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-22 12:00:01
| Show all posts
Don't you debug it? See where the problem is
Your code is copied from Mr. Gong's code. . . This was no problem when I was studying
Maybe somewhere else

FILE *pFile=fopen("ecg.dat","ab+");//Open binary (b) file additionally
fwrite(rxdata,1,len,pFile);//write file

For example, open fails. . To add pFile judgment
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list