Ich hab da ein kleines Problemchen.
Ich habe ein Programm welches mir den Dezimalwert eines Registers zuschickt. Dieses Register steuert 5 Relais. Ich möchte , aus dem ausgelesenen Dezimalwert , die Bitreihenfolge errechnen und dadurch ein Visuelles Feedback geben können , welche Bits gesetzt sind , bzw welche Relais damit aktiv sind.
Bsp:
Ausgelesener Wert(Dec) : 7
Bitreihenfolge : 00111
Relais aktiv : Relais 0 , Relais 1 , Relais 2
Hat jmd ne Ahnung wie ich aus dem Decwert die Bits errechne und durch die Bitreihenfolge auslesen bestimmen kann welche Relais mir im Programm als Aktiv angezeigt werden sollen?
z.Z. benutze ich Rote Buttons für die einzelnen Relais , welche Grün werden ,falls das Relais aktiv ist.
Hier mal der Code zum reinschnuppern:
Spoiler anzeigen
Ich verstehe ums verrecken nicht wieso da immer so viele Leerzeilen sind -.- Ich schreib hier alles direkt aneinander.
Edit by hal2000:
- Extrem ausladendes Layout korrigiert.
Ich habe ein Programm welches mir den Dezimalwert eines Registers zuschickt. Dieses Register steuert 5 Relais. Ich möchte , aus dem ausgelesenen Dezimalwert , die Bitreihenfolge errechnen und dadurch ein Visuelles Feedback geben können , welche Bits gesetzt sind , bzw welche Relais damit aktiv sind.
Bsp:
Ausgelesener Wert(Dec) : 7
Bitreihenfolge : 00111
Relais aktiv : Relais 0 , Relais 1 , Relais 2
Hat jmd ne Ahnung wie ich aus dem Decwert die Bits errechne und durch die Bitreihenfolge auslesen bestimmen kann welche Relais mir im Programm als Aktiv angezeigt werden sollen?
z.Z. benutze ich Rote Buttons für die einzelnen Relais , welche Grün werden ,falls das Relais aktiv ist.
Hier mal der Code zum reinschnuppern:
VB.NET-Quellcode
- Private Sub cmd_zyklRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_zyklRead.Click
- If TimerRead.Enabled = False Then
- cmd_zyklRead.Text = "Lesen aktiv"
- TimerRead.Enabled = True
- TB_ShortAdr.ReadOnly = True
- TB_Reg.ReadOnly = True
- Else
- TimerRead.Enabled = False
- cmd_zyklRead.Text = "Zyklisches Lesen"
- cb_SingleAct.Checked = True
- TB_ShortAdr.ReadOnly = False
- TB_Reg.ReadOnly = False
- End If
- End Sub
- Private Sub cmd_rel0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_rel0.Click
- If cb_SingleAct.Checked = True Then
- writeReg(TB_ShortAdr.Text, 0, 1)
- End If
- If cb_SingleAct.Checked = False And cmd_rel0.BackColor = Color.Red Then
- writeReg(TB_ShortAdr.Text, 0, TB_ReadReg.Text + 1)
- End If
- If cb_SingleAct.Checked = False And cmd_rel0.BackColor = Color.Green Then
- writeReg(TB_ShortAdr.Text, 0, TB_ReadReg.Text - 1)
- End If
- End Sub
- Private Sub cmd_rel1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_rel1.Click
- If cb_SingleAct.Checked = True Then
- writeReg(TB_ShortAdr.Text, 0, 2)
- End If
- If cb_SingleAct.Checked = False And cmd_rel1.BackColor = Color.Red Then
- writeReg(TB_ShortAdr.Text, 0, TB_ReadReg.Text + 2)
- End If
- If cb_SingleAct.Checked = False And cmd_rel1.BackColor = Color.Green Then
- writeReg(TB_ShortAdr.Text, 0, TB_ReadReg.Text - 2)
- End If
- End Sub
- Private Sub cmd_rel2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_rel2.Click
- If cb_SingleAct.Checked = True Then
- writeReg(TB_ShortAdr.Text, 0, 4)
- End If
- If cb_SingleAct.Checked = False And cmd_rel2.BackColor = Color.Red Then
- writeReg(TB_ShortAdr.Text, 0, TB_ReadReg.Text + 4)
- End If
- If cb_SingleAct.Checked = False And cmd_rel2.BackColor = Color.Green Then
- writeReg(TB_ShortAdr.Text, 0, TB_ReadReg.Text - 4)
- End If
- End Sub
- Private Sub cmd_rel3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_rel3.Click
- If cb_SingleAct.Checked = True Then
- writeReg(TB_ShortAdr.Text, 0, 8)
- End If
- If cb_SingleAct.Checked = False And cmd_rel3.BackColor = Color.Red Then
- writeReg(TB_ShortAdr.Text, 0, TB_ReadReg.Text + 8)
- End If
- If cb_SingleAct.Checked = False And cmd_rel3.BackColor = Color.Green Then
- writeReg(TB_ShortAdr.Text, 0, TB_ReadReg.Text - 8)
- End If
- End Sub
- Private Sub cmd_rel4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_rel4.Click
- If cb_SingleAct.Checked = True Then
- writeReg(TB_ShortAdr.Text, 0, 16)
- End If
- If cb_SingleAct.Checked = False And cmd_rel4.BackColor = Color.Red Then
- writeReg(TB_ShortAdr.Text, 0, TB_ReadReg.Text + 16)
- End If
- If cb_SingleAct.Checked = False And cmd_rel4.BackColor = Color.Green Then
- writeReg(TB_ShortAdr.Text, 0, TB_ReadReg.Text - 16)
- End If
- End Sub
- Private Sub TimerStatus_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerStatus.Tick
- If TimerRead.Enabled = True Then
- cb_SingleAct.Visible = True
- Else
- cb_SingleAct.Visible = False
- End If
- Dim x As Integer
- x = readReg(TB_ShortAdr.Text, 0)
- Select Case x
- Case 1
- cmd_rel0.BackColor = Color.Green
- cmd_rel1.BackColor = Color.Red
- cmd_rel2.BackColor = Color.Red
- cmd_rel3.BackColor = Color.Red
- cmd_rel4.BackColor = Color.Red
- Case 2
- cmd_rel0.BackColor = Color.Red
- cmd_rel1.BackColor = Color.Green
- cmd_rel2.BackColor = Color.Red
- cmd_rel3.BackColor = Color.Red
- cmd_rel4.BackColor = Color.Red
- Case 3
- cmd_rel0.BackColor = Color.Green
- cmd_rel1.BackColor = Color.Green
- cmd_rel2.BackColor = Color.Red
- cmd_rel3.BackColor = Color.Red
- cmd_rel4.BackColor = Color.Red
- Case 4
- cmd_rel0.BackColor = Color.Red
- cmd_rel1.BackColor = Color.Red
- cmd_rel2.BackColor = Color.Green
- cmd_rel3.BackColor = Color.Red
- cmd_rel4.BackColor = Color.Red
- Case 5
- cmd_rel0.BackColor = Color.Green
- cmd_rel1.BackColor = Color.Red
- cmd_rel2.BackColor = Color.Green
- cmd_rel3.BackColor = Color.Red
- cmd_rel4.BackColor = Color.Red
- Case 6
- cmd_rel0.BackColor = Color.Red
- cmd_rel1.BackColor = Color.Green
- cmd_rel2.BackColor = Color.Green
- cmd_rel3.BackColor = Color.Red
- cmd_rel4.BackColor = Color.Red
- Case 7
- cmd_rel0.BackColor = Color.Green
- cmd_rel1.BackColor = Color.Green
- cmd_rel2.BackColor = Color.Green
- cmd_rel3.BackColor = Color.Red
- cmd_rel4.BackColor = Color.Red
- Case 8
- cmd_rel0.BackColor = Color.Red
- cmd_rel1.BackColor = Color.Red
- cmd_rel2.BackColor = Color.Red
- cmd_rel3.BackColor = Color.Green
- cmd_rel4.BackColor = Color.Red
- Case 9
- cmd_rel0.BackColor = Color.Green
- cmd_rel1.BackColor = Color.Red
- cmd_rel2.BackColor = Color.Red
- cmd_rel3.BackColor = Color.Green
- cmd_rel4.BackColor = Color.Red
- Case 10
- cmd_rel0.BackColor = Color.Red
- cmd_rel1.BackColor = Color.Green
- cmd_rel2.BackColor = Color.Red
- cmd_rel3.BackColor = Color.Green
- cmd_rel4.BackColor = Color.Red
- Case 11
- cmd_rel0.BackColor = Color.Green
- cmd_rel1.BackColor = Color.Green
- cmd_rel2.BackColor = Color.Red
- cmd_rel3.BackColor = Color.Green
- cmd_rel4.BackColor = Color.Red
- Case 12
- cmd_rel0.BackColor = Color.Red
- cmd_rel1.BackColor = Color.Red
- cmd_rel2.BackColor = Color.Green
- cmd_rel3.BackColor = Color.Green
- cmd_rel4.BackColor = Color.Red
- Case 13
- cmd_rel0.BackColor = Color.Green
- cmd_rel1.BackColor = Color.Red
- cmd_rel2.BackColor = Color.Green
- cmd_rel3.BackColor = Color.Green
- cmd_rel4.BackColor = Color.Red
- Case 14
- cmd_rel0.BackColor = Color.Red
- cmd_rel1.BackColor = Color.Green
- cmd_rel2.BackColor = Color.Green
- cmd_rel3.BackColor = Color.Green
- cmd_rel4.BackColor = Color.Red
- Case 15
- cmd_rel0.BackColor = Color.Green
- cmd_rel1.BackColor = Color.Green
- cmd_rel2.BackColor = Color.Green
- cmd_rel3.BackColor = Color.Green
- cmd_rel4.BackColor = Color.Red
- Case 16
- cmd_rel0.BackColor = Color.Red
- cmd_rel1.BackColor = Color.Red
- cmd_rel2.BackColor = Color.Red
- cmd_rel3.BackColor = Color.Red
- cmd_rel4.BackColor = Color.Green
- Case 17
- cmd_rel0.BackColor = Color.Green
- cmd_rel1.BackColor = Color.Red
- cmd_rel2.BackColor = Color.Red
- cmd_rel3.BackColor = Color.Red
- cmd_rel4.BackColor = Color.Green
- Case 18
- cmd_rel0.BackColor = Color.Red
- cmd_rel1.BackColor = Color.Green
- cmd_rel2.BackColor = Color.Red
- cmd_rel3.BackColor = Color.Red
- cmd_rel4.BackColor = Color.Green
- Case 19
- cmd_rel0.BackColor = Color.Green
- cmd_rel1.BackColor = Color.Green
- cmd_rel2.BackColor = Color.Red
- cmd_rel3.BackColor = Color.Red
- cmd_rel4.BackColor = Color.Green
- Case 20
- cmd_rel0.BackColor = Color.Red
- cmd_rel1.BackColor = Color.Red
- cmd_rel2.BackColor = Color.Green
- cmd_rel3.BackColor = Color.Red
- cmd_rel4.BackColor = Color.Green
- Case 21
- cmd_rel0.BackColor = Color.Green
- cmd_rel1.BackColor = Color.Red
- cmd_rel2.BackColor = Color.Green
- cmd_rel3.BackColor = Color.Red
- cmd_rel4.BackColor = Color.Green
- Case 22
- cmd_rel0.BackColor = Color.Red
- cmd_rel1.BackColor = Color.Green
- cmd_rel2.BackColor = Color.Green
- cmd_rel3.BackColor = Color.Red
- cmd_rel4.BackColor = Color.Green
- Case 23
- cmd_rel0.BackColor = Color.Green
- cmd_rel1.BackColor = Color.Green
- cmd_rel2.BackColor = Color.Green
- cmd_rel3.BackColor = Color.Red
- cmd_rel4.BackColor = Color.Green
- Case 24
- cmd_rel0.BackColor = Color.Red
- cmd_rel1.BackColor = Color.Red
- cmd_rel2.BackColor = Color.Red
- cmd_rel3.BackColor = Color.Green
- cmd_rel4.BackColor = Color.Green
- Case 25
- cmd_rel0.BackColor = Color.Green
- cmd_rel1.BackColor = Color.Red
- cmd_rel2.BackColor = Color.Red
- cmd_rel3.BackColor = Color.Green
- cmd_rel4.BackColor = Color.Green
- Case 26
- cmd_rel0.BackColor = Color.Red
- cmd_rel1.BackColor = Color.Green
- cmd_rel2.BackColor = Color.Red
- cmd_rel3.BackColor = Color.Green
- cmd_rel4.BackColor = Color.Green
- Case 27
- cmd_rel0.BackColor = Color.Green
- cmd_rel1.BackColor = Color.Green
- cmd_rel2.BackColor = Color.Red
- cmd_rel3.BackColor = Color.Green
- cmd_rel4.BackColor = Color.Green
- Case 28
- cmd_rel0.BackColor = Color.Red
- cmd_rel1.BackColor = Color.Red
- cmd_rel2.BackColor = Color.Green
- cmd_rel3.BackColor = Color.Green
- cmd_rel4.BackColor = Color.Green
- Case 29
- cmd_rel1.BackColor = Color.Red
- cmd_rel0.BackColor = Color.Green
- cmd_rel2.BackColor = Color.Green
- cmd_rel3.BackColor = Color.Green
- cmd_rel4.BackColor = Color.Green
- Case 30
- cmd_rel0.BackColor = Color.Red
- cmd_rel1.BackColor = Color.Green
- cmd_rel2.BackColor = Color.Green
- cmd_rel3.BackColor = Color.Green
- cmd_rel4.BackColor = Color.Green
- Case 31
- cmd_rel0.BackColor = Color.Green
- cmd_rel1.BackColor = Color.Green
- cmd_rel2.BackColor = Color.Green
- cmd_rel3.BackColor = Color.Green
- cmd_rel4.BackColor = Color.Green
- Case Else
- cmd_rel0.BackColor = Color.Red
- cmd_rel1.BackColor = Color.Red
- cmd_rel2.BackColor = Color.Red
- cmd_rel3.BackColor = Color.Red
- cmd_rel4.BackColor = Color.Red
- End Select
- End SubPrivate Sub TimerRead_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerRead.Tick
- TB_ReadReg.Text = readReg(TB_ShortAdr.Text, TB_Reg.Text)
- End Sub
- End Class
Ich verstehe ums verrecken nicht wieso da immer so viele Leerzeilen sind -.- Ich schreib hier alles direkt aneinander.
Edit by hal2000:
- Extrem ausladendes Layout korrigiert.
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „hal2000“ ()