C writes serial port programs, sometimes the window freezes when opening or closing the serial port

Updated on technology 2024-03-15
10 answers
  1. Anonymous users2024-02-06

    while (m_isreceiving)

    The interface is stuck with DoEvents

    You're in an endless loop!! It's going to get stuck!!

  2. Anonymous users2024-02-05

    Is the interface stuck? Was there still data being received at the time?

    It is recommended to use multi-threading for data processing.

  3. Anonymous users2024-02-04

    Hello! If you don't close the serial port and unplug the serial port, there will definitely be an error, so you can judge whether the serial port is open when sending data.

  4. Anonymous users2024-02-03

    There is no such detection technology, because although different peripherals use serial port protocols, but for different inputs, even if the peripherals are linked, there will not necessarily be return data, and the serial port itself does not have the function of self-testing, so the serial port can only be opened, and it is impossible to know exactly whether there are peripherals connected, even if the upstairs says that it will not work with timeout.

  5. Anonymous users2024-02-02

    serialport= new serialport(com, baudrate, parity, databits, stopbits);

    Then you can do it.

    Be sure to close the serial port when the program exits.

  6. Anonymous users2024-02-01

    You should start a new thread, or use the backgroundworker to perform the interface update and send and receive.

    You are currently putting all the processing in one main thread, and the interface update is in this main thread, which will inevitably cause the interface to freeze.

    The execution of a thread is equivalent to procedural execution, which is sequential execution, which will inevitably have an impact on interface updates or data sending and receiving when an operation takes time.

    You can email me the source** to see.

  7. Anonymous users2024-01-31

    In your from1, declare the serial port as a static variable, e.g. public static serialport sp=new serialport();

    After that, you can directly use it in form2 to control the serial port, as for saving the settings, there are many ways, you can use the registry or ini (you can check the read and write of ini in c and find it yourself), when you open the serial port at form2, first save the above settings to ini, and then open it, also in the load of form2, read these settings first, and then assign these drop-down lists above according to the settings.

    Note: Generally speaking, your form2 does not start the serial port, but sets the serial port (that is, writes the settings to the ini), and starts and stops the serial port in form1 (also reads the ini loading settings when starting).

  8. Anonymous users2024-01-30

    Upstairs, that's not okay, if you want to do that, it's to start the form, and if it's over, all the forms are closed, so you hide the form when you start the first window, and then you start the second form, and in the second form, write: form1 f1; Add the argument form1 f1 to the constructor in the second form, and then give the argument to f1 in the function; f1 = f1;Then you can write the login if the login is successful ; Close form2; So it can be very simple.

  9. Anonymous users2024-01-29

    Write the settings to a txt file and read them the next time you start them.

    It can also be written in INI, XML, etc.

  10. Anonymous users2024-01-28

    Very strange question.

    For serial ports, the speed of data reception depends entirely on the sending speed of the other party.

    If there is a blockage in the receiving section, then the data may be lost and incomplete, but it will not be slow.

    Because the sender won't "cooperate" with you to slow down the send.

    Unless it's a question-and-answer protocol, then the speed depends on the frequency of the inquiry, and you should check that part of the **.

Related questions
7 answers2024-03-15

Out of the circle problem, this question is more classic, but at the same time slow and difficult, I have seen an algorithm, but the efficiency is not very high, and I haven't come up with it myself. >>>More

8 answers2024-03-15

I haven't studied how to select this problem after finding it.,I don't know if richTextBox can be implemented.,If it's just a search, it shouldn't be difficult.。

4 answers2024-03-15

Cite month[12][10]; Wrong. Without the element month[12][10], up to month[11][9], and the pointer p is useless. There's also the deletion of all your +10-level corresponding *. >>>More

4 answers2024-03-15

You use a P1 port to control the dynamic scanning of 8 digital tubes, and the dynamic scanning display of digital tubes needs to be blanked. >>>More

5 answers2024-03-15

bool f=0;

for(int i=1000;i>=1;i--) Start with the largest number of 1000 and try to the smaller number. >>>More