Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using in Unity3d #25

Open
gagagu opened this issue Sep 28, 2017 · 1 comment
Open

Using in Unity3d #25

gagagu opened this issue Sep 28, 2017 · 1 comment

Comments

@gagagu
Copy link

gagagu commented Sep 28, 2017

Hi,
i want to use you library in Unity3d and i will get an error which i don't know to handle. I've switched your Project and Unity3D to .net 4.6 and both are working correctly (separate).
The ArduinoUploader.dll and RJCP.SerialPortStream.dll are compiled also with 4.6

When i will start the Project in Visual Studio the Music sounds out of the Arduino correctly

I've copied the following files to unity:
ArduinoDriver.dll
ArduinoDriver.dll.config
ArduinoUploader.dll
IntelHexFormatReader.dll
NLog.dll
RJCP.SerialPortStream.dll
RJCP.SerialPortStream.xml

When i will start my Project and send the Music to the Arduino the yellow LED is blinking and i will get the following error:

IOException: Device Error
RJCP.IO.Ports.SerialPortStream.WriteCheckDeviceError () (at :0)
RJCP.IO.Ports.SerialPortStream.WriteCheck (System.Byte[] buffer, System.Int32 offset, System.Int32 count) (at :0)
RJCP.IO.Ports.SerialPortStream.Write (System.Byte[] buffer, System.Int32 offset, System.Int32 count) (at :0)
ArduinoUploader.BootloaderProgrammers.ArduinoBootloaderProgrammer.Send (ArduinoUploader.BootloaderProgrammers.Protocols.IRequest request) (at :0)
ArduinoUploader.BootloaderProgrammers.Protocols.STK500v1.Stk500V1BootloaderProgrammer.EstablishSync () (at :0)
ArduinoUploader.ArduinoSketchUploader.UploadSketch (System.Collections.Generic.IEnumerable`1[T] hexFileContents) (at :0)

I know ist not directly your issue but i'm hoping that you can identify the Problem when you see the error message. May be some files missing?

THX Forward!!!

@prankard
Copy link
Contributor

Hey Gagagu,

Interestingly I was also looking into getting this library working on Unity3d also.
I have downloaded the source, and changed the Unity API compatibility level to 4.6.

Then when using all the source files you can see the issue is with the SerialPortStream library where the DeviceError is thrown. There is a lot going on behind the scenes where it actually uses a native windows (or unix) library. I think this is the issue where from Unity the SerialPortStream isn't communicating to the port library natively.

However, I did manage to get half of this running in Unity (the communication, not uploading the software hex).
If you're happing uploading the ArduinoListener to your Arduino using the standard Arduino software (not using the autobootstrap the package this package does), and simply using this library to communicate with the Arduino Listener.

To do so, download the source files from this repo and drop the in unity.
Download and extract just the 'hardware' source files from ArduinoSketchUploader

Swap the namespace from 'using RJCP.IO.Ports;' to 'using System.IO.Ports;'
Swap the class from 'SerialPortStream' to 'SerialPort'
Remove the last method in 'InitializeWithAutoBootstrap' in 'ArduinoDriver.cs'

Include the other library used for Arduino Driver (NLog.dll)

That should be enough to get the sample mario tunes program running.
However, the port library originally supplied is supposedly better, check the readme.md in SerialPortStream

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants