LB Booster
Programming >> BASIC code examples >> Using modem control outputs to drive a relay
http://lbb.conforums.com/index.cgi?board=code&action=display&num=1513356869

Using modem control outputs to drive a relay
Post by Richard Russell on Dec 15th, 2017, 3:54pm

In response to a query at the LB Yahoo! group, here's a simple program to demonstrate driving the DTR and RTS Modem Control outputs from a standard serial port (internal or USB serial adaptor). On a DB9 connector DTR is on pin 4 and RTS is on pin 7. The code as shown is LBB-specific:

Code:
    ' change COM port number to suit
    open "com3:9600,n,8,1" for random as #com
    hcom = hwnd(#com)
    button #w, " Set DTR ", [setdtr], UL, 20, 20
    button #w, "Clear DTR", [clrdtr], UL, 20, 60
    button #w, " Set RTS ", [setrts], UL, 20, 100
    button #w, "Clear RTS", [clrrts], UL, 20, 140
    open "Modem Control test" for window as #w
    #w "trapclose [quit]"
    wait
    
[setdtr]
    calldll #kernel32, "EscapeCommFunction", hcom as ulong, _SETDTR as long, r as void
    wait

[clrdtr]
    calldll #kernel32, "EscapeCommFunction", hcom as ulong, _CLRDTR as long, r as void
    wait

[setrts]
    calldll #kernel32, "EscapeCommFunction", hcom as ulong, _SETRTS as long, r as void
    wait

[clrrts]
    calldll #kernel32, "EscapeCommFunction", hcom as ulong, _CLRRTS as long, r as void
    wait

[quit]
    close #com
    close #w
    end 

Richard.