Hi Anton_S
Thank you, so this is the piece of code i have now... wich includes a messagebox to ask the COM port and exit if CANCEL is pressed.
The code is lumped together with some examples found here and there, so if there are any tweaks let me know!
sp su15 serial recieve example.png
# DomoticX Virtual 3D Device Port SU15 interface. # Wat moet er gebeuren bij het starten van de simulatie? onstart{ options = ["Serial Port;", "Baudrate;"] default = ["COM8", "9600"] list = ["", "4800|9600|14400|19200|28800|38400|57600|115200"] serialsettings = UI.inputbox(options, default, list, "Serial port settings;") if serialsettings != FALSE $comport = serialsettings[0] $baudrate = serialsettings[1].to_i begin @serial = Serial.new($comport, $baudrate) rescue RubySerial;;Exception => e @serial.close if @serial MSketchyPhysics3;;SketchyPhysicsClient.physicsReset UI.messagebox("Serial port not found!") end else MSketchyPhysics3;;SketchyPhysicsClient.physicsReset end } # Wat moet er gebeuren tijdens de simulatie? ontick{ MSketchyPhysics3.closeControlPanel if frame == 1 string_size = 1024 $serialdata = eval(@serial.read(string_size)) logLine("COM poort; " + $comport.to_s) logLine("BAUD rate; " + $baudrate.to_s) logLine("Seriele data; " + $serialdata.to_s) logLine("") logLine("") logLine("") logLine("") logLine("") } # Wat moet er gebeuren als de de simulatie stopt? onend{ # Sluit de seriele poort als deze open staat. @serial.close if @serial }Ps. The simulation works fine... but sometimes when i STOP and START the simulation again i get this error, when i start it for the second time it works perfectly again, any ideas to prevent this?
sp su15 serial recieve error.png