• 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 /
  • Help Room /
avatar image
0
Question by MKyun · Jun 06, 2017 at 06:50 AM · serialport

Unity Connect Serial Port. Help me please.

I want to know how to connect SerialPort in Unity.

I Need Help me Please.

I upload the code I created.

 using UnityEngine;
 using System.Collections;
 using System.IO.Ports;
 using System.Text;
 
 public class PortFor : MonoBehaviour
 {
     private SerialPort sp;
 
     private string Path;
     private string text;
 
     void Start()
     {
         Path = Application.streamingAssetsPath + "/Text/Log.txt";
 
         text = "Unity Start!\r\n\r\n";
         System.IO.File.AppendAllText(Path, text, Encoding.Default);
 
         sp = new SerialPort("COM255", 9600, Parity.None, 8, StopBits.One);
         sp.Open();
 
         if (sp.IsOpen)
         {
             text = "Serial port is open!\r\n\r\n";
             System.IO.File.AppendAllText(Path, text, Encoding.Default);
         }
 
         sp.ReadTimeout = 10000;
     }
 
     private void OnApplicationQuit()
     {
         sp.Close();
     }
 
     void FixedUpdate()
     {
 
 
         if (sp.IsOpen)
         {
             string tempS = sp.ReadLine();
 
             text = "SerialData : " + tempS + "\r\n\r\n";
             System.IO.File.AppendAllText(Path, text, Encoding.Default);
         }
     }
 }
Comment
Add comment · Show 1
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 MKyun · Jun 06, 2017 at 08:06 AM 0
Share

Error Contents

 IOException: The port `CO$$anonymous$$255' does not exist.
 System.IO.Ports.WinSerialStream.ReportIOError (System.String optional_arg)
 System.IO.Ports.WinSerialStream..ctor (System.String port_name, Int32 baud_rate, Int32 data_bits, Parity parity, StopBits sb, Boolean dtr_enable, Boolean rts_enable, Handshake hs, Int32 read_timeout, Int32 write_timeout, Int32 read_buffer_size, Int32 write_buffer_size)
 (wrapper remoting-invoke-with-check) System.IO.Ports.WinSerialStream:.ctor (string,int,int,System.IO.Ports.Parity,System.IO.Ports.StopBits,bool,bool,System.IO.Ports.Handshake,int,int,int,int)
 System.IO.Ports.SerialPort.Open ()
 (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPort:Open ()
 PortFor.Start () (at Assets/PortFor.cs:21)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by josiperez · Jan 04, 2018 at 08:17 PM

Here https://answers.unity.com/questions/1092655/serial-port-on-unity-1.html

they comment about the strange syntax to use in ports greater than 9

 sp = new SerialPort ( "\\\\.\\COM58", 115200) ;

and the advice to use .NET 2.0 (not subset) Config is into Edit>ProjectSettings>Player>ApiCompatibilityLevel

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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

107 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Read Arduino Stream with Js or C# 0 Answers

Unity / Arduino wifi communication for multiwii serial protocol 0 Answers

send string to serial port on android 0 Answers

Sending Data from Arduino Uno to Unity 5 Answers

HELP: Arduino Genuino 101 to Unity3D. Serial Communication 0 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