Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: I'm Back!

  1. #1

    I'm Back!

    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..

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    6,839
    Blog Entries
    3
    Rep Power
    697
    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
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 7 64bit - Intel Core 2 Duo T6600 @ 2.2GHz - 4 GB RAM - NVIDIA GeForce G210M 512MB
    Windows 8 64bit - Intel Core i5-3350P @ 3.1GHz - 8 GB RAM - NVIDIA GeForce GT640 3GB

  3. #3
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    51
    Posts
    8,343
    Blog Entries
    2
    Rep Power
    10
    Console_WriteLine is also aliased by PrintL
    Much less typing
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  4. #4
    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!
    
    Last edited by oldpapa49; 17-10-2012 at 22:03.

  5. #5
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Blog Entries
    1
    Rep Power
    154

    Lightbulb

    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.
    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

  6. #6
    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..

  7. #7
    Quote Originally Posted by Petr Schreiber View Post
    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

  8. #8
    Quote Originally Posted by Michael Clease View Post
    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

  9. #9
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    6,839
    Blog Entries
    3
    Rep Power
    697
    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
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 7 64bit - Intel Core 2 Duo T6600 @ 2.2GHz - 4 GB RAM - NVIDIA GeForce G210M 512MB
    Windows 8 64bit - Intel Core i5-3350P @ 3.1GHz - 8 GB RAM - NVIDIA GeForce GT640 3GB

  10. #10
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Blog Entries
    1
    Rep Power
    154
    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
    
    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

Page 1 of 2 12 LastLast

Similar Threads

  1. I am back!
    By plamen in forum Shout Box Area
    Replies: 1
    Last Post: 21-11-2010, 11:37
  2. Back
    By ErosOlmi in forum Shout Box Area
    Replies: 3
    Last Post: 26-11-2007, 21:59
  3. We are back
    By ErosOlmi in forum thinBasic General
    Replies: 27
    Last Post: 17-04-2007, 23:15
  4. Back to work
    By ErosOlmi in forum Shout Box Area
    Replies: 1
    Last Post: 04-01-2007, 21:27
  5. Back from holidays
    By ErosOlmi in forum General
    Replies: 0
    Last Post: 20-08-2006, 11:48

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •