| |

VerySource

 Forgot password?
 Register
Search
View: 3397|Reply: 20

How to solve the problem of high CPU usage during serial communication

[Copy link]

1

Threads

19

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-3-11 16:30:02
| Show all posts |Read mode
I am a monitoring system written in VB and need to communicate with the PLC serial port. I use the MSComm control to communicate, which can occupy a lot of CPU during communication
Does any expert know how to solve it?

Thank you
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-6-6 01:30:01
| Show all posts
Use a better machine
Reply

Use magic Report

0

Threads

3

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-6-25 18:45:01
| Show all posts
It is estimated that it is the problem of programming. If it is not necessary, do not communicate too often. In addition, the data processing code for sending and receiving should be well designed.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-6-27 19:00:01
| Show all posts
How about multithreading?
Reply

Use magic Report

0

Threads

6

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-6-28 11:00:02
| Show all posts
Try to use event-driven mode to avoid waiting in an endless loop
Reply

Use magic Report

0

Threads

10

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-7-4 05:15:02
| Show all posts
Always use MSComm, it should not be the problem of MSComm connection, let's focus on other places.
Reply

Use magic Report

1

Threads

19

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

 Author| Post time: 2020-7-7 12:15:02
| Show all posts
I use it now, the delay after transmission, the delay code is as follows:
'*************************************
Public Sub MyDelay(WaitTime As Single)
'*************************************
    Dim Wait As Single
    Wait = Timer + WaitTime
    Do
        DoEvents
    Loop Until (Timer> Wait)
    DoEvents
End Sub
I don't know if it is the problem of the above program, I tried to use the ONCOMM event, the code is as follows,
Private Sub MSC1_OnComm()
    If MSComm1.CommEvent = comEvReceive Then
        ...........
    End If
End Sub
I set a breakpoint in "Private Sub MSC1_OnComm()",
However, this event was not triggered when the serial port information was received

Please master help
Reply

Use magic Report

0

Threads

6

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-7-14 22:45:02
| Show all posts
It should be caused by your delay program. You can use the event trigger method. The communication event is not triggered. The Rthreshold attribute may be 0. It is the number of bytes that triggers the received event. Change it to 1 or what you want. Just the number of bytes.
Reply

Use magic Report

0

Threads

9

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-7-15 13:00:01
| Show all posts
The buffer is set larger, do not trigger the event every time a character is received
Reply

Use magic Report

1

Threads

19

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

 Author| Post time: 2020-7-24 17:30:01
| Show all posts
Thank you, everyone upstairs for your help, the CPU problem is solved, but there are other problems,

If I want to trigger an OnComm event every 10 bytes, Rthreshold must be set to 10. At the beginning, if Rthreshold is set to a number less than 10, it will trigger multiple ONCOMM events, but I don’t know what happened later. , As long as Rthreshold is set to a number from 1 to 10, the OnComm event is triggered only once, not multiple times.

I have been unable to understand why this is,

Please expert help.
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