Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: X10 x 10
I made a slight rewrite to allow the housecode/unit and function to be entered on the command line, and made the calculation of the unit address code and the function code explicit and capable of addressing all possible units.
Thanks to the original author for figuring out all the command logic to drive the controller!
addextender("wilx34i.dll") AddExtender("wwser34I.dll") pname = "x10ctl" dbg = @YES mypath = intcontrol(1004,0,0,0,0) posn = strindex(mypath,"\",0,@backscan) mypath = strsub(mypath,1,posn) if (dbg) then display ( 3, pname, mypath ) if (dbg) then display ( 3, pname, ".%param1%. .%param2%." ) unitc = -1 funcc = -1 gosub x10parse if ( (unitc<0) || (funcc<0) ) display (3, "%pname% error","P1 = .%param1. P2 = .%param2%.") exit endif port=pComOpen("COM2",0,4800,"8N1","NONNON") pTimeout(port,2000) stop_poll = xbaseconvert("c3",16,10) Header = 4 Send = 6 if (dbg) then display (1,pname,"stop_poll = %stop_poll%") pPutByte(port,stop_poll) ; turn off any interface polling of PC getbyte = -1 while getbyte == -1 pPutByte(port,Header) ;Header -- Address a Unit pPutByte(port,unitc) ;House code / Device Code progress = "%pname% Header & unit code" Gosub WaitForAck ; Wait for Checksum EndWhile pPutByte(port,0) ; Send Ack progress = "%pname% Ack header & unit code" Gosub WaitForAck85 ; Wait for 0x55 getbyte = -1 while getbyte == -1 pPutByte(port,Send) ; Header -- Send Function pPutByte(port,funcc); House Code / Function progress = "%pname% Send function" Gosub WaitForAck ; Wait for Checksum EndWhile pPutByte(port,0) ; Send Ack progress = "%pname% Ack function" Gosub WaitForAck85 ; Wait For 0x55 pComClose(port,0) display(3,pname,"Complete") exit :WaitForAck start=TimeYmdHms( ) Now=TimeYmdHms( ) diff=TimeDiffSecs(Now, start) While diff < 4 getbyte=pGetByte(port) Now=TimeYmdHms( ) diff=TimeDiffSecs(Now, start) If getbyte > -1 then break Endwhile if (dbg) then display(1,progress,getbyte) Return :WaitForAck85 start=TimeYmdHms( ) Now=TimeYmdHms( ) diff=TimeDiffSecs(Now, start) While diff < 4 getbyte=pGetByte(port) Now=TimeYmdHms( ) diff=TimeDiffSecs(Now, start) If getbyte == 85 then break Endwhile if (dbg) then display(1,progress,"Ready") Return :x10parse ; units = arrdimension(16,16) ; devices a-p, units 1-16 ; funcs = arrdimension(16,5) ; devices a-p, alloff, allon, on, off, loff ; units = arrayfilegetcsv("c:\work\x10\units.csv",0) ; funcs = arrayfilegetcsv("c:\work\x10\funcs.csv",0) units = arrdimension(16) funcs = arrdimension(5) units[0] = 110 ; dev a or unit 1 units[1] = 1110 units[2] = 10 units[3] = 1010 units[4] = 1 units[5] = 1001 units[6] = 101 units[7] = 1101 units[8] = 111 units[9] = 1111 units[10] = 11 units[11] = 1011 units[12] = 0 units[13] = 1000 units[14] = 100 units[15] = 1100 ; dev p or unit 16 funcs[0] = 0 ; alloff funcs[1] = 1 ; allon funcs[2] = 10 ; on funcs[3] = 11 ; off funcs[4] = 110 ; loff ; if (dbg) then display (1,pname,"Arrays initialized") if (dbg) then display (1,pname,".%param1%. .%param2%.") unitc = -1 funcc = -1 if ( !isdefined(param1) ) then goto return if ( !isdefined(param2) ) then goto return param1 = strlower(param1) param2 = strlower(param2) device = strsub(param1,1,1) dndx = char2num(device) - char2num("a") if ( ( dndx < 0 ) || ( dndx > 15 ) ) then goto return if (dbg) then display(1,pname,"dndx = %dndx%") if ( isnumber(strsub(param1,2,-1)) ) undx = strsub(param1,2,-1) - 1 else undx = 0 endif if ( ( undx < 0 ) || ( undx > 15 ) ) then goto return if (dbg) then display(1,pname,"undx = %undx%") ; unitc = units[dndx,undx] unitc = (units[dndx]*10000) + units[undx] unitc = xbaseconvert(unitc,2,10) fndx = -1 if ( param2 == "alloff" ) then fndx = 0 if ( param2 == "allon" ) then fndx = 1 if ( param2 == "on" ) then fndx = 2 if ( param2 == "off" ) then fndx = 3 if ( param2 == "loff" ) then fndx = 4 if ( fndx < 0 ) then goto return ; funcc = funcs[dndx,fndx] funcc = (units[dndx]*10000) + funcs[fndx] funcc = xbaseconvert(funcc,2,10) :return if (dbg) then display(1,pname,"Unit = %unitc%, function = %funcc%") return
Article ID: W16361
File Created: 2014:07:18:09:49:36
Last Updated: 2014:07:18:09:49:36