Grasshopper

algorithmic modeling for Rhino

Hi Everyone-

About a year ago I started playing around with serial port programming using the GHPython component. Here's the old thread:

http://www.grasshopper3d.com/forum/topics/serial-port-programming-i...

For the most part, I got the serial port to work and I could share the port with other components without wiring the components together using a sticky Python dictionary. There were a couple of issues with closing the port (Rhino had to be restarted). 

In any case, I'm back at it. I am however going the C# component route with an eye towards writing my own components with visual studio. I am trying to create bidirectional communication with a serial device in grasshopper. I need more control over the serial port that the generic Firefly components can afford. Furthermore, I would like to understand how to program this myself. The first goal would be to create a few components that could handle various serial tasks, one to open/close port, one to read from port and one to write to it. This is not unlike how I got it to work in python, and is also similar to the logic in Firefly's serial components.

The thing that has me stumped with C# is how one shares the port between components? If one component is responsible for creating and opening/closing the port, how do the read/write components address the instance of the port created in the other component? Python has the sticky dictionary, is there something similar in C#? I'm a novice when it comes to C# and how it works within grasshopper, so maybe I'm missing something simple.

I've attached a klunky definition that uses C# to open/close a serial port. I've tried accessing the port with other components, but I don't know enough to make it work. Again, I'm mainly interested in the mechanics of how one component can access the serial port instance created in another component.  If I could get some user objects going for now, I'd be happy. In the future, I want to roll my own components. If anyone has any suggestions, code snippets, or any other forms of enlightenment, I'd be greatly appreciative!

Rhino5 x64 + GH version 0.9.0056

Thanks,

~BB~

 

Views: 3129

Attachments:

Replies to This Discussion

So I threw my back into it and decided to make some custom components with Visual Studio Express 2010 following the directions in the Grasshopper SDK. I have to admit I've been avoiding doing this for fear that it would be too hard, but I was pleasantly surprised. Not that bad, even for a C# novice. I am attaching the *.cs files for three components:

SerialCreate component creates the serial port instance. This component controls port parameters and opens/closes the port. (It won't close the port, however.) SerialWrite and Read try to interact with the port created by SerialCreate. I can verify that the port opens because it's unavailable to other terminal applications, but if I try to close the port, it won't...it stays open until I restart Rhino. SerialWrite works, because I can see the rx light on my device light up when I enter text in grasshopper. SerialRead does not work. I blue screen with a DPC WATCHDOG VIOLATION. 

All in all, not too bad for a day's work. I'll forget the user objects and go for custom components. The question that still remains is that I don't think I'm correctly or efficiently sharing the serial port instance with the other classes. Again, this is just a hack, but I'm happy I'm closer to solving the problem (or so it seems). If anyone has any ideas about how to better go about this, I'd appreciate any suggestions.

Thanks again,

~BB~

Attachments:

Hi

I have just found your post.  When I try to run the gh file that you attached, it works except the last c# component where it is trying to read from the serial port.  It gives me the following error message

            {0;0}
0. Error (CS1061): 'object' does not contain a definition for 'ReadChar' and no extension method 'ReadChar' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?) (line 75)

Can you enlighten me as to what could be the error.  Admittedly I do not have anything connected to the port.  Is this possibly the reason why?

Regards

William

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service