PDA

View Full Version : I'm Back!



oldpapa49
15-10-2012, 23:29
He guys, I'm back with a new something.. Here is a little history of what I have and what I need.

Ok, this project involves a CAN BUS item. Its a TSO which is like a remote control for a medical table. I have and using an Arduino UNO with a Sparkfun Can-Bus Shield. I'm able to read the pressing of the switches and output the info via USB/Serial that ThinBasic will pickup and display. I have assign 3 switches codes to test and print the exact name of the switch on the comm screen.

The Arduino UNO and SparkFun CAN-BUS program is very short. What it does is set speed of the CAN BUS, test for activity and writes it out on the serial comm 4 in my case. I do not open a serial window for ThinBasic needs it.

ThinBasic sits watching the serial line and does the tests eq:

If value3 = 0430015600 Then Console_WriteLine "Image Grab"
If value3 = 1606592704 Then Console_WriteLine "Detector Size -"
If value3 = 1606032704 Then Console_WriteLine "Detector Size +"

That's my test to see it on the open comm window.

This what I'm trying to find if I can say if value3 = 0430015600 Then Console_WriteLine "Image Grab" and it would refer to a box on a screen Make it brighter box (hi-light) it in a field of other boxes.

Be like 3 rows of buttons and 9 columns. The thing is, not all will be used. So I will need to ask what TSO they have and make a screen look like it. To top it off, there will be joystick like switches.. But that can be a circle with little boxes resembling a led.


I was thinking an Array assigning values in the array from a saved file that will represent a TSO.. 16 TSO that I know of..
But that is down the road..

I just need to learn a way to do it..

I will start making a box looking like the TSO and add 3 boxes to represent the switches.

TY guys..

Petr Schreiber
17-10-2012, 17:55
Hi,

it sounds like fun project!

Maybe little tip - instead of:


If value3 = 0430015600 Then Console_WriteLine "Image Grab"
If value3 = 1606592704 Then Console_WriteLine "Detector Size -"
If value3 = 1606032704 Then Console_WriteLine "Detector Size +"


... you could use:


Select Case value3

Case 0430015600
Console_WriteLine "Image Grab"

Case 1606592704
Console_WriteLine "Detector Size -"

Case 1606032704
Console_WriteLine "Detector Size +"

End Select


It is a bit longer, but in my projects it seems easily maintainable way to handle multiple tests for value of single variable.


Petr

ErosOlmi
17-10-2012, 21:09
Console_WriteLine is also aliased by PrintL
Much less typing

oldpapa49
17-10-2012, 22:01
Hey guys, thanks for getting back..

This where I'm at now..

I have got a box to display in the console. I would rather display in a UI panel area since there can be a few boxes representing a button.

The console displays the box with the name on top as the code says (I can not find the color chart examples). It only 1 box in the console so far.
When I depress first time it changes color, I sleep it before I change the color of it for not pressed.

For the life of me, I can not find or figure away to do this through the UI. I made a nice display but the Do/Loop kills it..

I need the Do/Loop to scan the serial port for the codes.

Basically I want to press a button and display the action on the screen. I hate to do it via console, looks so DOS :).

There are 14 TSO type, so I will need to add a file to be read after the type has been selected. Petr, if you recall the other program that has serial selection.. be that + the TSO type. BTW, that program is still in use and works great.

I do not know if there is another way of sniffing the serial port for the codes from the Arduino, but I'm always open for suggestions.

I'm attaching the code, it is a little of this and a little of that!


Wayne


' TMI TSO Test Program
' Program by W Little and Others
' 10/18/2012 rev . 01
' This program works with Arduino UNO and SparkFun CAN BUS Shield
' It will read via the USB as serial and Displays Button/Joystick action
'
' Needs:
' Read serial and decode data and light/display correct BOX location as ON and turn off. TBD
' current test TSO is 9896-001-80971
' need to creat away to select TSO and set box/button field.
' This program currently hardcoded for just 1 TSO as a learning tool
' Look here : for rev updates and feature additions:
'
' Currently working routine with RS232 support
' Screen info available to user
' This Program would not be possible if it
' where not the HELP from thinBasic Forum
' www.community.thinbasic.com GURU's
' Petr Schreiber, Eros Olmi,
' LionHeart008, Michael Clease and many
' other hero's behind the screen!
' Kudo's to them ALL!
' W Little wlfredl@yahoo.com
'
'--------------------------------------------
'
'--------------------------------------------
USES "UI"
Uses "CONSOLE"
USES "COMM"

Dim hDLG As DWord
'---------------------------------
Dim reList(20) As DWord
'--------------------------------- G
Dim hSaveDlg As DWord '16 O
DIM hReseDlg AS DWORD '17 O
DIM hUpDlg AS DWORD '18 D
DIM hDnDlg AS DWORD '19 !
DIM hLeftDlg AS DWORD '20
DIM hRightDlg AS DWORD '21 commcode ref
'---------------------------------
' I Know, Time to Clean Soon!
Dim display As String
Dim Chn As String
Dim Msg As String
DIM wparam,lparam as DWORD
DIM Win1Params as DWORD VALUE = %WS_POPUP or %WS_VISIBLE or %WS_CLIPCHILDREN or %WS_CAPTION or %WS_SYSMENU or %WS_MINIMIZEBOX or _
%WS_THICKFRAME
DIM n as LONG
DIM lResult as LONG
Dim errornumber As Long '
'DIM cbctl as DWORD '
Dim hComm As Long
DIM funct as String
DIM data as String
Dim nBytes As Long
DIM DECI as DWORD
DIM ModemData as DWORD
Dim value2 As String
Dim value3 As DWord
dim CountAtiB as DWORD
Dim CountATI As Long
Dim sBuffer As String
Dim MaxComm As DWord = 15'Change me to increase vList
DIM vList(MaxComm) AS String
dim ID_List01 as long
dim MaxItems as long
dim CurItem as long
DIM tmpStr AS STRING
dim tmpLong as long
' RS232 stuff
DIM commport AS String ' Select from main menu
DIM COMMDATA AS Dword ' 0 to 255 dec. Input from arrow or up down buttons
DIM commcode as dword ' 0 to 15, 40 (64 hex), 41 (65 hex) to rs232
DIM commcodeOLD as DWORD
DIM txtstr as String
DIM commstrOLD as String
DIM commstr as String
DIM commprint as String
DIM Counter AS LONG = 1'---Counter to count output lines
' code sent to rs232 for adj should be commcode, commdata

BEGIN CONST

'----------------------------------------
%Text01
%List01
%Butt01
%ID_HELP_LABEL
%CtrlRes
%MsgText
%HelpText
%helpText2
%CtrlRes2
%ButtonClose = 1001
END CONST

' New Code
' DIM vList(MaxElements) AS STRING (Only Supporting 4 Com Ports
' If you want more Com ports, change MaxElements DIM statement

vList(1) = "Com1"
vList(2) = "Com2"
vList(3) = "Com3"
vList(4) = "Com4"
vList(5) = "Com5"
vList(6) = "Com6"
vList(7) = "Com7"
vList(8) = "Com8"


commport = "Com1"
commcode = "-1"
' commdata = 127 'midrange start
commstr = "NO Function Selected"
'chn = 0 'US displays

hComm = COMM_FreeFile
COMM_Open("COM4", hComm)
COMM_Set(hComm, %COMM_BAUD, 115200)
'COMM_Set(hComm, %COMM_PARITY, 0)
'COMM_Set(hComm, %COMM_BYTE, 8)
'COMM_Set(hComm, %COMM_STOP, 0)
'COMM_Set(hComm, %COMM_RTSFLOW, 0)
'Console_WriteLine("Opening COM" & " as hComm=" & hComm)
' Count = 2
Console_WriteLine Chr$(13)

Function TBMain( ) As Long

Dialog New 0, "Philips TSO Test Program 9896-001-80971 (Rv .01)", -1, -1, 560, 300, Win1Params, 0 To hDlg

Control Add Label, hDlg, %HelpText,"Selected Commport is 4", 3, 1, 150, 12

Control Add Textbox , hDlg, %CtrlRes, commdata, 129, 250, 30, 15, Win1Params
'---Set window minimum size
Dialog Set Minsize hDlg, 560,320

Control Add Button, hDlg, %ButtonClose, "Click to kill", 90, 50, 150, 100

Dialog Show Modal hDlg, Call cbDialog

End Function

CallBack Function cbDialog () As Long

'Select Case CBMSG

' Case %WM_COMMAND


'If CBWPARAM = %ButtonClose Then Dialog End CBHNDL


' Case %WM_DESTROY

' MsgBox 0, "Window is to be destroyed."



' End Select

'End Function
Do

' ' For count = 2 To 4
' Sleep 100 ' delay for modem to respond
nBytes = COMM_Get(hComm, %COMM_RXQUE)

COMM_Recv(hComm, nBytes, sBuffer)
' value2 = sBuffer
' ' Count = count + 1
value2 = LEFT$(sBuffer, nBytes)
If Asc(value2) = -1 Then Loop 'need this to skip no data
If Asc(value2) >1 Then Call displayBox

value3 = DIGIT$(value2)
' Console_WriteLine (nBytes)
' Console_WriteLine (value3)




' Console_WriteLine(value2)
Loop

End Function



'---Show dialog in modal mode
'---cbDialog function is the callback function handling dialog events
'---Application control will pass to dialog callback till dialog will exists
'Dialog Show Modal hDlg' , Call cbDialog
'---If execution comes here it means main dialog as been destroyed
' PRINTL "---Application finished. Press a key to end---"
'WAITKEY



' Callback procedure for main window
'------------------------------------------------------------------------------
CallBack Function displayBox( ) As Long

If value3 = 0430015600 Then Call ImageGrab
If value3 = 1606592704 Then Console_WriteLine "Detector size -"
If value3 = 1606032704 Then Console_WriteLine "Detector size +"
If value3 = 0420015600 Then Console_WriteLine "Beam size"
If value3 = 2345309936 Then Console_WriteLine "FluoFlavor 1"
If value3 = 2355309936 Then Console_WriteLine "FluoFlavor 2"
If value3 = 2365309936 Then Console_WriteLine "FluoFlavor 3"
If value3 = 0490015600 Then Console_WriteLine "Reset buzzer"
If value3 = 4140015600 Then Console_WriteLine "Wedge follow"

Sleep 100
End Function

CallBack Function ImageGrab( ) As Long

Console_Box(60, 5, 10, 5, 24, 00, "Image Grab", 15, %CONSOLE_BOX_FLAG_3DON)
Sleep 1000
Console_Box(60, 5, 10, 5, 17, 24, " ", 15, %CONSOLE_BOX_FLAG_3DOFF)
End Function

'You Have Reach the Bottom, there is no other place to go other than UP!

Michael Clease
17-10-2012, 22:48
Hello Wayne

Do loops in the main callback is a big no no

At the moment any windows event to your window will call a new callback that will include mouse over, click, paint.....

you should look into timers, these are events that have unique ids and times, have a look at the example in the samples.

I do some RS232 work and this is method i use :


Case %WM_TIMER If CBWPARAM = %IDC_TIMER Then
Dialog Kill Timer CBHNDL, %IDC_TIMER
GetComports(CBHNDL)
GetFirmware(CBHNDL)
Dialog Set Timer CBHNDL, %IDC_TIMER, %TIMER_DELAY
EndIf




So check the timer event and control name and if valid kill the timer (we dont want to timer still running while were are working on it we might get more than one event), do whatever work is required and then enable the timer again.

Hope this helps.


Mike C.

oldpapa49
18-10-2012, 00:19
Mr. Clease,

I will look into this tomorrow, or maybe tonite,
I was just going to copy this last file into a thumb drive, not knowing if I even will work on it..

Thanks again..

oldpapa49
18-10-2012, 15:27
Hi,

it sounds like fun project!

Maybe little tip - instead of:


If value3 = 0430015600 Then Console_WriteLine "Image Grab"
If value3 = 1606592704 Then Console_WriteLine "Detector Size -"
If value3 = 1606032704 Then Console_WriteLine "Detector Size +"


... you could use:


Select Case value3

Case 0430015600
Console_WriteLine "Image Grab"

Case 1606592704
Console_WriteLine "Detector Size -"

Case 1606032704
Console_WriteLine "Detector Size +"

End Select


It is a bit longer, but in my projects it seems easily maintainable way to handle multiple tests for value of single variable.


Petr

Petr, I like this.. I have added this to my current code and makes less use of what I was going to do (Call's).

And if you look at my complete code, it is a cut and paste from that program you guys helped with way back when. Unlike that code, I ran a check to pull stored eeprom info from the monitor and then made selection to adjust
certain parameters of the monitor and then save.

Here, I need to monitor the serial port (USB to Serial). The hookup of the TSO under test is
TSO to SparkFun CAN BUS device which is mounted to the Arduino UNO board. The program running the two is simple and just sits waiting for a CAN BUS code sent from the TSO
The Arduino code once it recieves the code writes it to the serial port at 115200 right now..

I'm pasting that code after this.

The ThinBasic program need to watch for the serial activity testing it all the time (Michael) has paste a timer code (I need to understand it, so I will play with the change today)
When the code is not 0 or -1, It grabs it as a digit$ (This was easier to do checks on) and then to display to the screen in console.

My vision is to make a screen like the old monitor screen and instead of buttons, use boxes at the same location like the TSO buttons and have act as if they light when a button is pressed.
Maybe the "UI" is not the one to use.

Right now I have a box in console that changes color and in title tells which button is pressed.

Arduino code:


// demo: CAN-BUS Shield, receive data
#include "mcp_can.h"
#include <SPI.h>
#include <stdio.h>
#define INT8U unsigned char

INT8U Flag_Recv = 0;
INT8U len = 0;
INT8U buf[8];
char str[20];
void setup()
{
CAN.begin(CAN_250KBPS); // init can bus : baudrate = 250k
attachInterrupt(0, MCP2515_ISR, FALLING); // start interrupt
Serial.begin(115200);
}

void MCP2515_ISR()
{
Flag_Recv = 1;
}

void loop()
{
if(Flag_Recv) // check if get data
{
Flag_Recv = 0; // clear flag
CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf
// Serial.println("CAN_BUS GET DATA!");
// Serial.print("data len = ");Serial.println(len);
for(int i = 0; i<len; i++) // print the data
{
Serial.print(buf[i]);Serial.print("\t");
}
Serial.println();
}
}


Wayne

oldpapa49
18-10-2012, 19:04
Hello Wayne

Do loops in the main callback is a big no no

At the moment any windows event to your window will call a new callback that will include mouse over, click, paint.....

you should look into timers, these are events that have unique ids and times, have a look at the example in the samples.

I do some RS232 work and this is method i use :


Case %WM_TIMER If CBWPARAM = %IDC_TIMER Then
Dialog Kill Timer CBHNDL, %IDC_TIMER
GetComports(CBHNDL)
GetFirmware(CBHNDL)
Dialog Set Timer CBHNDL, %IDC_TIMER, %TIMER_DELAY
EndIf




So check the timer event and control name and if valid kill the timer (we dont want to timer still running while were are working on it we might get more than one event), do whatever work is required and then enable the timer again.

Hope this helps.


Mike C.

Could you point me to the script.. I'm failing in locating it..

And I see what you mean... DO LOOP eats CPU I was nearly at 100% on 1 core... Once I l=killed the background task, it went down to a 7%..

I think maybe Petr helped me out before.. I look into that too..

Wayne

Petr Schreiber
19-10-2012, 09:12
Hi,

I tried to change the do/loop to timer, as Mike suggested and added the select case and shutdown using button:


' TMI TSO Test Program
' Program by W Little and Others
' 10/18/2012 rev . 01
' This program works with Arduino UNO and SparkFun CAN BUS Shield
' It will read via the USB as serial and Displays Button/Joystick action
'
' Needs:
' Read serial and decode data and light/display correct BOX location as ON and turn off. TBD
' current test TSO is 9896-001-80971
' need to creat away to select TSO and set box/button field.
' This program currently hardcoded for just 1 TSO as a learning tool
' Look here : for rev updates and feature additions:
'
' Currently working routine with RS232 support
' Screen info available to user
' This Program would not be possible if it
' where not the HELP from thinBasic Forum
' www.community.thinbasic.com GURU's
' Petr Schreiber, Eros Olmi,
' LionHeart008, Michael Clease and many
' other hero's behind the screen!
' Kudo's to them ALL!
' W Little wlfredl@yahoo.com
'
'--------------------------------------------
'
'--------------------------------------------
Uses "UI"
Uses "CONSOLE"
Uses "COMM"

Dim hDLG As DWord
'---------------------------------
Dim reList(20) As DWord
'--------------------------------- G
Dim hSaveDlg As DWord '16 O
Dim hReseDlg As DWord '17 O
Dim hUpDlg As DWord '18 D
Dim hDnDlg As DWord '19 !
Dim hLeftDlg As DWord '20
Dim hRightDlg As DWord '21 commcode ref
'---------------------------------
' I Know, Time to Clean Soon!
Dim display As String
Dim Chn As String
Dim Msg As String
Dim wparam,lparam As DWord
Dim Win1Params As DWord Value = %WS_POPUP Or %WS_VISIBLE Or %WS_CLIPCHILDREN Or %WS_CAPTION Or %WS_SYSMENU Or %WS_MINIMIZEBOX Or _
%WS_THICKFRAME
Dim n As Long
Dim lResult As Long
Dim errornumber As Long '
'DIM cbctl as DWORD '
Dim hComm As Long
Dim funct As String
Dim data As String
Dim nBytes As Long
Dim DECI As DWord
Dim ModemData As DWord
Dim value2 As String
Dim value3 As DWord
Dim CountAtiB As DWord
Dim CountATI As Long
Dim sBuffer As String
Dim MaxComm As DWord = 15'Change me to increase vList
Dim vList(MaxComm) As String
Dim ID_List01 As Long
Dim MaxItems As Long
Dim CurItem As Long
Dim tmpStr As String
Dim tmpLong As Long
' RS232 stuff
Dim commport As String ' Select from main menu
Dim COMMDATA As DWord ' 0 to 255 dec. Input from arrow or up down buttons
Dim commcode As DWord ' 0 to 15, 40 (64 hex), 41 (65 hex) to rs232
Dim commcodeOLD As DWord
Dim txtstr As String
Dim commstrOLD As String
Dim commstr As String
Dim commprint As String
Dim Counter As Long = 1'---Counter to count output lines
' code sent to rs232 for adj should be commcode, commdata

Begin ControlID

'----------------------------------------
%Text01
%List01
%Butt01
%ID_HELP_LABEL
%CtrlRes
%MsgText
%HelpText
%helpText2
%CtrlRes2
%ButtonClose

%mainTimer
End ControlID

' New Code

' If you want more Com ports, change MaxElements DIM statement
Long i

For i = 1 To UBound(vList)
vList(i) = "Com" + Format$(i)
Next

commport = "Com1"
commcode = "-1"
' commdata = 127 'midrange start
commstr = "NO Function Selected"
'chn = 0 'US displays

hComm = COMM_FreeFile
COMM_Open("COM4", hComm)
COMM_Set(hComm, %COMM_BAUD, 115200)
'COMM_Set(hComm, %COMM_PARITY, 0)
'COMM_Set(hComm, %COMM_BYTE, 8)
'COMM_Set(hComm, %COMM_STOP, 0)
'COMM_Set(hComm, %COMM_RTSFLOW, 0)
'Console_WriteLine("Opening COM" & " as hComm=" & hComm)
' Count = 2
Console_WriteLine Chr$(13)

Function TBMain( ) As Long

Dialog New 0, "Philips TSO Test Program 9896-001-80971 (Rv .01)", -1, -1, 560, 300, Win1Params, 0 To hDlg

Control Add Label, hDlg, %HelpText,"Selected Commport is 4", 3, 1, 150, 12

Control Add Textbox , hDlg, %CtrlRes, commdata, 129, 250, 30, 15, Win1Params

Control Add Button, hDlg, %ButtonClose, "Click to kill", 90, 50, 150, 100

'---Set window minimum size
Dialog Set Minsize hDlg, 560,320

Dialog Show Modal hDlg, Call cbDialog

End Function

CallBack Function cbDialog () As Long

Select Case CBMSG
' -- When program starts, we start timer
Case %WM_INITDIALOG
Dialog Set Timer CBHNDL, %mainTimer, 1

' -- Handling button press
Case %WM_COMMAND
If CBCTL = %ButtonClose And CBCTLMSG = %BN_CLICKED Then
Dialog End CBHNDL
End If

' -- Once timer ticks
Case %WM_TIMER
If CBCTL = %mainTimer Then

nBytes = COMM_Get(hComm, %COMM_RXQUE)

COMM_Recv(hComm, nBytes, sBuffer)

value2 = LEFT$(sBuffer, nBytes)

If Asc(value2) = -1 Then Exit Function
If Asc(value2) > 1 Then Call displayBox

End If

' -- Shutdown of the timer
Case %WM_DESTROY
Dialog Kill Timer CBHNDL, %mainTimer

End Select

End Function


' Procedure for handling value3
'------------------------------------------------------------------------------
Function displayBox( ) As Long

Select Case value3
Case 0430015600
Call ImageGrab

Case 1606592704
Console_WriteLine "Detector size -"

Case 1606032704
Console_WriteLine "Detector size +"

Case 0420015600
Console_WriteLine "Beam size"

Case 2345309936
Console_WriteLine "FluoFlavor 1"

Case 2355309936
Console_WriteLine "FluoFlavor 2"

Case 2365309936
Console_WriteLine "FluoFlavor 3"

Case 0490015600
Console_WriteLine "Reset buzzer"

Case 4140015600
Console_WriteLine "Wedge follow"

End Select

Sleep 100

End Function

Function ImageGrab( ) As Long

Console_Box(60, 5, 10, 5, 24, 00, "Image Grab", 15, %CONSOLE_BOX_FLAG_3DON)
Sleep 1000
Console_Box(60, 5, 10, 5, 17, 24, " ", 15, %CONSOLE_BOX_FLAG_3DOFF)

End Function

'You Have Reach the Bottom, there is no other place to go other than UP!



Petr

Michael Clease
19-10-2012, 09:51
This will give a more reliable timer function and also if no data is received it doesn't do any thing.



Case %WM_TIMER
If CBCTL = %mainTimer Then
DialogKill Timer CBHNDL, %mainTimer ' kill timer so multiple calls not received
nBytes = COMM_Get(hComm, %COMM_RXQUE)
IF nBytes then
COMM_Recv(hComm, nBytes, sBuffer)
value2 = LEFT$(sBuffer, nBytes)
If Asc(value2) = -1 Then Exit Function
If Asc(value2) > 1 Then Call displayBox
END IF
DialogSetTimerCBHNDL, %mainTimer, 1 ' I have found values below 20-30 very dont really work.
' not really surprised on an interpreted language and thats what a buffer is for.


End If

oldpapa49
19-10-2012, 21:59
Ok, all, here is the near never to be done test of 1 TSO model...

I wonder if I will make a file to load in the 14 different models and make a screen up from the file?
Or will I just make 13 more ThinBasic programs...

Time will tell..

Mr. Clease, I have your timer rem out, will mess with it later..
Petr, your like me, for got the value3= line... All test in the case failed, I found it..

And here is the code.. and it works great.. cpu time near 0

And I got rid of most of the waste code so far.. and I played with the buttons as well.. I think it is a nice layout



' Empty GUI script created on 10-19-2012 07:19:11 by (ThinAIR)
' TMI TSO Test Program
' Program by W Little and Others
' 10/19/2012 rev . 04
' This program works with Arduino UNO and SparkFun CAN BUS Shield
' It will read via the USB as serial and Displays Button/Joystick action
'
' Needs:
' Read serial and decode data and light/display correct BOX location as ON and turn off. TBD
' current test TSO is 9896-001-80971
' need to creat away to select TSO and set box/button field.
' This program currently hardcoded for just 1 TSO as a learning tool
' Look here : for rev updates and feature additions:
'
' Currently working routine with RS232 support
' Screen info available to user
' This Program would not be possible if it
' where not the HELP from thinBasic Forum
' www.community.thinbasic.com GURU's
' Petr Schreiber, Eros Olmi,
' LionHeart008, Michael Clease and many
' other hero's behind the screen!
' Kudo's to them ALL!
' W Little wlfredl@yahoo.com
'
'--------------------------------------------
'
'--------------------------------------------
Uses "UI"
'Uses "CONSOLE"
Uses "COMM"

Dim hDLG As DWord
'---------------------------------
Dim reList(20) As DWord
'--------------------------------- G
' I Know, Time to Clean Soon!
Dim Win1Params As DWord Value = %WS_POPUP Or %WS_VISIBLE Or %WS_CLIPCHILDREN Or %WS_CAPTION Or %WS_SYSMENU Or %WS_MINIMIZEBOX Or _
%WS_THICKFRAME Or %DS_3DLOOK

Dim hComm As Long
Dim nBytes As Long
Dim value2 As String
Dim value3 As DWord
Dim sBuffer As String
Dim MaxComm As DWord = 15'Change me to increase vList
Dim vList(MaxComm) As String
' RS232 stuff
Dim commport As String ' Select from main menu
Dim COMMDATA As DWord ' 0 to 255 dec. Input from arrow or up down buttons
Dim commcode As DWord ' 0 to 15, 40 (64 hex), 41 (65 hex) to rs232
Dim commstr As String

' code sent to rs232 for adj should be commcode, commdata

Begin ControlID

%ID_Button_00 'Brightness
%ID_Button_01 'Detector Size -
%ID_Button_02 'Detector Size +
%ID_Button_03 'Fluoflavor 1
%ID_Button_04 'Fluoflavor 2
%ID_Button_05 'Fluoflavor 3
%ID_Button_06 'Image Grab
%ID_Button_07 'Not Used
%ID_Button_08 'Not Used
%ID_Button_09 'Buzzer Reset
%ID_Button_10 'Beam Size
%ID_Button_11 'Right Wedge
%ID_Button_12 'Shutters UP
%ID_Button_13 'Shutters Dn
%ID_Button_14 'Shutters Lft
%ID_Button_15 'Shutters Rt
%ID_Button_16 'Shutters Clik
%ID_Button_17 'Rt wedge Lft
%ID_Button_18 'Rt wedge Rt
%ID_Button_19 'Rt Wedge CW
%ID_Button_20 'Rt Wedge CCW
%ID_Button_21 'Rt Wedge Clik
%ID_BUTTON_22 'Reserve



'----------------------------------------
%Text01
%List01
%Butt01
%ID_HELP_LABEL
%CtrlRes
%MsgText
%HelpText
%helpText2
%CtrlRes2
%ButtonClose
%IDC_TIMER
%mainTimer
End ControlID

' New Code




' If you want more Com ports, change MaxElements DIM statement
Long i

For i = 1 To UBound(vList)
vList(i) = "Com" + Format$(i)
Next

commport = "Com4"
commcode = "-1"
' commdata = 127 'midrange start
commstr = "NO Function Selected"


hComm = COMM_FreeFile
COMM_Open(commport, hComm)
COMM_Set(hComm, %COMM_BAUD, 115200)

Function TBMain( ) As Long

Dialog New 0, "Philips TSO Test Program 9896-001-80971 (Rv .04)", -1, -1, 560, 300, Win1Params, 0 To hDlg

'Control Add Label, hDlg, %HelpText,"Selected Commport is ", commport, 3, 1, 150, 12

'Control Add Textbox , hDlg, %CtrlRes, commdata, 129, 250, 30, 15, Win1Params

Control Add Button hDlg, %ButtonClose, "Click to kill", 0, 0, 40, 25, %BS_CENTER | %WS_TABSTOP | %BS_MULTILINE |%WS_DLGFRAME

Control Add Button hDlg, %ID_Button_01, "Detector Size -" , 140, 40, 40, 25, %BS_CENTER | %WS_TABSTOP | %BS_MULTILINE |%WS_DLGFRAME
Control Disable hDlg, %ID_Button_01

Control Add Label hDlg, %ID_Button_00, "________________________________________________________________________________________________________________________ ",_
0, 145, 580, 15, %SS_CENTER
Control Add Button hDlg, %ID_Button_02, "Detector Size +" , 200, 40, 40, 25, %BS_CENTER | %WS_TABSTOP | %BS_MULTILINE |%WS_DLGFRAME
Control Disable hDlg, %ID_Button_02

Control Add Button hDlg, %ID_Button_03, "Fluoflavor 1" , 380, 40, 40, 25, %BS_CENTER | %WS_TABSTOP | %BS_MULTILINE |%WS_DLGFRAME
Control Disable hDlg, %ID_Button_03

Control Add Button hDlg, %ID_Button_04, "Fluoflavor 2" , 440, 40, 40, 25, %BS_CENTER | %WS_TABSTOP | %BS_MULTILINE |%WS_DLGFRAME
Control Disable hDlg, %ID_Button_04

Control Add Button hDlg, %ID_Button_05, "Fluoflavor 3" , 500, 40, 40, 25, %BS_CENTER | %WS_TABSTOP | %BS_MULTILINE |%WS_DLGFRAME
Control Disable hDlg, %ID_Button_05

Control Add Button, hDlg, %ID_Button_06, "Image Grab" , 20, 80, 40, 25,%BS_CENTER| %WS_TABSTOP | %BS_MULTILINE |%WS_DLGFRAME
Control Disable hDlg, %ID_Button_06

Control Add Button, hDlg, %ID_Button_07, "Not Used" , 140, 80, 40, 25,%BS_CENTER| %WS_TABSTOP | %BS_DEFAULT |%WS_DLGFRAME
Control Disable hDlg, %ID_Button_07

Control Add Button, hDlg, %ID_Button_08, "Not Used" , 200, 80, 40, 25,%BS_CENTER| %WS_TABSTOP | %BS_MULTILINE |%WS_DLGFRAME
Control Disable hDlg, %ID_Button_08

Control Add Button, hDlg, %ID_Button_09, "Reset Buzzer" , 500, 80, 40, 25,%BS_CENTER| %WS_TABSTOP | %BS_MULTILINE |%WS_DLGFRAME
Control Disable hDlg, %ID_Button_09

Control Add Button, hDlg, %ID_Button_10, "Beam Size" , 80, 120, 40, 25,%BS_CENTER | %WS_TABSTOP | %BS_MULTILINE |%WS_DLGFRAME
Control Disable hDlg, %ID_Button_10

Control Add Button, hDlg, %ID_Button_11, "Wedge follow" , 440, 120, 40, 25,%BS_CENTER | %WS_TABSTOP | %BS_MULTILINE |%WS_DLGFRAME
Control Disable hDlg, %ID_Button_11

Control Add Button, hDlg, %ID_Button_12, "Shutters Up" , 80, 160, 40, 25, %BS_CENTER | %WS_TABSTOP | %BS_MULTILINE |%WS_DLGFRAME
Control Disable hDlg, %ID_Button_12

Control Add Button, hDlg, %ID_Button_13, "Shutters Down" , 80, 220, 40, 25, %BS_CENTER | %WS_TABSTOP | %BS_MULTILINE |%WS_DLGFRAME
Control Disable hDlg, %ID_Button_13

Control Add Button, hDlg, %ID_Button_14, "Shutters Left" , 40, 190, 40, 25, %BS_CENTER | %WS_TABSTOP | %BS_MULTILINE |%WS_DLGFRAME
Control Disable hDlg, %ID_Button_14

Control Add Button, hDlg, %ID_Button_15, "Shutters Right" , 120, 190, 40, 25, %BS_CENTER | %WS_TABSTOP | %BS_MULTILINE |%WS_DLGFRAME
Control Disable hDlg, %ID_Button_15

Control Add Button, hDlg, %ID_Button_16, "Shutters Clik" , 82, 190, 35, 25, %BS_CENTER | %WS_TABSTOP | %BS_MULTILINE |%WS_DLGFRAME
Control Disable hDlg, %ID_Button_16

Control Add Button, hDlg, %ID_Button_17, "Right wedge left" , 400, 160, 40, 35, %BS_CENTER | %WS_TABSTOP | %BS_MULTILINE |%WS_DLGFRAME
Control Disable hDlg, %ID_Button_17

Control Add Button, hDlg, %ID_Button_18, "Right wedge right" , 480, 160, 40, 35, %BS_CENTER | %WS_TABSTOP | %BS_MULTILINE |%WS_DLGFRAME
Control Disable hDlg, %ID_Button_18

Control Add Button, hDlg, %ID_Button_19, "Right wedge CW" , 405, 210, 35, 55, %BS_CENTER | %WS_TABSTOP | %BS_MULTILINE |%WS_DLGFRAME
Control Disable hDlg, %ID_Button_19

Control Add Button, hDlg, %ID_Button_20, "Right wedge CCW" , 480, 210, 35, 55, %BS_CENTER | %WS_TABSTOP | %BS_MULTILINE |%WS_DLGFRAME
Control Disable hDlg, %ID_Button_20

Control Add Button, hDlg, %ID_Button_21, "Right wedge Clik" , 445, 180, 30, 35, %BS_CENTER | %WS_TABSTOP | %BS_MULTILINE |%WS_DLGFRAME
Control Disable hDlg, %ID_Button_21


'---Set window minimum size
Dialog Set Minsize hDlg, 560,320

Dialog Show Modal hDlg, Call cbDialog

End Function

CallBack Function cbDialog () As Long

Select Case CBMSG
' -- When program starts, we start timer
Case %WM_INITDIALOG
Dialog Set Timer CBHNDL, %mainTimer, 1

' -- Handling button press
Case %WM_COMMAND
If CBCTL = %ButtonClose And CBCTLMSG = %BN_CLICKED Then
Dialog End CBHNDL
End If

' Case %WM_TIMER
' If CBWPARAM = %IDC_TIMER Then
' Dialog Kill Timer CBHNDL, %IDC_TIMER
' GetComports(CBHNDL)
' GetFirmware(CBHNDL)
' nBytes = COMM_Get(hComm, %COMM_RXQUE)

' COMM_Recv(hComm, nBytes, sBuffer)

' value2 = LEFT$(sBuffer, nBytes)
' value3 =DIGIT$(value2)
' If Asc(value2) = -1 Then Exit Function
' If Asc(value2) > 1 Then Call displayBox

' Dialog Set Timer CBHNDL, %IDC_TIMER, %TIMER_DELAY
'EndIf


' -- Once timer ticks
Case %WM_TIMER
If CBCTL = %mainTimer Then

nBytes = COMM_Get(hComm, %COMM_RXQUE)

COMM_Recv(hComm, nBytes, sBuffer)

value2 = LEFT$(sBuffer, nBytes)
value3 =DIGIT$(value2)
If Asc(value2) = -1 Then Exit Function
If Asc(value2) > 1 Then Call displayBox

End If

' -- Shutdown of the timer
Case %WM_DESTROY
Dialog Kill Timer CBHNDL, %mainTimer

End Select

End Function


' Procedure for handling value3
'------------------------------------------------------------------------------


Function displayBox( ) As Long
Select Case value3

Case 0430015600
Control Enable hDlg, %ID_Button_06
Sleep 500
Control Disable hDlg, %ID_Button_06

Case 1606592704
Control Enable hDlg, %ID_Button_01
Sleep 500
Control Disable hDlg, %ID_Button_01

Case 1606032704
Control Enable hDlg, %ID_Button_02
Sleep 500
Control Disable hDlg, %ID_Button_02

Case 0420015600
Control Enable hDlg, %ID_Button_10
Sleep 500
Control Disable hDlg, %ID_Button_10

Case 2345309936
Control Enable hDlg, %ID_Button_03
Sleep 500
Control Disable hDlg, %ID_Button_03

Case 2355309936
Control Enable hDlg, %ID_Button_04
Sleep 500
Control Disable hDlg, %ID_Button_04

Case 2365309936
Control Enable hDlg, %ID_Button_05
Sleep 500
Control Disable hDlg, %ID_Button_05

Case 0490015600
Control Enable hDlg, %ID_Button_09
Sleep 500
Control Disable hDlg, %ID_Button_09

Case 4140015600
Control Enable hDlg, %ID_Button_11
Sleep 500
Control Disable hDlg, %ID_Button_11

Case 0450015600
Control Enable hDlg, %ID_Button_07
Sleep 500
Control Disable hDlg, %ID_Button_07

Case 4110015600
Control Enable hDlg, %ID_Button_08
Sleep 500
Control Disable hDlg, %ID_Button_08

'JoySticks below here
Case 210165408
Control Enable hDlg, %ID_Button_12
Sleep 500
Control Disable hDlg, %ID_Button_12

Case 210221408
Control Enable hDlg, %ID_Button_13
Sleep 500
Control Disable hDlg, %ID_Button_13

Case 211625408
Control Enable hDlg, %ID_Button_14
Sleep 500
Control Disable hDlg, %ID_Button_14

Case 211065408
Control Enable hDlg, %ID_Button_15
Sleep 500
Control Disable hDlg, %ID_Button_15

Case 88000000
Control Enable hDlg, %ID_Button_16
Sleep 500
Control Disable hDlg, %ID_Button_16

Case 2417312192
Control Enable hDlg, %ID_Button_17
Sleep 500
Control Disable hDlg, %ID_Button_17

Case 2416752192
Control Enable hDlg, %ID_Button_18
Sleep 500
Control Disable hDlg, %ID_Button_18

Case 2415753192
Control Enable hDlg, %ID_Button_19
Sleep 500
Control Disable hDlg, %ID_Button_19

Case 2415753752
Control Enable hDlg, %ID_Button_20
Sleep 500
Control Disable hDlg, %ID_Button_20

Case 1012000000
Control Enable hDlg, %ID_Button_21
Sleep 500
Control Disable hDlg, %ID_Button_21

'Case 4110015600
' Control Enable hDlg, %ID_Button_08
' Sleep 500
' Control Disable hDlg, %ID_Button_08


End Select

End Function


'You Have Reach the Bottom, there is no other place to go other than UP!


Thanks a bunch for the help, and again, I'm sure I'm not done

Wayne

oldpapa49
03-01-2013, 22:25
Well, I have basically finish the program and thanks for the help on this.. I needed to dig into the Geometric type TSO to find why the buttons and joysticks did not return any code when pressed or activated. Well I needed to place voltage on a pin that I labeled as security (Security signal is used to create 2 signals during an x-ray or operation on the x-ray side. 1 signal for the closure of the switch and a signal to say it passes security). The Image TSO which I started with did not require this security for it only operates function that are not x-ray related.

Once I put +12v on this pin, all GEOMetric switches and joysticks started to show code.

And I have learn that case can test a variable value (the joysticks use Hall effects IC for position) as well a set of either or..

I like to know on how to clear the screen of enabled buttons. Like a reset screen.

I have a call routine that does each and every %ID_Button_XX XX = 01 to 40+ Depends on the TSO

Can a for/next be used. I have tried but it seems to fail.. is the %ID_Button_ a special item. If not, I just list them all in the call..

These are all on the newer thinBasic.. I did try the new feature and found some source of commands and other features.. Which helps..

Old