serialport write时System.IO.IOException: 参数错误

柯人 2014-09-02 11:23:25
如题; 而且是 我的电脑上不会出错,另一人的电脑 出的错 ,
2014/09/02 09:08:35:405 发送信息失败--System.IO.IOException: 参数错误。

在 System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
在 System.IO.Ports.SerialStream.EndWrite(IAsyncResult asyncResult)
在 System.IO.Ports.SerialStream.Write(Byte[] array, Int32 offset, Int32 count, Int32 timeout)
在 System.IO.Ports.SerialPort.Write(Byte[] buffer, Int32 offset, Int32 count)
在 HycCommoLibrary.SerialPortHelperEX.Write(Byte[] buffer)
...全文
1014 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
TJ-King 2016-06-16
  • 打赏
  • 举报
回复
请问下,最后是怎么解决的?我也遇到同样的问题了
於黾 2014-09-02
  • 打赏
  • 举报
回复
先确定串口打开了?串口名没有问题? 每台电脑串口名不一定都是COM1
柯人 2014-09-02
  • 打赏
  • 举报
回复
引用 9 楼 Z65443344 的回复:
编译是按AnyCpu?
dll 是 anycpu exe是x86
柯人 2014-09-02
  • 打赏
  • 举报
回复
引用 9 楼 Z65443344 的回复:
编译是按AnyCpu?
是x86的
於黾 2014-09-02
  • 打赏
  • 举报
回复
编译是按AnyCpu?
柯人 2014-09-02
  • 打赏
  • 举报
回复
引用 7 楼 Z65443344 的回复:
电脑什么系统,多少位的
我的是 win7 64位 他的是 win7 32味的
於黾 2014-09-02
  • 打赏
  • 举报
回复
电脑什么系统,多少位的
柯人 2014-09-02
  • 打赏
  • 举报
回复
引用 5 楼 sunny906 的回复:
记录异常日志,看看Write接收的是什么类型的数据
我自己的代码 发送的是byte[] 主要是 我的电脑上发 就ok, 他的电脑就报 i/o参数错误
sunny906 2014-09-02
  • 打赏
  • 举报
回复
记录异常日志,看看Write接收的是什么类型的数据
柯人 2014-09-02
  • 打赏
  • 举报
回复
引用 3 楼 bdmh 的回复:
看看人家有没有串口,并且串口使用的是否匹配
是否匹配 什么意思,我是在做write操作的时候 我的电脑ok,另一人的电脑就写入失败 System.IO.IOException: 参数错误
bdmh 2014-09-02
  • 打赏
  • 举报
回复
看看人家有没有串口,并且串口使用的是否匹配
柯人 2014-09-02
  • 打赏
  • 举报
回复
串口一打开 是write的时候 System.IO.IOException: 参数错误。
android 串口驱动源代码 package android.serialport; import java.io.File; import java.io.FileDescriptor; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import android.util.Log; public class SerialPort { private static final String TAG = "SerialPort"; /* * Do not remove or rename the field mFd: it is used by native method close(); */ private FileDescriptor mFd; private FileInputStream mFileInputStream; private FileOutputStream mFileOutputStream; public SerialPort(File device, int baudrate) throws SecurityException, IOException { /* Check access permission */ if (!device.canRead() || !device.canWrite()) { try { /* Missing read/write permission, trying to chmod the file */ Process su; su = Runtime.getRuntime().exec("/system/bin/su"); /*String cmd = "chmod 777 " + device.getAbsolutePath() + "\n" + "exit\n";*/ String cmd = "chmod 777 /dev/s3c_serial0" + "\n" + "exit\n"; su.getOutputStream().write(cmd.getBytes()); if ((su.waitFor() != 0) || !device.canRead() || !device.canWrite()) { throw new SecurityException(); } } catch (Exception e) { e.printStackTrace(); throw new SecurityException(); } } mFd = open(device.getAbsolutePath(), baudrate); if (mFd == null) { Log.e(TAG, "native open returns null"); throw new IOException(); } mFileInputStream = new FileInputStream(mFd); mFileOutputStream = new FileOutputStream(mFd); } // Getters and setters public InputStream getInputStream() { return mFileInputStream; } public OutputStream getOutputStream() { return mFileOutputStream; } // JNI private native static FileDescriptor open(String path, int baudrate); public native void close(); static { System.loadLibrary("serial_port"); } }

111,097

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧