• 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
0
Question by Archus · Mar 16, 2017 at 09:13 AM · programmingserialport

Unity not receiving data from C++ program

I'm currently making a Unity program that able to receive data from other program that is made on C++. For the serial port controller, I use a prefab from DWilches (https://github.com/DWilches/SerialCommUnity) to read and send data for Unity side. For the C++ side, I have already try using a pre-made library for reading data from Arduino (http://playground.arduino.cc/Interfacing/CPPWindows) and using .NET Framework (System.IO and such)

The problem is that currently I can send string from the Unity side (confirmed by sending a single character) and received and read by the C++ program however when I try to send a string from the C++ program, its not triggering anything on the Unity side. For reference, I use the SampleUserPollingReadWrite from the DWilches's example. I have tried asking him and he says that his library needs a '\n' trigger however its still not showing anything on Unity's debug log even when I send ,for example, a string like "K\n" from C++ side.

Currently I'm using Virtual Serial Port to connect between the C++ program and the Unity program. I have used Eltima Virtual Serial Port (http://www.eltima.com/products/vspdxp/) and HHD Software Free Virtual Serial Port (https://freevirtualserialports.com/) however both of them still not working.

I'm a beginner also on Virtual Serial Ports so maybe there is a problem in using Virtual Serial Ports although I have tried making the C++ program to open both ports and send data back and forth and its working perfectly. For reference, here is the current C++ code using .NET Framework

 // VRSerialTest1.cpp : main project file.
 
 #include "stdafx.h"
 
 using namespace System;
 using namespace System::IO::Ports;
 
 int main(array<System::String ^> ^args)
 {
 
     String^ answer;
     String^ portName;
     String^ message;
     int baudRate = 9600;
     Console::WriteLine("Type in a port name and hit ENTER");
     portName = Console::ReadLine();
     // arduino settings
     SerialPort^ VR;
     VR = gcnew SerialPort(portName, baudRate);
     // open port
     try
     {
         VR->Open();
 
         do
         {
             // ask on or off
             Console::WriteLine("Type \"on\" to send data or \"off\" to read data");
             // get answer
             answer = Console::ReadLine();
             //check that user typed one of the options
             if (String::Compare(answer, "on") == 0)
             {
                 VR->WriteLine("1\n"); // send 1 to VR
                 Console::WriteLine("1\n");
             }
             else if (String::Compare(answer, "off") == 0)
             {
                 message = VR->ReadLine();
                 Console::WriteLine(message);
             }
             else
                 Console::WriteLine(answer + " was not an option");
             // ask user if he wants to continue
             Console::WriteLine("Try again? yes/no");
             // get answer
             answer = Console::ReadLine();
             // clear the screen
             Console::Clear();
         } while (String::Compare(answer, "yes") == 0);
         // close port to arduino
         VR->Close();
     }
     catch (IO::IOException^ e)
     {
         Console::WriteLine(e->GetType()->Name + ": Port is not ready\n");
     }
     catch (ArgumentException^ e)
     {
         Console::WriteLine(e->GetType()->Name + ": incorrect port name syntax, must start with COM/com\n");
     }
     // end program
     Console::Write("Press enter to close the program");
     Console::Read();
     return 0;
 }

Thank you for your time reading this. I'm really out-of-idea on where is the problem so any answer might be helpful.

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

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

How can i use any imported model(for example Crysis Nanosuit) instead of mecanim rigged model? 0 Answers

RigidBody.It doesn't give speed to my gameObject 3 Answers

Custom Input Manager Menu Reset Keybinds 0 Answers

Why doesn't my game update on Android Tablet unless I'm clicking the screen? 1 Answer


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