シリアルポートから読み取るプログラムを書きました。Visual Studio がインストールされているコンピューターでプログラムを実行しても問題ありません。全て大丈夫。しかし、リリース フォルダを別のプログラムにコピーして実行すると、エラーが発生しますSystem.IO.IOException
。このコードを使用して、シリアル ポートからデータを読み取ります。
byte[] buffer = new byte[42];
int readBytes = 0;
int totalReadBytes = 0;
int offset = 0;
int remaining = 41;
try
{
do
{
readBytes = serial.Read(buffer, offset, remaining);
offset += readBytes;
remaining -= readBytes;
totalReadBytes += readBytes;
}
while (remaining > 0 && readBytes > 0);
}
catch (TimeoutException ex)
{
Array.Resize(ref buffer, totalReadBytes);
}
UTF8Encoding enc = new UTF8Encoding();
recieved_data = enc.GetString(buffer, 27, 5);
Dispatcher.Invoke(DispatcherPriority.Send, new UpdateUiTextDelegate(WriteData), recieved_data);
この問題を解決するにはどうすればよいですか?