USB Controlled Relay library

Post your working scripts, libraries and tools
x32
Posts: 85
Joined: 25 Nov 2016, 16:44

USB Controlled Relay library

13 Mar 2018, 07:53

A function library for USB Relay boards. See this post for capturing USB input.
https://www.banggood.com/5V-2-Channel-U ... 10097.html
Image

It only has one function, turn the relays on or off. There must be a second function, for finding the board serial number, but there are no instructions for it. A test app in the file downloads can be used to find it.

Requires the following files in the script directory.
1. CommandApp_USBRelay.exe
2. usb_relay_device.dll
3. GuiApp_English.exe ;;;;;; These last two are only for
4. XCGUI.dll ;;;;;; finding the device serial number.

File download links.
Original file, https://www.dropbox.com/sh/7clljb4h1aeb ... 9BoMWY-Cha

Backup on my website, http://www.starshipgrissom.com/ahk/USB_Relay_Control.7z
This one includes copies of the library and a test script.

USBRelay(serial,oc,chan)
"serial" is your device's serial number.
"oc" is open or close. This is opposite of what would be expected, "open" activates the relay and "close" disconnects it.
"chan" is the relay chan, 1, 2, 3, ect. 255 controls all relays on the board.
Example - USBRelay(tk421,open,1)

I've only tested with a two channel board but I imagine it would work with any number of channels.

Code: Select all

;;  USB controled relay board. By X32.
;;  https://www.banggood.com/5V-2-Channel-USB-Relay-Module-Programmable-Computer-Control-p-910097.html

;;  Requires the following files in the script directory.
;;  1. CommandApp_USBRelay.exe
;;  2. usb_relay_device.dll
;;  3. GuiApp_English.exe      ;;;;;;  These last two are only for 
;;  4. XCGUI.dll               ;;;;;;  finding the device serial number.
;;
;;  File download links.
;;  Original file, https://www.dropbox.com/sh/7clljb4h1aeb0m1/AAA-oUOCE2a15PC9BoMWY-Cha
;;
;;  Backup on my website, http://www.starshipgrissom.com/ahk/USB_Relay_Control.7z


;; Usage, 
;; Ther are no instructions to locate the device serial number so you must use the test app for this purpose.
;; Run GuiApp_English.exe, click "Find Device", then find your device serial number in the drop down list.
;;
;; "serial" is your device's serial number.
;; "oc" is open or close.
;; "chan" is the relay chan, 1, 2, 3, ect. 
;; Example - USBRelay(tk421,open,1) 


USBRelay(serial,oc,chan)
	{
	Run, %comspec% /c CommandApp_USBRelay %serial% %oc% %chan%, , Hide
	}
	
	
/*   ;Test Application

; #Include, USBRelay.ahk

Gui, Add, Edit, x5 y5 w100 h25 vsn, xxxxx
Gui, Add, Text, x+5 y5 w100, <== Enter device`n serial number here.
Gui, Add, Button, x5 y55 w100 h25 goneoff, Relay 1 Off 
Gui, Add, Button, x+5 y55 w100 h25 goneon, Relay 1 On
Gui, Add, Button, x5 y105 w100 h25 gtwooff, Relay 2 Off 
Gui, Add, Button, x+5 y105 w100 h25 gtwoon, Relay 2 On 
Gui, Add, Button, x5 y155 w100 h25 galloff, All Relays Off 
Gui, Add, Button, x+5 y155 w100 h25 gallon, All Relays On 

Gui, Show, w215 h200 , USB Relay Control 
Return 

oneoff:
Gui, Submit, NoHide
serial = %sn%
oc = close
chan = 1
USBRelay(serial,oc,chan)
Return

oneon:
Gui, Submit, NoHide
serial = %sn%
oc = open
chan = 1
USBRelay(serial,oc,chan)
Return

twooff:
Gui, Submit, NoHide
serial = %sn%
oc = close
chan = 2
USBRelay(serial,oc,chan)
Return

twoon:
Gui, Submit, NoHide
serial = %sn%
oc = open
chan = 2
USBRelay(serial,oc,chan)
Return

alloff:
Gui, Submit, NoHide
serial = %sn%
oc = close
chan = 255
USBRelay(serial,oc,chan)
Return

allon:
Gui, Submit, NoHide
serial = %sn%
oc = open
chan = 255
USBRelay(serial,oc,chan)
Return


Exit:
GuiEscape:
GuiClose:
Gui, Destroy
ExitApp
*/
	
	
	

Return to “Scripts and Functions”

Who is online

Users browsing this forum: EvetsNalon and 19 guests