Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Socket Programming

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    Re: Socket Programming

    I now have a working example of what I am trying to achieve:

    Code:
    dim bs as p
    dim bsOutput as c
    dim ModeS as c
    dim Tickbox as c
    tbl = table.open("logging")
    idx = tbl.index_primary_put("ModeS")
    bs = sockets.open("127.0.0.1",30003,"C")
    FOR i = 1 TO 2000
    statusbar.set_text("Working - "+str(i))
    bsOutput = bs.readline()
    IF left(bsOutput,3) = "AIR" THEN
        ModeS = substr(bsOutput,at(",",bsOutput,4)+1,6)
        rec = tbl.fetch_find(ModeS)
        IF rec > 0 THEN
           tbl.fetch_goto(rec)
    	    IF isnotblank("tbl.as") THEN
                    tickbox = "Seen"
    	    ELSE
    	        tickbox = "Need"
    	    END IF
    	ui_msg_box("Socket Testing","Mode_S = " + tbl.modes + " = " + tbl.reg + tickbox)
        END IF
    END IF
    NEXT I
    bs.close()
    my questions are:

    1) How do I get this to work continuously and how would I then stop the script when needed?

    1a) Is there better code to use for this that might speed it up time wise? [Added later]

    2) Is there a way of running this in the background so I can still use A5V7 for other work?

    3) How can I get a dynamic listing displayed as in the msg_box above without having to click "OK" each time?

    thanks in anticipation
    Last edited by Graham Wickens; 01-03-2007, 06:44 AM. Reason: Add another question
    --
    Support your local Search and Rescue Unit, Get Lost!

    www.westrowops.co.uk

    Comment


      #17
      Re: Socket Programming

      my questions are:

      1) How do I get this to work continuously and how would I then stop the script when needed?
      Put it in a thread and let it run.

      1a) Is there better code to use for this that might speed it up time wise? [Added later]
      Where is the pain?

      ) Is there a way of running this in the background so I can still use A5V7 for other work?
      You could use this code in a thread. I have an example with Named Pipes and the Help "Thread Example".

      3) How can I get a dynamic listing displayed as in the msg_box above without having to click "OK" each time?
      With a timer and a listbox. The timer does start some refresh code. You can find the ietimer.cab here. Download it, double click on ietimer.cab. Select both files, right click and chose extract.

      thanks in anticipation
      You're welcome.
      Last edited by Marcel Kollenaar; 01-03-2007, 11:24 AM.
      Marcel

      I hear and I forget. I see and I remember. I do and I understand.
      ---- Confusius ----

      Comment


        #18
        Re: Socket Programming

        Thanks for that, it will keep me quiet for a couple of days until I work out what is going on

        OK I've got the cab file, where is the best folder to extract the two files to?
        --
        Support your local Search and Rescue Unit, Get Lost!

        www.westrowops.co.uk

        Comment


          #19
          Re: Socket Programming

          Hi Marcel,

          Now I have had time to read your suggestions, it would appear that I am way out of my depth with this stuff (ie all new to me), so standby for some more dumb questions over the coming weeks until I have it mastered. :(
          --
          Support your local Search and Rescue Unit, Get Lost!

          www.westrowops.co.uk

          Comment


            #20
            Re: Socket Programming

            Graham,

            The thread example: Don't try to understand what it does in detail but just look how the thread function is used and embedded in the code.

            The help files show a smaller and more simple example. Put these two together and chose the best.

            Now, when I this write, I rember that there is also another background function. Have to look it up. That starts a function in the background maybe that is easyer.

            The ietimer cab.
            Put the ietimer.ocx in the \windows\system32\ folder and register it with:

            regsvr32.exe ietimer.ocx

            Then use it as an ActiveX control.

            Example database with ietimer.ocx
            Last edited by Marcel Kollenaar; 01-03-2007, 04:55 PM.
            Marcel

            I hear and I forget. I see and I remember. I do and I understand.
            ---- Confusius ----

            Comment


              #21
              Re: Socket Programming

              I looked up the background function I mentioned above but it has to do with FTP_SCRIPT_RUN_SILENT(). So, this won't help you.
              Marcel

              I hear and I forget. I see and I remember. I do and I understand.
              ---- Confusius ----

              Comment


                #22
                Re: Socket Programming

                I've got a thread running AND a script to stop it. At the moment it writes to a text file, as I don't know what to do about displaying the lookup data.
                Code:
                thread_create("SBS_monitor",<<%code%
                xbasic_error_log("d:"+chr(92)+"My Databases"+chr(92)+"SBS"+chr(92)+"txt"+chr(92)+"thread_error_log.txt")
                dim thread_run_flag as l = .t.
                dim bs as p = sockets.open("127.0.0.1",30003,"C")
                dim bsOutput as c = ""
                dim ModeS as c = ""
                dim rec as c = ""
                tbl = table.open("logging")
                idx = tbl.index_primary_put("ModeS")
                tim  = remspecial(time())
                ftim = substr(tim,1,2)-"-"-substr(tim,3,2)-"-"-substr(tim,5,2)
                dim path as c = "d:"+chr(92)+"My Databases"+chr(92)+"SBS"+chr(92)+"txt"+chr(92)
                old_dir = dir_get()
                dir_put(path)
                sbsfile = file.create("SBS_Log"+ut(ftim)+".txt",file_rw_shared)
                while thread_run_flag
                bsOutput = bs.readline()
                	IF left(bsOutput,3) = "AIR" THEN
                		rec = tbl.fetch_find(substr(bsOutput,at(",",bsOutput,4)+1,6))
                		sbsfile.write_line(tbl.modes + " = " + ut(tbl.reg)+ " ["+ut(tbl.icaotypecode)+"] " + if(isnotblank("tbl.as"),"Seen","Need"))
                	end if
                end while
                sbsfile.close()
                bs.close()
                tbl.close()
                dir_put(old_dir)
                end
                %code%)
                --
                Support your local Search and Rescue Unit, Get Lost!

                www.westrowops.co.uk

                Comment


                  #23
                  Re: Socket Programming

                  As far my information is correct the code wil only run once in the thread. You must put it in a loop:

                  Code:
                  thread_create("T2", <<%code%
                  
                  dim proces_thread as L = .T.
                  
                  XBASIC_ERROR_LOG("c:\\Thread_t2.log") ' If something goes wrong you will find it here.
                  
                  while proces_thread
                      'Do something.........
                      sleep(1) '
                  end while
                  
                  %code%, p)
                  Lookup data:
                  Yes, you are right. In threads it is impossible to access the screen. The thread must collect the data and something outside the thread must must periodically show the data the thread provides.

                  Shame on me I forgot this disadvantage.

                  But, if the thread can drop a flag by the name_space pointer (parameter 3) of the THREAD_CREATE() function if there is new information an outside timer proces can detect the change and show the data.

                  Just an idea! :)
                  Last edited by Marcel Kollenaar; 01-03-2007, 08:59 PM. Reason: Add some extra thread info...
                  Marcel

                  I hear and I forget. I see and I remember. I do and I understand.
                  ---- Confusius ----

                  Comment


                    #24
                    Re: Socket Programming

                    Marcel/Graham,

                    I know nothing about threads but am just following this thread(pardon the pun) for interest sake. So I had a look in the help about the subject and came across the Thread_Variables() function which says
                    The THREAD_VARIABLES() function returns a pointer to all of the variables of a specific thread. This can be used to peek at what a background thread is doing or to set variables within that thread.
                    There is an example of its use in the Thread_Create() help page
                    thread_create("mythread", <<%code%
                    while flag_run
                    ' do a bunch of stuff
                    end while
                    %code%)
                    Then when you want to stop the thread, you can do the following from another script, the interactive window, etc:
                    tv = thread_variables("mythread")
                    tv.flag_run = .f.
                    delete tv
                    You could have a second timed script as Marcel suggested possibly access the data through this function.
                    Last edited by Tim Kiebert; 01-03-2007, 09:51 PM.
                    Tim Kiebert
                    Eagle Creek Citrus
                    A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

                    Comment


                      #25
                      Re: Socket Programming

                      Thanks Marcel/Tim,

                      Tim's example is how I am stopping the thread. Today, I'm going to have a go at the timer option.

                      1) Presumably I create a form with the timer script on it?

                      2) How do I then access the open file being created by the thread, as It would grow to be quite big by the end of the day and I only need to display the new entries each time I list the file.

                      3) Is an ordinary text file the way to do this or would it be better to write to a table or an array?

                      thanks in anticipation
                      Last edited by Graham Wickens; 01-04-2007, 05:49 AM. Reason: correct spelling
                      --
                      Support your local Search and Rescue Unit, Get Lost!

                      www.westrowops.co.uk

                      Comment


                        #26
                        Re: Socket Programming

                        You could try having your thread code write the same info to two files. Have your timed script read the second file and once read clear it. That way you will have one file with all of the day's data and a second with only the data since the last read by the timed script.
                        Tim Kiebert
                        Eagle Creek Citrus
                        A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

                        Comment


                          #27
                          Re: Socket Programming

                          Thats a good idea, I have just hit a problem, I changed the thread to write to a table instead of a text file, which works fine, then I designed a form with the start/stop buttons with an embedded browse, this worked with a manual F5 refresh. I have not started on the timer yet as I wanted to get the process clear in my mind.
                          Of course now I have to stop/start the Form every time I want to do other stuff in A5. I really wanted this display to be permanently on view.
                          If I put this Thread and associated forms and tables into its own A5 Database and started an A5 session with just the thread running, would I then be able to run another session to do other database work as I don't see any clash database wise?

                          Going back to the form to display data from the thread, I thought that if everytime the timer did a refresh, I could position the view -10 records say from the last record currently on view, would that work?
                          --
                          Support your local Search and Rescue Unit, Get Lost!

                          www.westrowops.co.uk

                          Comment


                            #28
                            Re: Socket Programming

                            Graham,
                            Rather than go to the trouble of starting a full thread, you can use a ui_modeless_dlg_box() with a {timer} interval and a ui_modeless_dlg_refresh(). You put the code to check the USB device in the section
                            if a_dlg_button="timer"
                            ' read the USB device
                            ' display the values in a multi-line listbox in the Xdialog
                            end if

                            and that should allow you to keep working in a5v7 while this modeless dlg is up. At least, I think it should work -- I haven't tried it!

                            Comment


                              #29
                              Re: Socket Programming

                              :) Thanks Peter,

                              I was just about to ask that question myself as my pc did not like the IEtimer, I did a search on "Timer" in Alpha Help and that gave me the suggestion.

                              Will I be able to add stop/start thread buttons to a modeless dialog box?
                              --
                              Support your local Search and Rescue Unit, Get Lost!

                              www.westrowops.co.uk

                              Comment


                                #30
                                Re: Socket Programming

                                Peter, good idea! It is worth trying that way. Never thought of using the modeless dlg version.
                                Marcel

                                I hear and I forget. I see and I remember. I do and I understand.
                                ---- Confusius ----

                                Comment

                                Working...
                                X