Mit der Relaiskarte steuere ich einen Motor an. Das 1. Relais startet/stoppt den Motor und das 2. Relais dient zur Bestimmung der Laufrichtung (links- oder rechtsrum).
Im SDK von Code Mercenaries gibt es u. a. ein Beispiel für Visual Basic 6 (so wie ich's benötige). Leider konnte ich damit nicht herausfinden, wie ich die beiden Relais schalte.
Ich habe nun aber entdeckt, dass bei den vielen Beispielprogrammen im SDK auch ein funktionierendes mit Code dabei ist, geschrieben in Delphi ("\Windows\samples\Simple IO\Delphi\LEDs DLL"). Zwar kenne ich eigentlich Delphi, da ich damit von 2001 bis 2006 täglich programmiert habe, aber trotzdem habe ich eine Umsetzung in VB6 bisher nicht hinbekommen.
Die einzige wirklich relevante Stelle im Delphi-Quellcode ist das hier:
Code: Select all
procedure TMainForm.LEDClick(Sender: TObject);
var
LEDByte: Integer;
I: Integer;
Report: IOWKIT56_IO_REPORT;
begin
if not Assigned(IOWarrior) then
Exit;
// initialize report to not interfere with input
FillChar(Report, IOWKIT56_IO_REPORT_SIZE, $FF);
Report.ReportID := 0;
// the LEDs are connected to different ports
case Pid of
IOWKIT_PID_IOW40:
LEDByte := 3;
IOWKIT_PID_IOW24:
LEDByte := 0;
IOWKIT_PID_IOW56:
LEDByte := 6;
else
LEDByte := 0;
end;
for I := Low(LEDs) to High(LEDs) do
// translate SpeedButton state into correct bit in the byte
// IO-Warrior uses negative logic
if LEDs[I].Down then
// set the bit to 0 to switch the LED on
Report.Bytes[LEDByte] := Report.Bytes[LEDByte] and not (1 shl I)
else
// set the bit to 1 to switch the LED off
Report.Bytes[LEDByte] := Report.Bytes[LEDByte] or (1 shl I);
// write the bits to the IO-Warrior
case Pid of
IOWKIT_PID_IOW40:
IowKitWrite(IOWarrior, IOW_PIPE_IO_PINS, PChar(@Report), IOWKIT40_IO_REPORT_SIZE);
IOWKIT_PID_IOW24:
IowKitWrite(IOWarrior, IOW_PIPE_IO_PINS, PChar(@Report), IOWKIT24_IO_REPORT_SIZE);
IOWKIT_PID_IOW56:
IowKitWrite(IOWarrior, IOW_PIPE_IO_PINS, PChar(@Report), IOWKIT56_IO_REPORT_SIZE);
end;
end;
Code: Select all
Private Sub iowWrite(ByVal motor As Byte, ByVal richtung As Byte)
' Write value
Dim Res As Long
Dim N As Long
Dim Pid As Long
Pid = IowKitGetProductId(iowHandles(0))
If Pid = IOWKIT_PID_IOW24 Then
N = 3
Else
If Pid = IOWKIT_PID_IOW40 Then
N = 5
Else
If Pid = IOWKIT_PID_IOW56 Then
N = 8
End If
End If
End If
' Report ID 0
data(0) = 0
If motor = 0 Then
data(1) = data(1) Or (ShiftLeft(1, 0))
Else
data(1) = data(1) And Not (ShiftLeft(1, 0))
End If
If richtung = 0 Then
data(2) = data(2) Or (ShiftLeft(1, 1))
Else
data(2) = data(2) And Not (ShiftLeft(1, 1))
End If
' Write to IOW
Res = IowKitWrite(iowHandles(0), IOW_PIPE_IO_PINS, data(0), N)
' Handle error
If Res <> N Then
' You can get error code from GetLastError()
MsgBox "ioWarrior: Write to IOW failed!", 0, "Error"
End If
End Sub
Die Werte data(1..7) wurden mit &HFF initialisiert.
Ich muss zugeben, dass ich mich mit Bit"schubsereien" nicht wirklich auskenne.
Hat jemand eine Idee? Ich kann gerne weitere Quellcodes nachreichen, falls diese zu einer Lösung führen können.