Relais sturen met VBA
Hallo,
Ik zou in mijn VBA (acces 2007) programma de sturing van een relaisprint willen opnemen.
Het betreft een 8 kanaals 12V relais module met USB connectie.
Onderstaand informatie omtrent de software.
Ik ben een tijd aan het proberen geweest om het in VBA werkend te krijgen, zonder succes.
Is er iemand die mij met de VBA code zou kunnen en willen helpen.
In mijn VBA relay testprogram heb ik opgenomen :
Hallo,
Ik zou in mijn VBA (acces 2007) programma de sturing van een relaisprint willen opnemen.
Het betreft een 8 kanaals 12V relais module met USB connectie.
Onderstaand informatie omtrent de software.
Ik ben een tijd aan het proberen geweest om het in VBA werkend te krijgen, zonder succes.
Is er iemand die mij met de VBA code zou kunnen en willen helpen.
In mijn VBA relay testprogram heb ik opgenomen :
Code:
Private Sub Test Relay_Click()
''5291D afEd5 usb_relay_device.dll
''1. call usb_relay_init() to init the lib.
''2. call usb_relay_device_enumerate() to get all the device pluged into pc
''3. call usb_relay_device_open() open the device you need
''4. other operation funcation:
''call usb_relay_device_open_one_relay_channel() to open one way relay
''call usb_relay_device_open_all_relay_channel() to open all relays
''call usb_relay_device_close_one_relay_channel()to close one way relay
''call usb_relay_device_close_all_relay_channel()to close all relays
''
Dim serial_number As String
Dim device_path As String
Dim usb_relais_device_type As Byte
Dim usb_relais_device_info As String
serial_number = "5291D"
device_path = Application.CurrentProject.Path
usb_relais_device_type = 8
usb_relais_device_info = "afE5"
''Call usb_relay_device_enumerate(device_path, serial_number, usb_relais_device_type, usb_relais_device_info) ''Gives an Error
''Call usb_relay_device_open(usb_relais_device_info:=afEd5) '' Gives an Error
''Call usb_relay_device_open(serial_number:="5291D", device_path:=Application.CurrentProject.Path, usb_relais_device_type:=8, usb_relais_device_info:=afE5) '' Gives an Error
Call usb_relay_init '' Gives an Error : can not find : usb_relay_device.dll
End Sub
In Module opgenomen :
Option Compare Database
Option Explicit 'In a standard (.BAS) module
Public Enum usb_relay_device_type
USB_RELAY_DEVICE_ONE_CHANNEL = 1
USB_RELAY_DEVICE_TWO_CHANNEL = 2
USB_RELAY_DEVICE_FOUR_CHANNEL = 4
USB_RELAY_DEVICE_EIGHT_CHANNEL = 8
End Enum
Public Type USB_Relay_Device_Info
serial_number As String
device_path As String
usb_relais_device_type As Byte
usb_relais_device_info As String
End Type
Public Declare Function usb_relay_device_close_all_relay_channel Lib "usb_relay_device.dll" (ByVal hHandle As Long) As Long
Public Declare Function usb_relay_device_close_one_relay_channel Lib "usb_relay_device.dll" (ByVal hHandle As Long, ByVal Index As Long) As Long
Public Declare Function usb_relay_device_enumerate Lib "usb_relay_device.dll" () As Long
Public Declare Function usb_relay_device_get_status Lib "usb_relay_device.dll" (ByVal hHandle As Long, ByRef Status As Long) As Long
Public Declare Function usb_relay_device_open Lib "usb_relay_device.dll" (ByRef Device_Info As USB_Relay_Device_Info) As Long
Public Declare Function usb_relay_device_open_all_relay_channel Lib "usb_relay_device.dll" (ByVal hHandle As Long) As Long
Public Declare Function usb_relay_device_open_one_relay_channel Lib "usb_relay_device.dll" (ByVal hHandle As Long, ByVal Index As Long) As Long
Public Declare Function usb_relay_device_open_with_serial_number Lib "usb_relay_device.dll" (ByVal serial_number As String, ByVal Length As Long) As Long
Public Declare Function usb_relay_device_set_serial Lib "usb_relay_device.dll" (ByVal hHandle As Long, ByVal Serial As Any) As Long
Public Declare Function usb_relay_exit Lib "usb_relay_device.dll" () As Long
Public Declare Function usb_relay_init Lib "usb_relay_device.dll" () As Long
Public Declare Sub usb_relay_device_close Lib "usb_relay_device.dll" (ByVal hHandle As Long)
Public Declare Sub usb_relay_device_free_enumerate Lib "usb_relay_device.dll" (ByRef Device_Info As USB_Relay_Device_Info)
Laatst bewerkt door een moderator: