PDA

View Full Version : Need to know



oldpapa49
18-03-2009, 16:53
Ok, it has been like ... Forever since I did basic.. it was when unstructured was around.. But I need to know a few things before I try to attempt my handy work on writing a program..

1. Is thinBasic portable? Is the completed program able to run as stand-alone on any windows enviroment (Did not see this listed)
2. Can it be GUI?
3. Can I get the arrow keys to do functions? (example (up Arrow) value = value + 1)
4. Can I talk to a comm port and send what I want and get response.

What I want to do is write a program to send hex or ASCII code to the serial port to effect a change on a device, the device will echo back.

I would like mouse and key enteraction
and a display window showing echo.

Lets say its been 15 to 20 years maybe.. So .. Help an old guy..
I will dl the file and start poking around..
Old

Petr Schreiber
18-03-2009, 16:59
Hi,

and welcome to the forum.

1 - yes, ThinAir IDE has Bundle feature, allowing to create stand alone EXE. Supported platforms are currently Win98 and up (XP and up prefered )
2 - yes, see SampleScripts/UI
3 - yes, see GetAsyncKeyState ( for example ) in help file
4 - yes, see SampleScripts/COMM


Petr

oldpapa49
18-03-2009, 17:17
TY Petr.. That was a quick reply..

Life is Wonderful now..

Old

ErosOlmi
18-03-2009, 17:23
Ciao and welcome to thinBasic community forum.

As Petr already replied, all what you asked is absolutely doable for thinBasic.

1) Portability: thinBasic does not produce real machine executable but what we call "bundled exe". It is a kind of self contained box with all is needed to execute your applications in any Window platform (from Win98 to Windows 7 or any Windows server OS, from Win 2000 Server to Windows 2008 Server)

2) thinBasic is very GUI oriented. See by yourself installing thinBasic and going into \thinBasic\SampleScripts\UI\ directory. You will find many many script to have a look.
But thinBasic can easily mix Gui windows with Console window with OpenGL (via TBGL module) windows all at the same time (if needed).

3) Windows applications usually reacts to events fired by the Windows Operating system. So you can react to keyboards events or even bypass them and get direct access to keyboard. Once you intercept the correct event you can do what you need to do.

4) thinBasic is a modular language. It means there is a strong Core module in charge of the main language itself. Plus thinBasic has many modules dedicated to specific tasks. One of those modules is called "COMM" and is dedicated to handling serial communications. Check help for "thinBasic modules" (http://www.thinbasic.com/public/products/thinBasic/help/html/modules.htm).

Let us know if you need further info.

Ciao
Eros

oldpapa49
22-03-2009, 16:02
So, my very first post was March 18 and was new to thinBasic. With all your help and suggestions I'm near my finished project and its March 22nd.
So in 4 days, a Idea almost reality.

Only thing left is rs232 stuff and cleaning/tweaks.

Like a red/green LED like thingy for rs232.. But that is as they say, another story.

I tried thinForm but 1.8b fails at line 1726 or 1725, thats was last nite..
Ok, here is the nearly complete thinBasic joint adventure program!

oldpapa49
22-03-2009, 16:25
You know, it just never stops on what one might come up after a bit more trial and error,, This a real look at what the rs232 will see..
Before when I exited I saw the code of what was sent.. Now I see it real time!

A 15b

Petr Schreiber
22-03-2009, 16:46
Hi,

here is slightly modified version, which makes sure "current operation" will be drawn whole.
There was problem two controls shared the same ID.

Petr

oldpapa49
22-03-2009, 17:29
1, I did an assume on the first one at line # 124 (%HelpText) was omitted in mine.. So it was some sort of default.

2, Line 230 stuff moved to end.. Guess its better act on it after the routine than to do it before.

Well, I was close.. :)

Thanks again..

Petr Schreiber
22-03-2009, 17:46
Very close!,

problem on line 124 was in fact you did not passed any ID, so I guess ID of 0 was presumed => not good.

User control IDs should begin from WM_USER up, that is why I changed the constant definition in BEGIN CONST / END CONST block at line 70.


Thanks,
Petr

oldpapa49
23-03-2009, 23:15
Thought I let ya know, It working.. Got RS232 to talk to the monitor and it is going just fine..

I think I need to put an Exit button because if I remove all console commands, and USER CONSOLE, when I hit the X box on the opened window, it closes, but thinbasic.exe still running in task.. doing that a few times really screws up the ole computer.

If I close the console or window menu then console, no problem.

Wayne

Petr Schreiber
23-03-2009, 23:34
Wayne,

this is not normal behavior, X button should be fine.
I think there was problem in cbDialog, having one CASE outside of SELECT CASE.
You had WM_Destroy there twice.

Try to replace it with the following (based on 15c from this thread, be careful ):


CALLBACK FUNCTION cbDialog( ) AS LONG
errorNumber = ERR

SELECT CASE CBMSG

CASE %WM_INITDIALOG
'---Add controls

CONTROL ADD BUTTON, CBHNDL, %ID_Button_00, "Brightness", 40, 60, 100, 15, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_01, "Contrast", 160, 60, 100, 15, %WS_TABSTOP | %BS_DEFAULT CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_02, "Horz Position", 40, 80, 100, 15, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_03, "Horz Size", 160, 80, 100, 15, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_04, "Vert Center", 40, 100, 100, 15, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_05, "Vert Size", 160, 100, 100, 15, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_06, "Pin BOW ) ) ( (", 40, 140, 100, 15, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_07, "Pin ) ( ( )", 160, 160, 100, 15, %WS_TABSTOP | %BS_DEFAULT CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_08, "Pin ) ( ( )", 40, 160, 100, 15, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_09, "Pin / / \ \", 40, 180, 100, 15, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_10, "Pin Keyst / \ \ /", 160, 140, 100, 15, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_11, "Vert Lin", 160, 120, 100, 15, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_12, "Vertical Lin", 40, 120, 100, 15, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_13, "Reserve", 160, 180, 100, 15, %WS_TABSTOP | %BS_DEFAULT CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_14, "Reset", 179, 250, 40, 15, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin
'CONTROL ADD BUTTON, CBHNDL, %ID_Button_15, "Reserve" , 160, 100, 100, 35, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin

CONTROL ADD BUTTON, CBHNDL, %ID_Button_16, "Save Data", 100, 28, 40, 25, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_17, "Reset Mon", 160, 28, 40, 25, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_18, "Up", 129, 200, 40, 25, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_19, "Dn", 129, 240, 40, 25, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_20, "Left", 80, 220, 40, 25, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_21, "Right", 179, 220, 40, 25, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin

CONTROL ADD LABEL hDlg, %CtrlRes, "", 141, 229, 30, 10, %SS_CENTER ', cbPrintRS232
CONTROL ADD LABEL hDlg, %CtrlRes2, "", 150, 1, 100, 28, %SS_CENTER ', cbPrintRS232

CALL cbListbox
CALL cbPrintRS232 'displays what was sent to make believe rs232
'CALL cbRS232
CASE %WM_COMMAND


CASE %WM_SIZE '---The WM_SIZE message is sent to a window after its size has changed.
'
CASE %WM_SIZING '---The WM_SIZING message is sent to a window that the user is resizing.
' PRINTL TIME$, "Fired %WM_SIZING dialog message", CBWPARAM, LOWRD( CBLPARAM ), HIWRD( CBLPARAM )
'case %WM_MOVING
' local RC as RECT ptr
' RC = cblParam
' printl time$, "Fired %WM_MOVING dialog message", RC.nLeft, RC.nTop, RC.nRight, RC.nBottom
CASE %WM_MOVE
' PRINTL tmpstr, curitem, LO( INTEGER, CBLPARAM ), HI( INTEGER, CBLPARAM )
CASE %WM_DESTROY
'---Do whatever needed just before dialog is destroyed.
' PRINTL TIME$, "Fired %WM_DESTROY dialog message"
' PRINTL "Baud", baud


DIALOG END hVertDlg
DIALOG END hBriteDlg '00
DIALOG END hContDlg '01
DIALOG END hHorzPDlg '02
DIALOG END hHorzSDlg '03
DIALOG END hVertCtrDlg '04
DIALOG END hVertSizeDlg '05
DIALOG END hPinBowDlg '06
DIALOG END hPinCtrSz1Dlg '07
DIALOG END hPinCtrSz2Dlg '08
DIALOG END hPinTiltDlg '09
DIALOG END hPinKeyDlg '10
DIALOG END hVertLin1Dlg '11
DIALOG END hVertLin2Dlg '12

DIALOG END hSaveDlg '16
DIALOG END hReseDlg '17
DIALOG END hUpDlg '18
DIALOG END hDnDlg '19
DIALOG END hLeftDlg '20
DIALOG END hRightDlg '21
END SELECT
END FUNCTION


I still do not like much that WHILE/WEND in cbListbox, as it duplicates the callback above.


Petr

Petr Schreiber
23-03-2009, 23:42
Version no.2,


CALLBACK FUNCTION cbDialog( ) AS LONG
errorNumber = ERR

SELECT CASE CBMSG

CASE %WM_INITDIALOG
'---Add controls

CONTROL ADD BUTTON, CBHNDL, %ID_Button_00, "Brightness", 40, 60, 100, 15, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_01, "Contrast", 160, 60, 100, 15, %WS_TABSTOP | %BS_DEFAULT CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_02, "Horz Position", 40, 80, 100, 15, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_03, "Horz Size", 160, 80, 100, 15, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_04, "Vert Center", 40, 100, 100, 15, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_05, "Vert Size", 160, 100, 100, 15, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_06, "Pin BOW ) ) ( (", 40, 140, 100, 15, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_07, "Pin ) ( ( )", 160, 160, 100, 15, %WS_TABSTOP | %BS_DEFAULT CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_08, "Pin ) ( ( )", 40, 160, 100, 15, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_09, "Pin / / \ \", 40, 180, 100, 15, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_10, "Pin Keyst / \ \ /", 160, 140, 100, 15, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_11, "Vert Lin", 160, 120, 100, 15, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_12, "Vertical Lin", 40, 120, 100, 15, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_13, "Reserve", 160, 180, 100, 15, %WS_TABSTOP | %BS_DEFAULT CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_14, "Reset", 179, 250, 40, 15, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin
'CONTROL ADD BUTTON, CBHNDL, %ID_Button_15, "Reserve" , 160, 100, 100, 35, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin

CONTROL ADD BUTTON, CBHNDL, %ID_Button_16, "Save Data", 100, 28, 40, 25, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_17, "Reset Mon", 160, 28, 40, 25, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_18, "Up", 129, 200, 40, 25, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_19, "Dn", 129, 240, 40, 25, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_20, "Left", 80, 220, 40, 25, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin
CONTROL ADD BUTTON, CBHNDL, %ID_Button_21, "Right", 179, 220, 40, 25, %WS_TABSTOP | %BS_DEFAULT, CALL cbCheckButtonWin

CONTROL ADD LABEL CBHNDL, %CtrlRes, "", 141, 229, 30, 10, %SS_CENTER ', cbPrintRS232
CONTROL ADD LABEL CBHNDL, %CtrlRes2, "", 150, 1, 100, 28, %SS_CENTER ', cbPrintRS232

CONTROL ADD LISTBOX, CBHNDL, %List01, vList( ), 4, 30, 55, 30, 0, 0
CONTROL ADD TEXTBOX, CBHNDL, %Text01, vList( 1 ), 4, 15, 50, 12
CONTROL ADD BUTTON, CBHNDL, %Butt01, "Set", 60, 15, 30, 12

CALL cbPrintRS232 'displays what was sent to make believe rs232
'CALL cbRS232
CASE %WM_COMMAND

'---Test which control has been clicked
SELECT CASE cbctl
'---Something has happened with %List01
CASE %List01

SELECT CASE cbctlmsg
CASE %LBN_SELCHANGE
LISTBOX GET TEXT CBHNDL, %List01 TO tmpStr
CONTROL SET TEXT CBHNDL, %Text01, tmpStr ' & Count

END SELECT


CASE %Butt01

'---Get the text from a textbox and place into a string
CONTROL GET TEXT CBHNDL, %Text01 TO tmpStr
commport = tmpStr
'---Get the window unique ID of the control
CONTROL HANDLE CBHNDL, %List01 TO ID_List01

'---Get the number of items present into listbox
MaxItems = SENDMESSAGE( ID_List01, %LB_GETCOUNT, 0, 0 )

'---Get current selected item (remember it start at zero position)
'CurItem = sendmessage(ID_List01, %LB_GETCURSEL, 0, 0) + 1
LISTBOX GET SELECTED CBHNDL, %List01 TO CurItem

'---Now delete selected item ...
SENDMESSAGE( ID_List01, %LB_DELETESTRING, CurItem - 1, 0 )

'---...and insert new text in same position
SENDMESSAGE( ID_List01, %LB_INSERTSTRING, CurItem - 1, STRPTR( tmpStr ))

END SELECT

END SELECT
END FUNCTION