![]() |
LDCommPort - Printable Version +- Small Basic Forum (https://litdev.uk/mybb) +-- Forum: Small Basic (https://litdev.uk/mybb/forumdisplay.php?fid=1) +--- Forum: Extensions (https://litdev.uk/mybb/forumdisplay.php?fid=3) +--- Thread: LDCommPort (/showthread.php?tid=423) |
LDCommPort - Eddie - 07-13-2025 Hallo zusammen, ich versuche gerade, mit SB eine Steuerung für meine Modelleisenbahn zu schreiben. Dabei bin ich auf ein Problem gestoßen, das ich nicht lösen kann. Ich habe folgenden Code zur Steuerung der Lokomotiven erstellt. lokAdresseTB = Controls.AddTextBox(20,930) Controls.SetTextBoxText(lokAdresseTB, "3") lokSlider = LDControls.AddSlider(150.930.200) LDControls.SetSliderRange(lokSlider,0,126) LDControls.SetSliderValue(lokSlider,0) LokVorBTN = Controls.AddButton("▶️ Vorwärts",380,930) LokZurBTN = Controls.AddButton("◀️ Rückwärts",450,930) LokStopBTN = Controls.AddButton("⏹️ Halt",520,930) Sub-LokSteuerung adresse = Controls.GetTextBoxText(lokAdresseTB) geschw = LDControls.GetSliderValue(lokSlider) Wenn Controls.LastClickedButton = LokVorBTN, dann LDCommPort.TXString("<t " + adresse + geschw +"1 ">") EndIf Wenn Controls.LastClickedButton = LokZurBTN, dann LDCommPort.TXString("<t " + adresse + geschw + "0 ">") EndIf Wenn Controls.LastClickedButton = LokStopBTN, dann LDCommPort.TXString("<t " + adresse + " 1 0>") EndIf EndSub Das Problem liegt in dieser Zeile: LDCommPort.TXString("<t " + address + speed +"1 ">"). Hier behauptet SB, ich hätte drei Argumente angegeben, obwohl nur eines benötigt wird. Hat jemand eine Idee, wie man das anders schreiben könnte? Der Befehl, der an die DCC-EX-Zentrale gesendet werden muss, sieht folgendermaßen aus: <t 3 50 1> Das t steht für die anzusprechende Lokomotive; die 3 ist die DCC-Adresse, die 50 die Geschwindigkeit und die 1 die Richtung. Viele Grüße, Eddie RE: LDCommPort - litdev - 07-13-2025 Hi Eddie, Looking just at the command LDCommPort.TXString("<t " + address + speed +"1 ">") as the rest appears to be using language aliases (share using Publish converts to standard SB without aliases). TXString requires a single string, the following compiles with the string output for testing: Code: adresse = 3 Maybe it is simply the extra " you have. RE: LDCommPort - Eddie - 07-13-2025 Es liegt wohl nicht am " . Wenn ich nur " an den Anfang und das Ende des Strings setze, wie es sein sollte, dann werden die Variablen 'adress' und 'geschw' wie alles andere in " " gelb und haben dann keine Wirkung mehr. RE: LDCommPort - litdev - 07-13-2025 Did you try it the way I showed, which creates a string concatenation of constants (in " ") and variables. If you still have issues, then please post the full code using Publish so we can try compiling it without manually changing keywords. For example try importing the following LDCommPort test sample program JTCF968.000 RE: LDCommPort - Eddie - 07-13-2025 Ich habe den Code unter FXDZ308.000 veröffentlicht. Das Programm startet nun, aber der String wird nicht wie vorgesehen gesendet. RE: LDCommPort - litdev - 07-13-2025 OK, so it compiles, next is to do the simplest test (probably would have done that first). I don't have your hardware obviously, but I would start with something as simple as possible that should test the connection. Code: result = LDCommPort.AvailablePorts() If this does work, then put TextWindow.WriteLine debug statements in your code to debug further. If this doesn't work, then check the port, baudrate command and documentation (parity etc) for the hardware, and any return error messages. RE: LDCommPort - Scout - 07-13-2025 Hi Eddie, I don't know if your DCC-EX central unit is an Arduino application or some other hardware. The following COM checker should be able to find the Arduino. If COM5 won't open, another program might have reserved it, so close it first. I don't know if CR and LF are necessary, so maybe comment them out. Code: ArduinoCommand = "<s>" RE: LDCommPort - AbsoluteBeginner - 07-13-2025 (07-13-2025, 12:21 PM)Eddie Wrote: Ich habe den Code unter FXDZ308.000 veröffentlicht. Das Programm startet nun, aber der String wird nicht wie vorgesehen gesendet. (translated by Google translator) Hi, Eddie ![]() You write: LDCommPort.TXString("<t "+ adresse + geschw +" 1 >") If the program executes this code of yours, it will create a message like this: <t adressegeschw 1 > Is this the message you want to send? If I understand correctly, each command in the message should be separated by a space. For example like this: <t adresse geschw 1> But, for this, your line of code should look like this: LDCommPort.TXString("<t "+ adresse + " " + geschw +" 1>") ![]() RE: LDCommPort - Eddie - 07-14-2025 Hello, I found the error. It was due to the slider output, e.g., 30.12345667. These many decimal places prevented the string from being sent or further processed in the DCC-EX central unit. I've rounded it now, and it works. Thanks for your answers. Regards, Eddie |