We would like to build a community for Small Basic programmers of any age who like to code. Everyone from total beginner to guru is welcome. Click here to register and share your programming journey!


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Question about a program
#1
Hallo, ich habe ein Programm unter der QCBN-Nummer 365.000 veröffentlicht. Das Programm soll zur Steuerung meiner Modellbahn dienen. Beim Start öffnet sich ein grafisches Fenster mit Schaltflächen und einem Gleisplan mit Linien. Alles funktioniert. Klickt man auf die grünen Kreise, bewegt sich eine Linie, die eine Weiche darstellen soll. Nun zum Problem: Stellt man die Weiche per Mausklick, ist alles in Ordnung. Der Befehl wird an die DCC-EX-Zentrale gesendet und die Weiche auf der Anlage schaltet ebenfalls. Drückt man die Schaltfläche Fahrstraße A, werden die Befehle auch korrekt gesendet. Was jedoch nicht schaltet, sind die Weichen in meinem Gleisplan. Meine Idee war, das Textfeld tb1 auszulesen. Dort wird die Rückmeldung der Zentrale angezeigt. Leider ist mir das bisher nicht gelungen. Hat jemand eine Idee?
Reply
#2
Since I don't have this train control, I bridged pins 2 and 3 on the connector.
With the following result:
       

The send strings are sent one after the other.
However, the receive string contains the total result on one line, twice.

I recommend:
- Outputting the received data in the text window
- Processing the route data line by line
    Sending a command
    Querying the result
    Updating the track plan
- Performing as few actions as possible in the event subroutines
   but rather in the main program (so it's best to only pass flags).
[-] The following 3 users Like Scout's post:
  • AbsoluteBeginner, litdev, stevantosic
Reply
#3
Since there is no solution to the problem yet, I've modified my program slightly and published it under GRVG. The last sub-code is supposed to cause a specific shape to rotate based on incoming data in textbox tb1. The data in the textbox is unique, e.g., <H 112 1>. Why isn't the shape moving? It's as if the data isn't being read at all. Can someone explain to me why this is.

Sorry, here is the complete link to the program GRVG 779.000
Reply
#4
Hi,

First there is an error on line755.

  If  = Text.IsSubText(datentb, "<H 112 1>") Then

I assume this should be without the = 

Second, without your hardware and no idea how to control the program it is hard to know, but if I alter the program to just call subroutine PrüfeRückmeldungenEinfach() with <H 112 1> in textBox tb1 then the gate near the top opens, so this bit works fine.

So, all I can suggest is to add TextWindow.WriteLine debugging, or if you are using SB-Prime, then run the program in debug mode or use the Flow Chart tool to help trace the flow of the program.

Also, Scout's suggestion about performing all actions in a main 'Game loop' controlled by flags set in events is a good one in general for interactive event driven programs - it keeps all the program activity on the main UI thread (sequential) while just using event subroutines that can run asynchronously (at the same time) to set flags used within the 'Game loop'.  This is not just a 'nice idea', it is how all interactive programs usally are written and keeps the program logic nicely confined, sequential, debuggable.  Here is a link on this:

https://learn.microsoft.com/en-us/archiv...ent-basics

Finally, I really like the look of the program, you have put a lot of work into it.
[-] The following 1 user Likes litdev's post:
  • AbsoluteBeginner
Reply
#5
Hi,

Another thought on your program

Changes made to the UI (GraphicsWIndow objects) from within event subroutines only take effect after the event subroutine has ended.  Consider the examples below.

Code:
'Main UI thread code
tb = Controls.AddTextBox(50,50)
GraphicsWindow.MouseDown = OnMouseDown
'Event Subroutines
Sub OnMouseDown
  Controls.SetTextBoxText(tb,"Hello World")
  Program.Delay(3000) 'Time consuming work
EndSub

Code:
'Main UI thread code

tb = Controls.AddTextBox(50,50)
GraphicsWindow.MouseDown = OnMouseDown

'Game loop

While ("True")
  If (clicked) Then
    Controls.SetTextBoxText(tb,"Hello World")
    Program.Delay(3000) 'Other time consuming work
    clicked = "" 'Reset handled flag
  EndIf
 
  Program.Delay (100) 'Don't mash cpu
EndWhile

'Subroutines

Sub OnMouseDown
  clicked = "True"
EndSub
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)