Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by crow45 · Jun 12, 2016 at 12:45 AM · errornetworkingarduinoserialportresponse

Unity / Arduino wifi communication for multiwii serial protocol

Hello, im using unity to send and recieve socket using serial protocol after converting values and assembling the socket and send it i couldn't get any answer from the arduino considering that when i send it via a socket test android application and write the socket manually (24 4d 3c 00 64 64) in Hex, i get an answer, i think it has somethink with the speed of transmission, this is my code:

 `
     public void setupSocket() {                            // Socket setup here
         try {                
             mySocket = new TcpClient(Host, Port);
             theStream = mySocket.GetStream();
             theWriter = new StreamWriter(theStream);
             theReader = new StreamReader(theStream);
             socketReady = true;
             cnx.Play ();                                //voice assistant "connected"
         }
         catch (Exception e) {
             Debug.Log("Socket error:" + e);                // catch any exceptions
             lostcnx.Play ();                                    //Disconnected voice assistant
         }
     }
     
     public void writeSocket(string theLine) {            // function to write data out
         if (!socketReady)
             return;
         string tmpString = theLine;
         theWriter.WriteLine(tmpString);
         theWriter.Flush();
 
 
 
     }
     
     public string readSocket() {                        // function to read data in
         if (!socketReady)
             return "";
         if (theStream.DataAvailable)
             return theReader.ReadLine();
 
         return "NoData";
     }
     
     


and this is the socket encoding and decoding code :

 `
         
         //send msp with payload
         private List<Byte> requestMSP(int msp, byte[] payload)
         {
             if (msp < 0)
             {
                 return null;
             }
             List<Byte> bf = new List<Byte>();
             foreach (byte c in MSP_HEADER.ToCharArray())
             {
                 bf.Add(c);
             }
             
             byte checksum = 0;
             byte pl_size = (byte)((payload != null ? (int)(payload.Length) : 0) & 0xFF);
             bf.Add(pl_size);
             checksum ^= (byte)(pl_size & 0xFF);
             
             bf.Add((byte)(msp & 0xFF));
             checksum ^= (byte)(msp & 0xFF);
             
             if (payload != null)
             {
                 foreach (byte b in payload)
                 {
                     bf.Add((byte)(b & 0xFF));
                     checksum ^= (byte)(b & 0xFF);
                 }
             }
             bf.Add(checksum);
             return (bf);
         }
         
         void sendRequestMSP(List<Byte> msp)
         {
             byte[] arr = new byte[msp.Count];
             int i = 0;
             foreach (byte b in msp)
             {
                 arr[i++] = b;
             }
             client.writeSocket(BitConverter.ToString(arr)); // send the complete byte sequence in one go
             string output=BitConverter.ToString(arr);
             Debug.Log (output);/*
             for (int l = 0; l < arr.Length; l ++) { 
             Debug.Log (arr [l]);
         }*/
         }
         `

its a multiwii serial protocol, i've tried many possible solution the socket looks correct in the debug messages but i guess the hex value is converted in wrong way before sending, and the baudrate for arduino is 115200 i don't know if i can control the speed of transmition some how or not as in the serial port example it is possible, i appreciate any help it is for my final year project and im running out of time

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.

Follow this Question

Answers Answers and Comments

82 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

Related Questions

UNet Networking problem 1 Answer

Unity [PUN] New Instantiated players cannot see previously instantiated players 0 Answers

Unity hangs when I press play (serial port, unity + arduino) 0 Answers

Mirror network error : There is already a player for this connection. 1 Answer

Using serial makes game very laggy 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