Hallo Rainer, vielen Dank für Deine schnelle Antwort.
Ich poste hier mal die Scripte:
Script 1 ist das Beispiel für LED an /aus das ich umschreiben soll, bzw. in das ich die einzelnen Befehle einsetzen soll.
Hier also Script 1
___________________________________________________________
- Teil Beispiel (Bsp.frm)
’ Private Declare Sub Sleep Lib „kernel32“ (ByVal dwMilliseconds As Long)
Dim lngNumDevices As Long
Dim strSerienNummer As String * 16
Dim strBeschreibung As String * 256
Private Sub CbTxD_Click()
On Error GoTo CbTxD_Click_fehler
’ Anzeige bereinigen
LoggerList.Clear
’ Anzahl angeschlossener USB Geräte
If FT_GetNumDevices(lngNumDevices, vbNullString, FT_LIST_BY_NUMBER_ONLY) FT_OK Then
LoggerList.AddItem („Fehler bei Aufruf: FT_GetNumDevices funktionierte nicht“)
Exit Sub
Else
LoggerList.AddItem ("Anzahl vorhandener USB Geräte: " & lngNumDevices)
End If
strBeschreibung = Trim(Me.DeviceName.Text) & Chr(0)
If FT_OpenEx(strBeschreibung, FT_OPEN_BY_DESCRIPTION, lngHandle) FT_OK Then
LoggerList.AddItem „Fehler bei Aufruf: FT_OpenEx“
Exit Sub
Else
LoggerList.AddItem „----“
End If
If Me.CbTxD.Value Then
If FT_SetBreakOn(lngHandle) = FT_OK Then
LoggerList.AddItem „Break ON - LED an?“
End If
Else
If FT_SetBreakOff(lngHandle) = FT_OK Then
LoggerList.AddItem „Break OFF“
End If
End If
If FT_Close(lngHandle) FT_OK Then
LoggerList.AddItem „Fehler bei Aufruf: FT_Close“
Exit Sub
Else
LoggerList.AddItem „----“
End If
CbTxD_Click_fehler_ende:
Exit Sub
CbTxD_Click_fehler:
MsgBox Err.Description
Resume CbTxD_Click_fehler_ende
End Sub
Private Sub DeviceName_Change()
End Sub
Private Sub Form_Load()
End Sub
Private Sub Label2_Click()
End Sub
_____________________________________________________
- Teil Beispiel (Module.bas)
Option Explicit
'====================================
'INTERFACE DEKlarationen für FTDI DLL
'====================================
Public Declare Function FT_ListDevices Lib „FTD2XX.DLL“ ( _
ByVal arg1 As Long, _
ByVal arg2 As String, _
ByVal dwFlags As Long) As Long
Public Declare Function FT_GetNumDevices Lib „FTD2XX.DLL“ Alias „FT_ListDevices“ ( _
ByRef arg1 As Long, _
ByVal arg2 As String, _
ByVal dwFlags As Long) As Long
Public Declare Function FT_Open Lib „FTD2XX.DLL“ ( _
ByVal intDeviceNumber As Integer, _
ByRef lngHandle As Long) As Long
Public Declare Function FT_OpenEx Lib „FTD2XX.DLL“ ( _
ByVal arg1 As String, _
ByVal arg2 As Long, _
ByRef lngHandle As Long) As Long
Public Declare Function FT_Close Lib „FTD2XX.DLL“ ( _
ByVal lngHandle As Long) As Long
Public Declare Function FT_Read Lib „FTD2XX.DLL“ ( _
ByVal lngHandle As Long, _
ByVal lpszBuffer As String, _
ByVal lngBufferSize As Long, _
ByRef lngBytesReturned As Long) As Long
Public Declare Function FT_Write Lib „FTD2XX.DLL“ ( _
ByVal lngHandle As Long, _
ByVal lpszBuffer As String, _
ByVal lngBufferSize As Long, _
ByRef lngBytesWritten As Long) As Long
Public Declare Function FT_WriteByte Lib „FTD2XX.DLL“ Alias „FT_Write“ ( _
ByVal lngHandle As Long, _
ByRef lpszBuffer As Any, _
ByVal lngBufferSize As Long, _
ByRef lngBytesWritten As Long) As Long
Public Declare Function FT_SetBaudRate Lib „FTD2XX.DLL“ ( _
ByVal lngHandle As Long, _
ByVal lngBaudRate As Long) As Long
Public Declare Function FT_SetDataCharacteristics Lib „FTD2XX.DLL“ ( _
ByVal lngHandle As Long, _
ByVal byWordLength As Byte, _
ByVal byStopBits As Byte, _
ByVal byParity As Byte) As Long
Public Declare Function FT_SetFlowControl Lib „FTD2XX.DLL“ ( _
ByVal lngHandle As Long, _
ByVal intFlowControl As Integer, _
ByVal byXonChar As Byte, _
ByVal byXoffChar As Byte) As Long
Public Declare Function FT_SetDtr Lib „FTD2XX.DLL“ ( _
ByVal lngHandle As Long) As Long
Public Declare Function FT_ClrDtr Lib „FTD2XX.DLL“ ( _
ByVal lngHandle As Long) As Long
Public Declare Function FT_SetRts Lib „FTD2XX.DLL“ ( _
ByVal lngHandle As Long) As Long
Public Declare Function FT_ClrRts Lib „FTD2XX.DLL“ ( _
ByVal lngHandle As Long) As Long
Public Declare Function FT_GetModemStatus Lib „FTD2XX.DLL“ ( _
ByVal lngHandle As Long, _
ByRef lngModemStatus As Long) As Long
Public Declare Function FT_SetChars Lib „FTD2XX.DLL“ ( _
ByVal lngHandle As Long, _
ByVal byEventChar As Byte, _
ByVal byEventCharEnabled As Byte, _
ByVal byErrorChar As Byte, _
ByVal byErrorCharEnabled As Byte) As Long
Public Declare Function FT_Purge Lib „FTD2XX.DLL“ ( _
ByVal lngHandle As Long, _
ByVal lngMask As Long) As Long
Public Declare Function FT_SetTimeouts Lib „FTD2XX.DLL“ ( _
ByVal lngHandle As Long, _
ByVal lngReadTimeout As Long, _
ByVal lngWriteTimeout As Long) As Long
Public Declare Function FT_GetQueueStatus Lib „FTD2XX.DLL“ ( _
ByVal lngHandle As Long, _
ByRef lngRxBytes As Long) As Long
Public Declare Function FT_SetBreakOn Lib „FTD2XX.DLL“ ( _
ByVal lngHandle As Long) As Long
Public Declare Function FT_SetBreakOff Lib „FTD2XX.DLL“ ( _
ByVal lngHandle As Long) As Long
Public Declare Function FT_GetStatus Lib „FTD2XX.DLL“ ( _
ByVal lngHandle As Long, _
ByRef lngRxBytes As Long, _
ByRef lngTxBytes As Long, _
ByRef lngEventsDWord As Long) As Long
Public Declare Function FT_SetEventNotification Lib „FTD2XX.DLL“ ( _
ByVal lngHandle As Long, _
ByVal dwEventMask As Long, _
ByVal pVoid As Long) As Long
Public Declare Function FT_ResetDevice Lib „FTD2XX.DLL“ ( _
ByVal lngHandle As Long) As Long
Public Declare Function FT_GetBitMode Lib „FTD2XX.DLL“ ( _
ByVal lngHandle As Long, _
ByRef intData As Any) As Long
Public Declare Function FT_SetBitMode Lib „FTD2XX.DLL“ ( _
ByVal lngHandle As Long, _
ByVal intMask As Byte, _
ByVal intMode As Byte) As Long
Public Declare Function FT_SetLatencyTimer Lib „FTD2XX.DLL“ ( _
ByVal Handle As Long, _
ByVal pucTimer As Byte) As Long
Public Declare Function FT_GetLatencyTimer Lib „FTD2XX.DLL“ ( _
ByVal Handle As Long, _
ByRef ucTimer As Long) As Long
’ Return codes
Public Const FT_OK = 0
Public Const FT_INVALID_HANDLE = 1
Public Const FT_DEVICE_NOT_FOUND = 2
Public Const FT_DEVICE_NOT_OPENED = 3
Public Const FT_IO_ERROR = 4
Public Const FT_INSUFFICIENT_RESOURCES = 5
Public Const FT_INVALID_PARAMETER = 6
Public Const FT_INVALID_BAUD_RATE = 7
Public Const FT_DEVICE_NOT_OPENED_FOR_ERASE = 8
Public Const FT_DEVICE_NOT_OPENED_FOR_WRITE = 9
Public Const FT_FAILED_TO_WRITE_DEVICE = 10
Public Const FT_EEPROM_READ_FAILED = 11
Public Const FT_EEPROM_WRITE_FAILED = 12
Public Const FT_EEPROM_ERASE_FAILED = 13
Public Const FT_EEPROM_NOT_PRESENT = 14
Public Const FT_EEPROM_NOT_PROGRAMMED = 15
Public Const FT_INVALID_ARGS = 16
Public Const FT_NOT_SUPPORTED = 17
Public Const FT_OTHER_ERROR = 18
’ Flags für FT_OpenEx
Public Const FT_OPEN_BY_SERIAL_NUMBER = 1
Public Const FT_OPEN_BY_DESCRIPTION = 2
’ Flags für FT_ListDevices
Public Const FT_LIST_BY_NUMBER_ONLY = &H80000000
Public Const FT_LIST_BY_INDEX = &H40000000
Public Const FT_LIST_ALL = &H20000000
’ IO buffer
Public Const FT_In_Buffer_Size = 1024
Public Const FT_Out_Buffer_Size = 1024
Public FT_In_Buffer As String * FT_In_Buffer_Size
Public FT_Out_Buffer As String * FT_Out_Buffer_Size
Public FT_IO_Status As Long
Public FT_Result As Long
Public FT_Device_Count As Long
Public FT_Device_String_Buffer As String * 50
Public FT_Device_String As String
Global lngHandle As Long
Public FT_HANDLE As Long
Public Sub FT_Error_Report(ErrStr As String, PortStatus As Long)
’ Fehlermeldungen
Dim Str As String
Select Case PortStatus
Case FT_INVALID_HANDLE
Str = ErrStr & " - Invalid Handle"
Case FT_DEVICE_NOT_FOUND
Str = ErrStr & " - Device Not Found"
Case FT_DEVICE_NOT_OPENED
Str = ErrStr & " - Device Not Opened"
Case FT_IO_ERROR
Str = ErrStr & " - General IO Error"
Case FT_INSUFFICIENT_RESOURCES
Str = ErrStr & " - Insufficient Resources"
Case FT_INVALID_PARAMETER
Str = ErrStr & " - Invalid Parameter"
Case FT_INVALID_BAUD_RATE
Str = ErrStr & " - Invalid Baud Rate"
Case FT_DEVICE_NOT_OPENED_FOR_ERASE
Str = ErrStr & " - Device not opened for Erase"
Case FT_DEVICE_NOT_OPENED_FOR_WRITE
Str = ErrStr & " - Device not opened for Write"
Case FT_FAILED_TO_WRITE_DEVICE
Str = ErrStr & " - Failed to write Device"
Case FT_EEPROM_READ_FAILED
Str = ErrStr & " - EEPROM read failed"
Case FT_EEPROM_WRITE_FAILED
Str = ErrStr & " - EEPROM write failed"
Case FT_EEPROM_ERASE_FAILED
Str = ErrStr & " - EEPROM erase failed"
Case FT_EEPROM_NOT_PRESENT
Str = ErrStr & " - EEPROM not present"
Case FT_EEPROM_NOT_PROGRAMMED
Str = ErrStr & " - EEPROM not programmed"
Case FT_INVALID_ARGS
Str = ErrStr & " - Invalid Arguments"
Case FT_NOT_SUPPORTED
Str = ErrStr & " - not supported"
Case FT_OTHER_ERROR
Str = ErrStr & " - other error"
End Select
End Sub
____________________________________________________
Diese Datei soll ich also modifizieren und dort die Befehle einsetzen die ich zuvor beschrieben habe. ZUsätzlich soll ich aus dem folgenden Script den Timer und die Sleepfunktion hier einsetzen.
Hier nun also das zweite Script mit dem Timer (es ist eine SOftwareampelschaltung aber eben noch ohne direkte Befehle an den Ausgang. Das ganze wird über einen USB-RS232 gesteuert, da ist ein zusätzliches Steckbord dran in das man die drei LEDs einstecken muss. Schade dass man hier keine BIlder schicken kann.
________________________________________________
Hier also Scipt 2 (Softwareampelschaltung)
(Ampelf.frm)der des Projektes Ample.vbp
Option Explicit
Private ModusLicht As Boolean
Private AmpelLichtNummer As Integer
Private AmpelBlinkNummer As Integer
Private Sub comStartAmpelLicht_Click()
If comStartAmpelLicht.Caption = „Start“ Then
comStartAmpelLicht.Caption = „Stopp“
comStartAmpelBlink.Enabled = False
ModusLicht = True
AmpelLichtNummer = 0
Timer1.Enabled = True
Else
Timer1.Enabled = False
comStartAmpelLicht.Caption = „Start“
comStartAmpelLicht.Enabled = True
comStartAmpelBlink.Enabled = True
End If
labRot.ForeColor = vbBlack
labGelb.ForeColor = vbBlack
labGrün.ForeColor = vbBlack
End Sub
Private Sub comStartAmpelBlink_Click()
If comStartAmpelBlink.Caption = „Start“ Then
comStartAmpelBlink.Caption = „Stopp“
comStartAmpelLicht.Enabled = False
ModusLicht = False
AmpelLichtNummer = 0
Timer1.Enabled = True
Else
Timer1.Enabled = False
comStartAmpelLicht.Enabled = True
comStartAmpelBlink.Caption = „Start“
comStartAmpelBlink.Enabled = True
End If
labRot.ForeColor = vbBlack
labGelb.ForeColor = vbBlack
labGrün.ForeColor = vbBlack
End Sub
Private Sub Timer1_Timer()
AmpelLichtNummer = AmpelLichtNummer + 1
If ModusLicht Then
Select Case AmpelLichtNummer
Case 1 'Rot
labRot.ForeColor = vbRed
labGelb.ForeColor = vbBlack
labGrün.ForeColor = vbBlack
Case 11 'Rot gelb
labGelb.ForeColor = vbYellow
Case 21 'Grün
labGrün.ForeColor = vbGreen
labRot.ForeColor = vbBlack
labGelb.ForeColor = vbBlack
Case 41 'Grün nach Gelb
labGrün.ForeColor = vbBlack
labGelb.ForeColor = vbYellow
Case 51 'zurück nach rot
AmpelLichtNummer = 0
End Select
Else
Select Case AmpelLichtNummer
Case 1 'an
labGelb.ForeColor = vbYellow
Case 6 'aus
labGelb.ForeColor = vbBlack
Case 8 ’ zurück nach an
AmpelLichtNummer = 0
End Select
End If
End Sub
_______________________________________
Ich hoffe das hier ist verständlich.
Lieber Gruß