http://www.codeproject.com/KB/vb/PortAcc... podle tohoto jsem stvořil toto:
Public Class Form1
Inherits Form
Dim sum As Byte
Public intAddress As Integer
Public intVal2Write As Integer
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
'Declare variables to store read information and Address
'values
Dim intAddress As Integer, intReadVal As Integer
If ComboBox1.Text = Nothing Then
Else
'Get the address from the Textbox
intAddress = Convert.ToInt32(ComboBox1.Text)
'Read the corresponding value and store
intReadVal = porting.Inp(intAddress)
TextBox2.Text = intReadVal.ToString()
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
bintodec()
'Dim intAddress As Integer, intVal2Write As Integer
'Get the address from the Textbox
If Not ComboBox1.Text = Nothing Then
intAddress = Convert.ToInt16(ComboBox1.Text)
'Read the corresponding value and store
intVal2Write = Convert.ToString(sum)
'porting is the name of the module
porting.Out(intAddress, intVal2Write)
End If
sum = 0
End Sub
Sub bintodec()
If CheckBox1.Checked = True Then
sum = 1
End If
If CheckBox2.Checked = True Then
sum = sum + 2
End If
If CheckBox3.Checked = True Then
sum = sum + 4
End If
If CheckBox4.Checked = True Then
sum = sum + 8
End If
If CheckBox5.Checked = True Then
sum = sum + 16
End If
If CheckBox6.Checked = True Then
sum = sum + 32
End If
If CheckBox7.Checked = True Then
sum = sum + 64
End If
If CheckBox8.Checked = True Then
sum = sum + 128
End If
Label3.Text = CStr(sum)
End Sub
a následně toto:
Public Class Form1
Inherits Form
Dim t As New Threading.Thread(AddressOf write)
Dim sum As Byte
Public intAddress As Integer
Public intVal2Write As Integer
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
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
t.Start(
End Sub
Sub write()
start:
sum = 64
intAddress = Convert.ToInt16(1912)
'Read the corresponding value and store
intVal2Write = Convert.ToString(sum)
'porting is the name of the module
porting.Out(intAddress, intVal2Write)
Threading.Thread.Sleep(Label10.Text)
sum = 0
intAddress = Convert.ToInt16(1912)
'Read the corresponding value and store
intVal2Write = Convert.ToString(sum)
'porting is the name of the module
porting.Out(intAddress, intVal2Write)
Threading.Thread.Sleep(Label11.Text)
GoTo start
End Sub
End Class
Výsledek je zapínaní/vypínaní pinu po uplynutí doby nastavené pomocí scrollbarů. Bohužel je to pouze pro jeden výstup z LPT portu (konkrétně 8.) Tento kód chci rozšířit pro všech 8 výstupů
|