' "LOGICData Table Controller"
PrgVersion$ = "0-0-1-1"
ComPort = 0
TableHeight = 0
TableHeight$ = ""
LOGICData$ = "" ' LOGICData protocol
ComOpen = 0 ' keeps track of opened Com Port
CS = 0 ' CheckSum
CR$ = CHR$(13) ' "Carriage Return"
LFCR$ = CHR$(10)+CHR$(13) ' "Line Feed & Carriage Return"
NOMAINWIN
ONCOMERROR [ComErrorHandler]
[MAIN]
WindowWidth = 213
WindowHeight = 300
UpperLeftX = INT((DisplayWidth-WindowWidth)/2)
UpperLeftY = INT((DisplayHeight-WindowHeight)/2)
' MENU #Main, "&File", "E&xit",[QUIT]
' MENU #Main, "&?","&About...",[ABOUT]
' " Table Height "
GROUPBOX #Main.GBx10," Table Height ", 10, 10,185,115
TEXTBOX #Main.TBx10, 30, 30, 30, 20
STATICTEXT #Main.STx10,"(0..255)", 65, 33, 80, 20
STATICTEXT #Main.STx11,"Message sent: "+LOGICData$, 30, 95,160, 20
BUTTON #Main.Btn10,"Set", [SendHeight], UL, 30, 60, 60, 22
BUTTON #Main.Btn11,"Top", [SendTableTop], UL,115, 30, 60, 22
BUTTON #Main.Btn12,"Bottom",[SendTableBottom],UL,115, 60, 60, 22
' " Com Port "
GROUPBOX #Main.GBx20," Com Port ", 10,150,185, 55
TEXTBOX #Main.TBx21, 30,170, 20, 20
STATICTEXT #Main.STx21,"=", 52,173, 10, 20
GRAPHICBOX #Main.GFx21, 62,173, 15, 15
'STYLEBITS #Main.GFx21,0,_WS_BORDER,0,0 'remove image's border
BUTTON #Main.Btn23,"Ok",[ComOpenPort],UL, 115,170, 60, 22
' " EXIT & About "
BUTTON #Main.Btn30,"&Exit",[QUIT],UL, 115,230, 60, 22
BUTTON #Main.Btn31,"About",[ABOUT],UL, 30,230, 60, 22
OPEN "LOGICData" FOR window AS #Main
#Main "TRAPCLOSE [QUIT]"
#Main.GFx21, "down; fill red; flush"
IF ComPort <> 0 THEN [ComOpenPort]
IF ComPort = 0 THEN #Main.TBx21, "!setfocus"
WAIT
[ComOpenPort]
IF ComOpen = 0 THEN
ComOpen = 1
#Main.TBx21, "!contents? ComPort" ' get the com port #
#Main.TBx10, "!setfocus"
OPEN "com";ComPort;":115200,n,8,1" FOR random AS #ComHandle 'LBB syntax
#Main.TBx21, STR$(ComPort)
#Main.GFx21, "down; fill green; flush"
END IF
WAIT
[ComErrorHandler]
NOTICE "Serial port error" + CR$ + "Com Port " + STR$(ComPort) + " not found"
#Main.GFx21, "down; fill red; flush"
#Main.TBx21, ""
#Main.TBx21, "!setfocus"
CLOSE #ComHandle
ComOpen = 0
WAIT
[SendTableTop]
IF ComOpen = 1 THEN ' do it ONLY if com port is open
'TableHeight = 255/0xFF
#Main.GBx10," Table Height = 255 "
#Main.TBx10, ""
#Main.STx11,"Message sent: 94 10 00 FF 7B"
#ComHandle "94 10 00 FF 7B" + LFCR$ ' Tisch auf Höhe 255
END IF
WAIT
[SendTableBottom]
IF ComOpen = 1 THEN ' do it ONLY if com port is open
'TableHeight = 0/0x00
#Main.GBx10," Table Height = 0 "
#Main.TBx10, ""
#Main.STx11,"Message sent: 94 10 00 00 84"
#ComHandle "94 10 00 00 84" + LFCR$ ' Tisch auf Höhe 0
END IF
WAIT
[SendHeight] 'If height 20(Ox14 or &H14) = "94 10 00 14 90"
IF ComOpen = 1 THEN ' do it ONLY if com port is open
#Main.TBx10, "!contents? TableHeight$" ' use string to see if empty
IF TableHeight$ = "" THEN [DONOTHING] ' trap a case where the input is empty
TableHeight = VAL(TableHeight$) ' since not empty, convert to value and go on
IF TableHeight < 256 THEN ' do it only if value is 0..255
#Main.GBx10," Table Height = " + STR$(TableHeight)+ " "
#Main.TBx10, ""
CS = &H94 XOR &H10 XOR &H00 XOR TableHeight ' CheckSum calculation
IF TableHeight < 10 THEN ' adjust i.e "5" to "05"
LOGICData$ = "94 10 00 0" + DECHEX$(TableHeight) + " " + DECHEX$(CS)
ELSE
LOGICData$ = "94 10 00 " + DECHEX$(TableHeight) + " " + DECHEX$(CS)
END IF
#Main.STx11,"Message sent: "+LOGICData$
#ComHandle, LOGICData$ + LFCR$
ELSE
[DONOTHING]
TableHeight = 0
#Main.GBx10," Table Height "
#Main.TBx10, ""
#Main.TBx10, "!setfocus"
#Main.STx11,"Message sent: "
END IF
END IF
WAIT
[ABOUT]
NOTICE " About..."+CR$+_
"LOGICData Table Controller"+CR$+CR$+_
" version "+PrgVersion$+CR$+CR$+_
"Flotulopex & Co. - July 2017"+CR$+CR$+_
" Liberty BASIC 4.5.1"+CR$+_
" and LB Booster 3.0.8"+CR$+CR$+_
" Serial com settings:"+CR$+_
" 115200,n,8,1"
WAIT
[QUIT]
IF ComOpen = 1 THEN CLOSE #ComHandle
CLOSE #Main
END