sketchucation logo sketchucation
    • Login
    1. Home
    2. Bas9999
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info
    B
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 3
    • Posts 20
    • Groups 1

    Bas9999

    @Bas9999

    10
    Reputation
    1
    Profile views
    20
    Posts
    0
    Followers
    0
    Following
    Joined
    Last Online

    Bas9999 Unfollow Follow
    registered-users

    Latest posts made by Bas9999

    • RE: MSPhysics 1.0.3 (16 October 2017)

      Well i have found earlier versions around on the internet and i am confused with the version numbering because it already passed v1.0.0 @ 2014-09-01..... πŸ˜‰

      MSPhysics - v0.1.0 (2014-04-26)
      MSPhysics - v0.2.0 (2014-06-26)
      MSPhysics - v0.2.0 (2015-04-06) ???
      MSPhysics - v1.0.0 (2014-09-01)

      posted in Plugins
      B
      Bas9999
    • RE: Write to serial port with Ruby [SOLVED!]

      Hi Anton_S

      *EDIT SOLVED!!! SEE BELOW

      Could you assist on this one?

      When for example i use a diffrent baudrate (on purpose) i still get this error:
      sp su15 serial recieve error baudrate.png

      The original code was:

      ontick{
        MSketchyPhysics3.closeControlPanel if frame == 1
        string_size = 1024
        $serialdata = eval(@serial.read(string_size))
      }
      

      I changed it to this, but that doesn't work:

      ontick{
        MSketchyPhysics3.closeControlPanel if frame == 1
        string_size = 1024
      
        begin
          $serialdata = eval(@serial.read(string_size))
        rescue RubySerial;;Exception => e
          @serial.close if @serial
          MSketchyPhysics3;;SketchyPhysicsClient.physicsReset
          UI.messagebox("ERROR!")
        end
      }
      

      How to catch this error?

      *EDIT SOLVED!!!
      I just changed the line to:

      $serialdata = @serial.read(string_size)
      

      so it's only:

      ontick{
        MSketchyPhysics3.closeControlPanel if frame == 1
        $serialdata = eval(@serial.read(1024))
      }
      
      posted in SketchyPhysics
      B
      Bas9999
    • RE: Stop simulation immediatly / End script!

      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

      posted in SketchyPhysics
      B
      Bas9999
    • RE: SketchyPhysics 3.5.6 (26 January 2015)

      Ahem...

      Should "SketchyPhysics 3.5.6 (January 26, 2014)"
      not be "SketchyPhysics 3.5.6 (January 26, 2015)"?

      πŸ˜’

      posted in SketchyPhysics
      B
      Bas9999
    • Stop simulation immediatly / End script!

      I wanted to implement a better error handler for the script here: http://sketchucation.com/forums/viewtopic.php?f=61%26amp;t=61033

      What i did was to bring up the error on purpose, to let SketchyPhysics open a COM port that does not exist with

      @serial = Serial.new('COM7', 9600)
      

      Gives:
      sketchyphysics COM port - file not found error.png

      Hey look... it sees the COM port as a file...NEAT!, so i looked up some code, where you can check if a file exists:

      File.exist?('file.ext')
      

      Gives Boolean True or False as return

      So, a COM port can also be checked if it exists with:

      File.exist?('COM7')
      

      So i put this line together:

      @serial = Serial.new('COM7', 9600) if File.exist?('COM7')
      

      Now...when runing the simulation and the COM port is not found the simulation just starts and gives the error:
      sketchyphysics COM port - file not found error 02.png

      Ok, so we need to STOP the script immediatly, so i looked up how to stop a script from another example, i came up with this line:

      MSketchyPhysics3;;SketchyPhysicsClient.physicsReset
      

      Now putting it all together and include a nice messagebox, this is the part i have now:

      onstart{
        if File.exist?('COM7')
          @serial = Serial.new('COM7', 9600)
        else
          UI.messagebox('Serial Port not found!')
          MSketchyPhysics3;;SketchyPhysicsClient.physicsReset
        end
      }
      

      But what happens now is, that we get the message the COM port is not found that is ok, but right after that, another error pops up, SketchyPychics still executes the function: ONEND!!

      onend{
        @serial.close
      }
      

      sketchyphysics COM port - file not found error 03.png

      So my question is: How to abort the script/simulation immediatly?

      *EDIT

      I could do this:

      onend{
        @serial.close if File.exist?('COM7')
      }
      

      but's not charming to implement the check everytime...

      posted in SketchyPhysics
      B
      Bas9999
    • RE: Disable control panel popup

      @anton_s said:

      Although it still has to be in onUpdate or onTick event.
      So your one liner would look like this:
      onUpdate { MSketchyPhysics3.closeControlPanel if frame == 1 }

      πŸ‘ 🀣

      posted in SketchyPhysics
      B
      Bas9999
    • RE: Write to serial port with Ruby [SOLVED!]

      Hi All,

      This is an example how to SEND data to the Arduino with SU 14/15, SketchyPhysics and Ruby Serial

      First the Arduino programming, here is the code to lit the integrated LED on digital 13, when there is a serial "1" recieved, the LED goes out when there is a "0" recieved.

      Arduino code:

      String readString;
      
      void setup() {
        pinMode(13, OUTPUT);
        Serial.begin(9600);
      }
       
      void loop() {
        while (Serial.available()) {
          delay(3);
          if (Serial.available() >0) {
            char c = Serial.read();
            readString += c;
          } 
        }
       
        if (readString.length() >0) {
          if (readString == "1") { digitalWrite(13, HIGH); }
          if (readString == "0") { digitalWrite(13, LOW); }
          readString = "";
        } 
      }
      

      Now...once programmed, create a sketchyphysics solid and paste this code in it:

      onstart{
        @serial = Serial.new('COM8', 9600)
      }
      
      onclick{
        @m = Sketchup.active_model.materials.add "My material"
        group.material = @m
        @m.color="Yellow"
      
        logLine("LED ON!")
        @serial.write('1')
      }
      
      onunclick{
        @m = Sketchup.active_model.materials.add "My material"
        group.material = @m
        @m.color="White"
      
        logLine("LED OFF!")
        @serial.write('0')
      }
      
      ontick{
        MSketchyPhysics3.closeControlPanel if frame == 1
      }
      
      onend{
        @serial.close
      }
      

      How does this work?
      When you run the script and click on the solid, the color will change to yellow and over the serial port a "1" will be send, de Arduino will recieve this "1" and will put on the LED light, when you release the mouse button, the model changes color back to white and a "0" will be sent, the Arduino recieves this and will put the LED light out!

      Have fun!

      Ps. Is there any code to read out a textbox or something (userinput possible?), where the user can specify the COMPORT and BAUDRATE?

      SU_14_15_Ruby Serial Sketchup Sketchyphysics screen.jpg

      I think i will start to create the 204/2015 walktrough soon!, this will be the banner for the
      projects:
      SketchyPhysics serial banner.jpg


      SU_14_15 - Ruby Serial SEND Example with Sketchup Sketchyphysics.skp

      posted in SketchyPhysics
      B
      Bas9999
    • RE: Write to serial port with Ruby [SOLVED!]

      @mptak said:

      I see you tested it with SU2015...this confuses me. Were you using the 64 bit version of sketchup? Which Sketchy Physics download did you use? Thanks.

      No, i used the 32-bit version of SU2015, sketchyphysics does not work on 64-bit (yet)

      posted in SketchyPhysics
      B
      Bas9999
    • RE: Write to serial port with Ruby [SOLVED!]

      Hello Anton_S

      I've tested it with Sketchup 2015... 😍 , it works like a charm!

      This is the code to read data for the serial port so far...

      onstart{
        @serial = Serial.new('COM8', 9600)
      }
       
      ontick{
        MSketchyPhysics3.closeControlPanel if frame == 1
        $serialdata = eval(@serial.read(1024))
        logLine("Serial data; " + $serialdata.to_s)
        logLine("")
        logLine("")
        logLine("")
        logLine("")
        logLine("")
        logLine("")
      }
      
      onend{
        @serial.close
      }
      

      Thank you!, i see if i can make a script that SENDS data to the Arduino / Raspberry...

      posted in SketchyPhysics
      B
      Bas9999
    • RE: Disable control panel popup

      Or just 1 line πŸ˜‰

      MSketchyPhysics3.closeControlPanel if frame == 1
      
      posted in SketchyPhysics
      B
      Bas9999