Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Eddie · Aug 07, 2010 at 07:30 AM · c++serialport

Receiving information from a serial port

I'm new to Unity3D, in fact just today. I'm doing a project that requires input from a device that sends data to a computer via a serial port. Is there a way to program Unity in C/C++ to be able to open a serial port and receive data streamed from it?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

7 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by Magnus Wolffelt · Aug 07, 2010 at 09:39 AM

Shouldn't need a plugin, at least not with Unity 3.0:

"Then along comes .Net 2.0, and this time Microsoft added the System.IO.Ports Namespace, and within that was the SerialPort Class. DotNet developers finally had an intrinsic way of serial port communication,"

http://msdn.microsoft.com/en-us/library/system.io.ports.aspx

Also, be sure to set API compatibility level to .NET 2.0. The default is something like .NET 2.0 reduced.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DaveA · Apr 10, 2011 at 04:53 AM 0
Share

Have you actually tried this? In my tests, I get nothing but exceptions, if I'm lucky it doesn't hang. The Read functions all fail, and simply having ReadLine compiled in causes it to hang. I've read elsewhere the fault is with $$anonymous$$ono.

avatar image DaveA · May 08, 2011 at 06:14 AM 2
Share

Ah, finally got it working, thanks! ReadLine blocks the thread, so using a short timeout and alternate thread helps

avatar image
3

Answer by Rasmus Schlnsen · Sep 26, 2010 at 06:33 PM

I've just did a blogpost on communicating with an Arduino device using System.IO.Ports.SerialPort class. Basically you create an instance of the SerialPort class in Start() specifying the COM port and baud rate, and then in Update your extract data.

If you're interested you can find the post here

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DaveA · Apr 10, 2011 at 04:52 AM 0
Share

I was not able to get this working, does it still work in 3.3?

avatar image andy78flavia28 · Jun 25, 2015 at 12:28 PM 1
Share

Can you repost your blogspot, please?

avatar image
-1

Answer by Eric5h5 · Aug 07, 2010 at 07:32 AM

You'd need to write a plugin for that (requires Unity Pro).

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Eddie · Aug 07, 2010 at 07:43 AM 0
Share

Great! So it is possible, good to know. Thanks! Any quick pointers on where that might be in the documentation: writing a plugin.

avatar image Eric5h5 · Aug 07, 2010 at 08:11 AM 0
Share

@Eddie: http://unity3d.com/support/documentation/$$anonymous$$anual/Plugins.html

avatar image
0

Answer by David Thomas · Dec 13, 2010 at 02:05 PM

I have a PIC based controller that uses a USB virtual serial port. I've been using it with XNA and all my interface software is in C#. I'll let you know how it goes with getting it to talk with Unity. Any advice out there?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by subhash · Jun 10, 2011 at 01:11 PM

I am trying the same thing whenever I use readline . the framerate goes down to 1fps and if I try coroutine then then the data is not correct it is merged one inside the another.

Can somebody help on this Regards Subhash

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to use native C++ classes in Unity 1 Answer

Zooming out by moving camera away from target(scrollwheel) 1 Answer

DirectInput in Unity 0 Answers

Can I use c plus plus to program a game in unity? 1 Answer

IUnityEventQueue - how do I use it? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges