0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Unity2021でHOKUYOセンサーとシリアルポート通信する方法

Last updated at Posted at 2022-12-31

HOKUYOの側域センサーをUnityでシリアルポート通信するまでに出たエラー対応です。

前提

  • Windows 11
  • Unity2021.3.11f1

結論

Api Compatibility Levelがデフォルトだと.NET Standard2.1になっているので、ここを.NET FrameworkにすればSystem.IO.Portsなどが使えるようになります。
2022-12-31_16h36_18.png

結論までの道のり

エラー1

C#サンプルをUnityから実行してみようと思うと以下のエラーが。

error CS0234: The type or namespace name 'Ports' does not exist in the namespace 'System.IO' (are you missing an assembly reference?)

エラー2

そこでこちらを参考に、System.IO.PortsをUnityにいれてみたが、以下のエラーが。

PlatformNotSupportedException: System.IO.Ports is currently only supported on Windows.

エラー3

.NETの設定どうなっているのか見てたところStandardだったので、もしやと思って.NET Framerworkにしてみたところ、以下エラーが。

error CS0433: The type 'SerialPort' exists in both 'System.IO.Ports, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' and 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

対応

エラー1対応で入れたdllがかぶっていることが問題なので、消したところ正常に実行できるようになりました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?