Mám hotové spínání motoru s výstupem přez COM port. Problém je, že je řešen přez 2 vlákna -> přivlastní si 50% procesoru (AMD Athlon X2 4000+). Jak ho mám předělat, aby si vzal minimum CPU.
Public Class PWM
Dim t As New Threading.Thread(AddressOf neco)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Sub neco()
SerialPort1.Open()
start:
If Label3.Text = "True" Then
GoTo start
Else
SerialPort1.RtsEnable = True
DELAY(Label10.Text)
SerialPort1.RtsEnable = False
DELAY(Label11.Text)
End If
GoTo start
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Label4.Text = "True" Then
Label3.Text = "False"
Else
Label4.Text = "True"
t.Start()
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Label3.Text = True
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
t.Abort()
End Sub
Private Sub HScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar1.Scroll
Label10.Text = (0 + HScrollBar2.Value) / HScrollBar1.Value
Label11.Text = (100 - HScrollBar2.Value) / HScrollBar1.Value
Label12.Text = CStr(CStr(HScrollBar2.Value) + "%")
End Sub
Private Sub HScrollBar2_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar2.Scroll
Label10.Text = (0 + HScrollBar2.Value) / HScrollBar1.Value
Label11.Text = (100 - HScrollBar2.Value) / HScrollBar1.Value
Label12.Text = CStr(CStr(HScrollBar2.Value) + "%")
End Sub
End Class
(pro prodlevu jsem použil "DELAY" z knihovny "Port.dll") Celý projekt VB.NET 2010: http://uloz.to/5981561/pwm.zip Pass: .net (+ ovládání joystickem přez SlimDX)
|