func main() global IP as string global Port as integer global Address as integer global Speed as integer global Handle as integer global DisplayLoconet as integer dim DirF, Snd, F912, F1320, F2128, Active, LastPos, Connected, tem as integer dim Status, i, j, k as integer dim Byte(20) as integer dim Line as string dim Buffer as string dim Token as string dim ByteString as string Address = 3 Handle = 1 DirF = 0 Snd = 0 F912 = 0 F1320 = 0 F2128 = 0 Active = 0 Connected = 0 Token = chr(13)+chr(10) print "Loconet Throttle V0.1" print "(c) Michael Mosher 2007" print " " print "Requires Loconet over TCP server" print " " if FileInfo(".\IP.dat",2) = "True" then IP = FileQuickLoad(".\IP.dat") print "load IP " + IP else IP = "127.0.0.1" print "defualt IP " + IP endif if FileInfo(".\Port.dat",2) = "True" then Port = FileQuickLoad(".\Port.dat") print "load Port " + Port else Port = 1234 print "defualt Port " + Port endif Connect_DisplayForm() LoopMain: if FormAllButtons() = 1 then if FormButton(Button_Quit,0) > 0 then '------ Quit Handler ----- if Active = 1 then Speed = 0 DirF = $20 Snd = 0 F1320 = 0 F2128 = 0 Active = 0 if Active = 1 then SendSpeed() SendDirF(DirF) SendSnd(Snd) SendF912(F912) SendF1320(F1320) SendF2128(F2128) Release() endif endif End endif if Connected = 0 then if FormButton(Button_Save,0) > 0 then '------ Save Handler ----- IP = FormTextBox(Text_IP) Port = FormTextBox(Text_Port) FileQuickSave(".\IP.dat", IP) FileQuickSave(".\Port.dat", Port) endif if FormButton(Button_Connect,0) > 0 then '------ Connect Handler ----- IP = FormTextBox(Text_IP) Port = FormTextBox(Text_Port) if ConnectTCP() = 0 then Main_DisplayForm() Connected = 1 endif endif else for i = 0 to 4 if FormButton(Button_F1+i,0) > 0 then '------ F0-F4 Handler ----- if BitGet(DirF,i) = 0 then BitSet(DirF, i, 1) else BitSet(DirF, i, 0) endif SendDirF(DirF) DisplayDirF(DirF) endif next for i = 0 to 3 if FormButton(Button_F5+i,0) > 0 then '------ F5-9 Handler ----- if BitGet(Snd,i) = 0 then BitSet(Snd, i, 1) else BitSet(Snd, i, 0) endif SendSnd(Snd) DisplaySnd(Snd) endif if FormButton(Button_F9+i,0) > 0 then '------ F9-12 Handler ----- if BitGet(F912,i) = 0 then BitSet(F912, i, 1) else BitSet(F912, i, 0) endif SendF912(F912) DisplayF912(F912) endif next for i = 0 to 7 if FormButton(Button_F13+i,0) > 0 then '------ F13-20 Handler ----- if BitGet(F1320,i) = 0 then BitSet(F1320, i, 1) else BitSet(F1320, i, 0) endif SendF1320(F1320) DisplayF1320(F1320) endif if FormButton(Button_F21+i,0) > 0 then '------ F21-28 Handler ----- if BitGet(F2128,i) = 0 then BitSet(F2128, i, 1) else BitSet(F2128, i, 0) endif SendF2128(F2128) DisplayF2128(F2128) endif next if FormButton(Button_Forward,0) > 0 then '------ Forward Handler ----- BitSet(DirF, 5, 0) FormLabel(Label_Dir,-1,-1,-1,-1,"Fwd") Speed = 0 gosub SpeedLine SendSpeed() SendDirF(DirF) endif if FormButton(Button_Reverse,0) > 0 then '------ Reverse Handler ----- BitSet(DirF, 5, 1) FormLabel(Label_Dir,-1,-1,-1,-1,"Rev") Speed = 0 gosub SpeedLine SendSpeed() SendDirF(DirF) endif if FormButton(Button_Up,0) > 0 then '------ Up Handler ----- Speed = Speed + 1 if Speed > 127 then Speed = 127 if Speed = 1 then Speed = 2 gosub SpeedLine SendSpeed() endif if FormButton(Button_Down,0) > 0 then '------ Down Handler ----- Speed = Speed - 1 if Speed < 0 then Speed = 0 if Speed = 1 then Speed = 0 gosub SpeedLine SendSpeed() endif if FormButton(Button_FastUp,0) > 0 then '------ Fast Up Handler ----- Speed = Speed + 10 if Speed > 127 then Speed = 127 if Speed = 1 then Speed = 2 gosub SpeedLine SendSpeed() endif if FormButton(Button_FastDown,0) > 0 then '------ Fast Down Handler ----- Speed = Speed - 10 if Speed < 0 then Speed = 0 if Speed = 1 then Speed = 0 gosub SpeedLine SendSpeed() endif if FormButton(Button_Stop,0) > 0 then '------ Stop Handler ----- Speed = 0 gosub SpeedLine SendSpeed() endif if FormButton(Button_Select,0) > 0 then '------ Select Handler ----- Address = FormTextBox(Text_Address) if Address > 10239 then Address = InputBox("Address must be between 0 and 10239","Address Error",3) if Address > 10239 then Address = 3 endif Speed = 0 DirF = 0 Snd = 0 F912 = 0 F1320 = 0 F2128 = 0 gosub SpeedLine if Acuire() = 0 then Active = 1 FormButton(Button_FastUp,-1,-1,-1,-11,"Fast Up") FormButton(Button_FastDown,-1,-1,-1,-11,"Fast Down") FormButton(Button_Up,-1,-1,-1,-11,"Up") FormButton(Button_Down,-1,-1,-1,-11,"Down") FormButton(Button_Stop,-1,-1,-1,-11,"Stop") FormButton(Button_Reverse,-1,-1,-1,-11,"Reverse") FormButton(Button_Forward,-1,-1,-1,-11,"Forward") FormButton(Button_Select,-1,-1,-1,-10,"Select") FormButton(Button_Release,-1,-1,-1,-11,"Release") FormButton(Button_F0,-1,-1,-1,-11,"F0") FormButton(Button_F1,-1,-1,-1,-11,"F1") FormButton(Button_F2,-1,-1,-1,-11,"F2") FormButton(Button_F3,-1,-1,-1,-11,"F3") FormButton(Button_F4,-1,-1,-1,-11,"F4") FormButton(Button_F5,-1,-1,-1,-11,"F5") FormButton(Button_F6,-1,-1,-1,-11,"F6") FormButton(Button_F7,-1,-1,-1,-11,"F7") FormButton(Button_F8,-1,-1,-1,-11,"F8") FormButton(Button_F9,-1,-1,-1,-11,"F9") FormButton(Button_F10,-1,-1,-1,-11,"F10") FormButton(Button_F11,-1,-1,-1,-11,"F11") FormButton(Button_F12,-1,-1,-1,-11,"F12") FormButton(Button_F13,-1,-1,-1,-11,"F13") FormButton(Button_F14,-1,-1,-1,-11,"F14") FormButton(Button_F15,-1,-1,-1,-11,"F15") FormButton(Button_F16,-1,-1,-1,-11,"F16") FormButton(Button_F17,-1,-1,-1,-11,"F17") FormButton(Button_F18,-1,-1,-1,-11,"F18") FormButton(Button_F19,-1,-1,-1,-11,"F19") FormButton(Button_F20,-1,-1,-1,-11,"F20") FormButton(Button_F21,-1,-1,-1,-11,"F21") FormButton(Button_F22,-1,-1,-1,-11,"F22") FormButton(Button_F23,-1,-1,-1,-11,"F23") FormButton(Button_F24,-1,-1,-1,-11,"F24") FormButton(Button_F25,-1,-1,-1,-11,"F25") FormButton(Button_F26,-1,-1,-1,-11,"F26") FormButton(Button_F27,-1,-1,-1,-11,"F27") FormButton(Button_F28,-1,-1,-1,-11,"F28") FormTextBox(Text_Address,-1,-1,-1,-10,Address) DisplayDirF(DirF) DisplaySnd(Snd) DisplayF912(F912) DisplayF1320(F1320) DisplayF2128(F2128) endif endif if FormButton(Button_Release,0) > 0 then '------ Release Handler ----- Speed = 0 DirF = 0 Snd = 0 F912 = 0 F1320 = 0 F2128 = 0 Active = 0 gosub SpeedLine SendSpeed() SendDirF(DirF) SendSnd(Snd) SendF912(F912) SendF1320(F1320) SendF2128(F2128) FormButton(Button_FastUp,-1,-1,-1,-10,"Fast Up") FormButton(Button_FastDown,-1,-1,-1,-10,"Fast Down") FormButton(Button_Up,-1,-1,-1,-10,"Up") FormButton(Button_Down,-1,-1,-1,-10,"Down") FormButton(Button_Stop,-1,-1,-1,-10,"Stop") FormButton(Button_Reverse,-1,-1,-1,-10,"Reverse") FormButton(Button_Forward,-1,-1,-1,-10,"Forward") FormButton(Button_Select,-1,-1,-1,-11,"Select") FormButton(Button_Release,-1,-1,-1,-10,"Release") FormButton(Button_F0,-1,-1,-1,-10,"F0") FormButton(Button_F1,-1,-1,-1,-10,"F1") FormButton(Button_F2,-1,-1,-1,-10,"F2") FormButton(Button_F3,-1,-1,-1,-10,"F3") FormButton(Button_F4,-1,-1,-1,-10,"F4") FormButton(Button_F5,-1,-1,-1,-10,"F5") FormButton(Button_F6,-1,-1,-1,-10,"F6") FormButton(Button_F7,-1,-1,-1,-10,"F7") FormButton(Button_F8,-1,-1,-1,-10,"F8") FormButton(Button_F9,-1,-1,-1,-10,"F9") FormButton(Button_F10,-1,-1,-1,-10,"F10") FormButton(Button_F11,-1,-1,-1,-10,"F11") FormButton(Button_F12,-1,-1,-1,-10,"F12") FormButton(Button_F13,-1,-1,-1,-10,"F13") FormButton(Button_F14,-1,-1,-1,-10,"F14") FormButton(Button_F15,-1,-1,-1,-10,"F15") FormButton(Button_F16,-1,-1,-1,-10,"F16") FormButton(Button_F17,-1,-1,-1,-10,"F17") FormButton(Button_F18,-1,-1,-1,-10,"F18") FormButton(Button_F19,-1,-1,-1,-10,"F19") FormButton(Button_F20,-1,-1,-1,-10,"F20") FormButton(Button_F21,-1,-1,-1,-10,"F21") FormButton(Button_F22,-1,-1,-1,-10,"F22") FormButton(Button_F23,-1,-1,-1,-10,"F23") FormButton(Button_F24,-1,-1,-1,-10,"F24") FormButton(Button_F25,-1,-1,-1,-10,"F25") FormButton(Button_F26,-1,-1,-1,-10,"F26") FormButton(Button_F27,-1,-1,-1,-10,"F27") FormButton(Button_F28,-1,-1,-1,-10,"F28") FormTextBox(Text_Address,-1,-1,-1,-11,Address) DisplayDirF(DirF) DisplaySnd(Snd) DisplayF912(F912) DisplayF1320(F1320) DisplayF2128(F2128) Release() endif if FormButton(Button_DisplayLoconet,0) > 0 then '------ Display loconet Handler ----- if DisplayLoconet = 1 then DisplayLoconet = 0 FormBrush(128,128,0) Console(4) else DisplayLoconet = 1 FormBrush(255,255,0) Console(5) endif FormFillRectangle(111,246,5,18) ' display Loconet indicator endif endif endif if Active > 0 then if FormMouseDown() > 0 then if FormMouseX() < 11 then if FormMouseY() < 128 then Speed = 127 - FormMouseY() if Speed = 1 then Speed = 0 gosub SpeedLine SendSpeed() endif endif endif if Timer(1) > 60000 then ' heartbeat SendSpeed() endif if SocketBuff(1) > 0 then Buffer = SocketInput(1) k = 0 CheckLoop2: Line = GetWord(Buffer, 1, k+1, Token, Status) if Status <> -1 then if BeginsWith(Line, "RECEIVE") = 1 then i = 0 CheckLoop3: ByteString = GetWord(Line, 8, i+1, " ", Status) if Status <> -1 then Byte(i) = HexToDec(ByteString) i = i + 1 goto CheckLoop3 endif if Byte(1) = Handle then if Byte(0) = $A0 then Speed = Byte(2) gosub SpeedLine endif if Byte(0) = $A1 then DirF = Byte(2) DisplayDirF(DirF) endif if Byte(0) = $A2 then Snd = Byte(2) DisplaySnd(Snd) endif endif endif 'RECEIVE k = k + 1 goto CheckLoop2 endif 'Get word endif 'socket data endif 'active Goto LoopMain SpeedLine: FormPen(0,0,255) FormLine(0,LastPos, 14, LastPos) FormPen(255,0,0) FormLine(0,(127-Speed), 14, (127-Speed)) FormLabel(Label_Speed,-1,-1,-1,-1,Speed) LastPos = (127-Speed) return endfunc '------------------------------------------------------------------------------- func DisplayDirF(F as integer) dim i as integer if BitGet(F,4) = 1 then FormBrush(255,255,0) else FormBrush(128,128,0) endif FormFillRectangle(234,6,5,18) for i = 0 to 3 if BitGet(F,i) = 1 then FormBrush(255,255,0) else FormBrush(128,128,0) endif FormFillRectangle(234,26+(i*20),5,18) next endfunc '------------------------------------------------------------------------------- func DisplaySnd(F as integer) dim i as integer for i = 0 to 3 if BitGet(F,i) = 1 then FormBrush(255,255,0) else FormBrush(128,128,0) endif FormFillRectangle(234,106+(i*20),5,18) next endfunc '------------------------------------------------------------------------------- func DisplayF912(F as integer) dim i as integer print "F9-12= " + F for i = 0 to 3 if BitGet(F,i) = 1 then FormBrush(255,255,0) else FormBrush(128,128,0) endif FormFillRectangle(234,186+(i*20),5,18) next endfunc '------------------------------------------------------------------------------- func DisplayF1320(F as integer) dim i as integer for i = 0 to 7 if BitGet(F,i) = 1 then FormBrush(255,255,0) else FormBrush(128,128,0) endif FormFillRectangle(194,106+(i*20),5,18) next endfunc '------------------------------------------------------------------------------- func DisplayF2128(F as integer) dim i as integer for i = 0 to 7 if BitGet(F,i) = 1 then FormBrush(255,255,0) else FormBrush(128,128,0) endif FormFillRectangle(154,106+(i*20),5,18) next endfunc '------------------------------------------------------------------------------- func Acuire() as integer dim B(4) as integer dim i, j, k, Status as integer dim Byte(20) as integer dim Output as string dim Line as string dim Buffer as string dim Token as string dim ByteString as string Token = chr(13)+chr(10) B(0) = 191 B(1) = Address \ 128 B(2) = Address & $7F B(3) = 0 FOR j = 0 TO 2 B(3) = B(3) ^ B(j) NEXT B(3) = B(3) ^ 255 if SocketBuff(1) > 0 then Buffer = SocketInput(1) endif Output = "SEND " + Convert(B(0),"X")+" "+Convert(B(1),"X")+" "+Convert(B(2),"X")+" "+Convert(B(3),"X")+chr(13)+chr(10) SocketOutput(1,Output) if DisplayLoconet = 1 then print Mid(Output,6,Len(Output)-7) TimerClear(1) TimerClear(2) AcuireLoop: if SocketBuff(1) > 0 then Buffer = SocketInput(1) 'Print "B=<" + Buffer + ">" k = 0 AcuireLoop2: Line = GetWord(Buffer, 1, k+1, Token, Status) ' Print "L=<" + Line + ">" if Status <> -1 then if BeginsWith(Line, "RECEIVE") = 1 then i = 0 AcuireLoop3: ByteString = GetWord(Line, 8, i+1, " ", Status) if Status <> -1 then Byte(i) = HexToDec(ByteString) i = i + 1 goto AcuireLoop3 endif if Byte(0) = $E7 then if Byte(4) = B(2) then if Byte(9) = B(1) then if (Byte(3) & $30) <> $ $30 then Handle = Byte(2) B(0) = $BA B(1) = Handle B(2) = Handle B(3) = 0 FOR j = 0 TO 2 B(3) = B(3) ^ B(j) NEXT B(3) = B(3) ^ 255 Output = "SEND " + Convert(B(0),"X")+" "+Convert(B(1),"X")+" "+Convert(B(2),"X")+" "+Convert(B(3),"X")+chr(13)+chr(10) SocketOutput(1,Output) if DisplayLoconet = 1 then print Mid(Output,6,Len(Output)-7) TimerClear(1) exit() else MsgBox("Address in use", 0, "Can't Connect") exit(1) endif '$30 endif 'B(1) endif 'B(2) endif '$E7 endif 'RECEIVE k = k + 1 goto AcuireLoop2 endif 'Get word endif 'socket data if Timer(2) < 10000 then goto AcuireLoop else MsgBox("No Slot recieved", 0, "Can't Connect") exit(2) endif endfunc '------------------------------------------------------------------------------- func Release() dim B(4) as integer dim i, j, k, Status as integer dim Byte(20) as integer dim Output as string dim Line as string dim Buffer as string dim Token as string dim ByteString as string Token = chr(13)+chr(10) B(0) = $BB B(1) = Handle B(2) = 0 B(3) = 0 FOR j = 0 TO 2 B(3) = B(3) ^ B(j) NEXT B(3) = B(3) ^ 255 if SocketBuff(1) > 0 then Buffer = SocketInput(1) endif Output = "SEND " + Convert(B(0),"X")+" "+Convert(B(1),"X")+" "+Convert(B(2),"X")+" "+Convert(B(3),"X")+chr(13)+chr(10) SocketOutput(1,Output) if DisplayLoconet = 1 then print Mid(Output,6,Len(Output)-7) TimerClear(1) TimerClear(2) AcuireLoop: if SocketBuff(1) > 0 then Buffer = SocketInput(1) k = 0 AcuireLoop2: Line = GetWord(Buffer, 1, k+1, Token, Status) if Status <> -1 then if BeginsWith(Line, "RECEIVE") = 1 then i = 0 AcuireLoop3: ByteString = GetWord(Line, 8, i+1, " ", Status) if Status <> -1 then Byte(i) = HexToDec(ByteString) i = i + 1 goto AcuireLoop3 endif if Byte(0) = $E7 then if Byte(2) = handle then B(0) = $B5 B(1) = Handle B(2) = $10 + (Byte(3) & $07) B(3) = 0 FOR i = 0 TO 2 B(3) = B(3) ^ B(i) NEXT B(3) = B(3) ^ 255 Output = "SEND " + Convert(B(0),"X")+" "+Convert(B(1),"X")+" "+Convert(B(2),"X")+" "+Convert(B(3),"X")+chr(13)+chr(10) SocketOutput(1,Output) if DisplayLoconet = 1 then print Mid(Output,6,Len(Output)-7) exit() endif 'Byte(2) endif '$E7 endif 'RECEIVE k = k + 1 goto AcuireLoop2 endif 'Get word endif 'socket data if Timer(2) < 10000 then goto AcuireLoop endif endfunc '------------------------------------------------------------------------------- func ConnectTCP() as integer dim stat, Cnt as integer Cnt = 0 SocketConnect(1,IP,Port) WaitLoop: Cnt = Cnt + 1 if SocketState(1) = 4 then print "Connected" exit(0) else print SocketData(1,6) print " / "+SocketData(1,5) if Cnt > 30 then MsgBox("Can't Connect", 0) exit(1) endif endif pause(100) Goto WaitLoop endfunc '------------------------------------------------------------------------------- func SendSpeed() dim B(4) as integer dim i integer dim Output as string B(0) = $A0 B(1) = Handle B(2) = Speed B(3) = 0 FOR i = 0 TO 2 B(3) = B(3) ^ B(i) NEXT B(3) = B(3) ^ 255 Output = "SEND " + Convert(B(0),"X")+" "+Convert(B(1),"X")+" "+Convert(B(2),"X")+" "+Convert(B(3),"X")+chr(13)+chr(10) SocketOutput(1,Output) if DisplayLoconet = 1 then print Mid(Output,6,Len(Output)-7) TimerClear(1) endfunc '------------------------------------------------------------------------------- func SendDirF(DirF as integer) dim B(4) as integer dim i integer dim Output as string B(0) = $A1 B(1) = Handle B(2) = DirF B(3) = 0 FOR i = 0 TO 2 B(3) = B(3) ^ B(i) NEXT B(3) = B(3) ^ 255 Output = "SEND " + Convert(B(0),"X")+" "+Convert(B(1),"X")+" "+Convert(B(2),"X")+" "+Convert(B(3),"X")+chr(13)+chr(10) SocketOutput(1,Output) if DisplayLoconet = 1 then print Mid(Output,6,Len(Output)-7) TimerClear(1) endfunc '------------------------------------------------------------------------------- func SendSnd(Snd as integer) dim B(4) as integer dim i integer dim Output as string B(0) = $A2 B(1) = Handle B(2) = Snd B(3) = 0 FOR i = 0 TO 2 B(3) = B(3) ^ B(i) NEXT B(3) = B(3) ^ 255 Output = "SEND " + Convert(B(0),"X")+" "+Convert(B(1),"X")+" "+Convert(B(2),"X")+" "+Convert(B(3),"X")+chr(13)+chr(10) SocketOutput(1,Output) if DisplayLoconet = 1 then print Mid(Output,6,Len(Output)-7) TimerClear(1) endfunc '------------------------------------------------------------------------------- func SendF912(Fn as integer) dim B(11) as integer dim i integer dim Output as string if Address < 1 then exit() if Address > 10239 then exit() B(0) = $ED B(1) = $0B B(2) = $7F if Address < 128 then B(3) = $24 'REPS B(4) = $02 'DHI B(5) = Address 'IM1 B(6) = $20 | (Fn & $0f) 'IM2 B(7) = 0 'IM3 else B(3) = $34 'REPS B(4) = $04 'DHI if ((Address \ 256) + 192) & $80) > 0 then B(4) = BitSet(B(4),0,1) if ((Address // 256) & $80) > 0 then B(4) = BitSet(B(4),1,1) B(5) = ((Address \ 256) + 192) & $7F 'IM1 B(6) = (Address // 256) & $7f 'IM2 B(7) = $20 | (Fn & $0f) 'IM3 endif B(8) = $0 'IM4 B(9) = $0 'IM5 FOR i = 0 TO 9 B(10) = B(10) ^ B(i) NEXT B(10) = B(10) ^ 255 Output = "SEND " + Convert(B(0),"X")+" "+Convert(B(1),"X")+" "+Convert(B(2),"X")+" "+Convert(B(3),"X")+" "+Convert(B(4),"X")+" "+Convert(B(5),"X")+" "+Convert(B(6),"X")+" "+Convert(B(7),"X")+" "+Convert(B(8),"X")+" "+Convert(B(9),"X")+" "+Convert(B(10),"X")+chr(13)+chr(10) SocketOutput(1,Output) if DisplayLoconet = 1 then print Mid(Output,6,Len(Output)-7) TimerClear(1) endfunc '------------------------------------------------------------------------------- func SendF1320(Fn as integer) dim B(11) as integer dim i integer dim Output as string if Address < 1 then exit() if Address > 10239 then exit() B(0) = $ED B(1) = $0B B(2) = $7F if Address < 128 then B(3) = $34 'REPS B(4) = $02 'DHI if (Fn & $80) > 0 then B(4) = BitSet(B(4),2,1) B(5) = Address 'IM1 B(6) = $5E 'IM2 B(7) = Fn & $0f 'IM3 B(8) = 0 'IM4 else B(3) = $44 'REPS B(4) = $04 'DHI if ((Address \ 256) + 192) & $80) > 0 then B(4) = BitSet(B(4),0,1) if ((Address // 256) & $80) > 0 then B(4) = BitSet(B(4),1,1) if (Fn & $80) > 0 then B(4) = BitSet(B(4),3,1) B(5) = ((Address \ 256) + 192) & $7F 'IM1 B(6) = (Address // 256) & $7f 'IM2 B(7) = $5E 'IM3 B(8) = Fn & $7f 'IM4 endif B(9) = $0 'IM5 FOR i = 0 TO 9 B(10) = B(10) ^ B(i) NEXT B(10) = B(10) ^ 255 Output = "SEND " + Convert(B(0),"X")+" "+Convert(B(1),"X")+" "+Convert(B(2),"X")+" "+Convert(B(3),"X")+" "+Convert(B(4),"X")+" "+Convert(B(5),"X")+" "+Convert(B(6),"X")+" "+Convert(B(7),"X")+" "+Convert(B(8),"X")+" "+Convert(B(9),"X")+" "+Convert(B(10),"X")+chr(13)+chr(10) SocketOutput(1,Output) if DisplayLoconet = 1 then print Mid(Output,6,Len(Output)-7) TimerClear(1) endfunc '------------------------------------------------------------------------------- func SendF2128(Fn as integer) dim B(11) as integer dim i integer dim Output as string if Address < 1 then exit() if Address > 10239 then exit() B(0) = $ED B(1) = $0B B(2) = $7F if Address < 128 then B(3) = $34 'REPS B(4) = $06 'DHI if (Fn & $80) > 0 then B(4) = BitSet(B(4),2,1) B(5) = Address 'IM1 B(6) = $5F 'IM2 B(7) = Fn & $0f 'IM3 B(8) = 0 'IM4 else B(3) = $44 'REPS B(4) = $06 'DHI if ((Address \ 256) + 192) & $80) > 0 then B(4) = BitSet(B(4),0,1) if ((Address // 256) & $80) > 0 then B(4) = BitSet(B(4),1,1) if (Fn & $80) > 0 then B(4) = BitSet(B(4),3,1) B(5) = ((Address \ 256) + 192) & $7F 'IM1 B(6) = (Address // 256) & $7f 'IM2 B(7) = $5F 'IM3 B(8) = Fn & $7f 'IM4 endif B(9) = $0 'IM5 FOR i = 0 TO 9 B(10) = B(10) ^ B(i) NEXT B(10) = B(10) ^ 255 Output = "SEND " + Convert(B(0),"X")+" "+Convert(B(1),"X")+" "+Convert(B(2),"X")+" "+Convert(B(3),"X")+" "+Convert(B(4),"X")+" "+Convert(B(5),"X")+" "+Convert(B(6),"X")+" "+Convert(B(7),"X")+" "+Convert(B(8),"X")+" "+Convert(B(9),"X")+" "+Convert(B(10),"X")+chr(13)+chr(10) SocketOutput(1,Output) if DisplayLoconet = 1 then print Mid(Output,6,Len(Output)-7) TimerClear(1) endfunc '------------------------------------------------------------------------------- func HexToDec(Hex as string) as integer dim LeftChar as string dim RightChar as string LeftChar = Left(Hex, 1) RightChar = Right(Hex, 1) exit(DecDigit(LeftChar) * 16 + DecDigit(RightChar)) endfunc '------------------------------------------------------------------------------- func DecDigit(Digit as string) as integer StrIf Digit = "0" then exit (0) StrIf Digit = "1" then exit (1) StrIf Digit = "2" then exit (2) StrIf Digit = "3" then exit (3) StrIf Digit = "4" then exit (4) StrIf Digit = "5" then exit (5) StrIf Digit = "6" then exit (6) StrIf Digit = "7" then exit (7) StrIf Digit = "8" then exit (8) StrIf Digit = "9" then exit (9) StrIf Digit = "A" then exit (10) StrIf Digit = "B" then exit (11) StrIf Digit = "C" then exit (12) StrIf Digit = "D" then exit (13) StrIf Digit = "E" then exit (14) StrIf Digit = "F" then exit (15) endfunc '------------------------------------------------------------------------------- func Main_DisplayForm() FormRes(240,268) FormNew() FormBGColor(228,228,228) FormCLS() FormTextColor(0,0,0) FormFont("-",10,1) FormSettings(AlignCenter) FormLabel(Label_Heading,25,0,175,20,"Loconet Throttle") FormFont("-",9,0) FormLabel(Label_Address, 85, 20,75,15,"Address:") FormLabel(Label_Speed2, 85, 55,75,15,"Speed:") FormLabel(Label_Speed, 85, 70,75,15,Speed) FormLabel(Label_Dir, 85, 85,75,15,"Fwd") FormBGColor(255,255,255) FormTextBox(Text_Address, 85, 35,75,20,Address) FormSettings(Alignleft) FormBGColor(211,211,211) FormFont("-",9,1) FormButton(Button_Quit, 0,245,60,20,"Quit") FormButton(Button_DisplayLoconet,70,245,40,20,"Ln") FormButton(Button_FastUp, 20, 20,60,20,"Fast") FormButton(Button_Up, 20, 40,60,20,"Up") FormButton(Button_Down, 20, 65,60,20,"Down") FormButton(Button_FastDown, 20, 85,60,20,"Fast") FormButton(Button_Stop, 20,110,60,20,"Stop") FormButton(Button_Forward, 10,135,70,20,"Forward") FormButton(Button_Reverse, 10,155,70,20,"Reverse") FormButton(Button_Select, 10,180,70,20,"Select") FormButton(Button_Release, 10,200,70,20,"Release") FormButton(Button_F0, 200, 5,33,20,"F0") FormButton(Button_F1, 200, 25,33,20,"F1") FormButton(Button_F2, 200, 45,33,20,"F2") FormButton(Button_F3, 200, 65,33,20,"F3") FormButton(Button_F4, 200, 85,33,20,"F4") FormButton(Button_F5, 200,105,33,20,"F5") FormButton(Button_F6, 200,125,33,20,"F6") FormButton(Button_F7, 200,145,33,20,"F7") FormButton(Button_F8, 200,165,33,20,"F8") FormButton(Button_F9, 200,185,33,20,"F9") FormButton(Button_F10,200,205,33,20,"F10") FormButton(Button_F11,200,225,33,20,"F11") FormButton(Button_F12,200,245,33,20,"F12") FormButton(Button_F13,160,105,33,20,"F13") FormButton(Button_F14,160,125,33,20,"F14") FormButton(Button_F15,160,145,33,20,"F15") FormButton(Button_F16,160,165,33,20,"F16") FormButton(Button_F17,160,185,33,20,"F17") FormButton(Button_F18,160,205,33,20,"F18") FormButton(Button_F19,160,225,33,20,"F19") FormButton(Button_F20,160,245,33,20,"F20") FormButton(Button_F21,120,105,33,20,"F21") FormButton(Button_F22,120,125,33,20,"F22") FormButton(Button_F23,120,145,33,20,"F23") FormButton(Button_F24,120,165,33,20,"F24") FormButton(Button_F25,120,185,33,20,"F25") FormButton(Button_F26,120,205,33,20,"F26") FormButton(Button_F27,120,225,33,20,"F27") FormButton(Button_F28,120,245,33,20,"F28") FormSettings(Alignleft) FormBGColor(228,228,228) FormPen(255,255,255) FormRectangle(233, 5,7,20) FormRectangle(233, 25,7,20) FormRectangle(233, 45,7,20) FormRectangle(233, 65,7,20) FormRectangle(233, 85,7,20) FormRectangle(233,105,7,20) FormRectangle(233,125,7,20) FormRectangle(233,145,7,20) FormRectangle(233,165,7,20) FormRectangle(233,185,7,20) FormRectangle(233,205,7,20) FormRectangle(233,225,7,20) FormRectangle(233,245,7,20) FormRectangle(193,105,7,20) FormRectangle(193,125,7,20) FormRectangle(193,145,7,20) FormRectangle(193,165,7,20) FormRectangle(193,185,7,20) FormRectangle(193,205,7,20) FormRectangle(193,225,7,20) FormRectangle(193,245,7,20) FormRectangle(153,105,7,20) FormRectangle(153,125,7,20) FormRectangle(153,145,7,20) FormRectangle(153,165,7,20) FormRectangle(153,185,7,20) FormRectangle(153,205,7,20) FormRectangle(153,225,7,20) FormRectangle(153,245,7,20) FormRectangle(110,245,7,20) FormBrush(128,128,0) FormFillRectangle(111,246,5,18) ' display Loconet indicator FormBrush(0,0,255) ' speed touch space FormFillRectangle(0,0,15,128) FormButton(Button_FastUp,-1,-1,-1,-10,"Fast Up") FormButton(Button_FastDown,-1,-1,-1,-10,"Fast Down") FormButton(Button_Up,-1,-1,-1,-10,"Up") FormButton(Button_Down,-1,-1,-1,-10,"Down") FormButton(Button_Stop,-1,-1,-1,-10,"Stop") FormButton(Button_Reverse,-1,-1,-1,-10,"Reverse") FormButton(Button_Forward,-1,-1,-1,-10,"Forward") FormButton(Button_Select,-1,-1,-1,-11,"Select") FormButton(Button_Release,-1,-1,-1,-10,"Release") FormButton(Button_F0,-1,-1,-1,-10,"F0") FormButton(Button_F1,-1,-1,-1,-10,"F1") FormButton(Button_F2,-1,-1,-1,-10,"F2") FormButton(Button_F3,-1,-1,-1,-10,"F3") FormButton(Button_F4,-1,-1,-1,-10,"F4") FormButton(Button_F5,-1,-1,-1,-10,"F5") FormButton(Button_F6,-1,-1,-1,-10,"F6") FormButton(Button_F7,-1,-1,-1,-10,"F7") FormButton(Button_F8,-1,-1,-1,-10,"F8") FormButton(Button_F9,-1,-1,-1,-10,"F9") FormButton(Button_F10,-1,-1,-1,-10,"F10") FormButton(Button_F11,-1,-1,-1,-10,"F11") FormButton(Button_F12,-1,-1,-1,-10,"F12") FormButton(Button_F13,-1,-1,-1,-10,"F13") FormButton(Button_F14,-1,-1,-1,-10,"F14") FormButton(Button_F15,-1,-1,-1,-10,"F15") FormButton(Button_F16,-1,-1,-1,-10,"F16") FormButton(Button_F17,-1,-1,-1,-10,"F17") FormButton(Button_F18,-1,-1,-1,-10,"F18") FormButton(Button_F19,-1,-1,-1,-10,"F19") FormButton(Button_F20,-1,-1,-1,-10,"F20") FormButton(Button_F21,-1,-1,-1,-10,"F21") FormButton(Button_F22,-1,-1,-1,-10,"F22") FormButton(Button_F23,-1,-1,-1,-10,"F23") FormButton(Button_F24,-1,-1,-1,-10,"F24") FormButton(Button_F25,-1,-1,-1,-10,"F25") FormButton(Button_F26,-1,-1,-1,-10,"F26") FormButton(Button_F27,-1,-1,-1,-10,"F27") FormButton(Button_F28,-1,-1,-1,-10,"F28") FormTextBox(Text_Address,-1,-1,-1,-11,Address) endfunc '------------------------------------------------------------------------------- func Connect_DisplayForm() Console(1) ' No console for PPC '--- Buttons --- gconst Button_Quit 0 gconst Button_Stop 1 gconst Button_For 2 gconst Button_Rev 3 gconst Button_FastUp 4 gconst Button_Up 5 gconst Button_Down 6 gconst Button_FastDown 7 gconst Button_Forward 8 gconst Button_Reverse 9 gconst Button_Select 10 gconst Button_Release 11 gconst Button_DisplayLoconet 13 gconst Button_F1 14 gconst Button_F2 15 gconst Button_F3 16 gconst Button_F4 17 gconst Button_F0 18 gconst Button_F5 19 gconst Button_F6 20 gconst Button_F7 21 gconst Button_F8 22 gconst Button_F9 23 gconst Button_F10 24 gconst Button_F11 25 gconst Button_F12 26 gconst Button_F13 27 gconst Button_F14 28 gconst Button_F15 29 gconst Button_F16 30 gconst Button_F17 31 gconst Button_F18 32 gconst Button_F19 33 gconst Button_F20 34 gconst Button_F21 35 gconst Button_F22 36 gconst Button_F23 37 gconst Button_F24 38 gconst Button_F25 39 gconst Button_F26 40 gconst Button_F27 41 gconst Button_F28 42 gconst Button_Connect 43 gconst Button_Save 44 '--- Labels --- gconst Label_Heading 0 gconst Label_IP 1 gconst Label_Port 2 gconst Label_F0 3 gconst Label_F1 4 gconst Label_F2 5 gconst Label_F3 6 gconst Label_F4 7 gconst Label_F5 8 gconst Label_F6 9 gconst Label_F7 10 gconst Label_F8 11 gconst Label_F9 12 gconst Label_F10 13 gconst Label_F11 14 gconst Label_F12 15 gconst Label_Speed 16 gconst Label_Speed2 17 gconst Label_Dir 18 gconst Label_F13 19 gconst Label_F14 20 gconst Label_F15 21 gconst Label_F16 22 gconst Label_F17 23 gconst Label_F18 24 gconst Label_F19 25 gconst Label_F21 26 gconst Label_F22 27 gconst Label_F23 28 gconst Label_F24 29 gconst Label_F25 30 gconst Label_F26 31 gconst Label_F27 32 gconst Label_F28 33 gconst Label_Address 34 '--- TextBoxes --- gconst Text_IP 0 gconst Text_Port 1 gconst Text_Address 2 ' FormRes(240,268) FormNew() FormBGColor(228,228,228) FormCLS() FormTextColor(0,0,0) FormFont("-",10,1) FormSettings(AlignCenter) FormLabel(Label_Heading,0,0,240,20,"Loconet over TCP connection") FormFont("-",9,0) FormSettings(AlignRight) FormLabel(Label_IP, 0, 20,60,20,"IP:") FormLabel(Label_Port, 0, 40,60,20,"Port:") FormBGColor(255,255,255) FormSettings(AlignLeft) FormTextBox(Text_IP, 65, 20,100,20,IP) FormTextBox(Text_Port, 65, 40,100,20,Port) FormSettings(Alignleft) FormBGColor(211,211,211) FormFont("-",9,1) FormButton(Button_Quit, 10,100,60,20,"Quit") FormButton(Button_Connect, 80,100,70,20,"Connect") FormButton(Button_Save, 160,100,70,20,"Save") endfunc