无法使用SerialCommhelper在C 中打开/初始化串行端口
Cannot open/initialize serial port in C++ using SerialCommHelper
我们正在使用USB - 塞端口转换器来建立串行端口连接。我们已经在没有串行端口的计算机上对其进行了测试,并且能够通过转换器成功地将命令发送到设备。一旦我们将.EXE文件发布到具有相同的USB串行转换器的另一台PC,它将无法打开COM端口。
我们唯一需要更改代码中的东西是端口号,我们确保从设备管理器中正确。在工作计算机上的com6,而在非工作人员上进行com11。我们还尝试将COM11更改为COM2(未使用的端口号)。我们试图使其工作的PC确实已经有3个真实的串行端口(COM1、3和4),但是它们会以某种方式干扰此端口吗?
我们使用serialCommhelper.cpp代码来初始化端口。
HRESULT CSerialCommHelper:: Init(std::string szPortName, DWORD dwBaudRate,BYTE byParity,BYTE byStopBits,BYTE byByteSize)
{
HRESULT hr = S_OK;
try
{
m_hDataRx = CreateEvent(0,0,0,0);
//open the COM Port
//LPCWSTR _portName =LPCWSTR( szPortName.c_str());
wchar_t* wString=new wchar_t[4096];
MultiByteToWideChar(CP_ACP, 0, szPortName.c_str(), -1, wString, 4096);
m_hCommPort = ::CreateFile(wString,
GENERIC_READ|GENERIC_WRITE,//access ( read and write)
0, //(share) 0:cannot share the COM port
0, //security (None)
OPEN_EXISTING,// creation : open_existing
FILE_FLAG_OVERLAPPED,// we want overlapped operation
0// no templates file for COM port...
);
if ( m_hCommPort == INVALID_HANDLE_VALUE )
{
TRACE ( "CSerialCommHelper : Failed to open COM Port Reason: %d",GetLastError());
ASSERT ( 0 );
std::cout << "This is where the error happens" << std::endl;
return E_FAIL;
}
,我们使用
称此为此if( m_serial.Init(comPort, 38400, 0, 1, 8) != S_OK )
正确设置了哪个comport,但init永远不会返回s_ok。
任何帮助将不胜感激!谢谢你!
com端口名称语法更改com10及更高。您需要:" \。 com10"
如下所示...http://support.microsoft.com/kb/115831/en-us
相关文章:
- Qt Q串行端口未编程设备未关闭
- 在 linux c++ 中没有通过串行端口发送的数据
- 检查串行端口Linux中是否有传入数据(cbInQue for linux)
- 在不传输的情况下更改 Win32 中的串行端口波特率
- 增强 ASIO 和串行端口异步读取
- 串行端口写入究竟如何从缓冲区实际写入数据?
- 如何将参数这些串行端口传递到函数中
- 从 C/C++ 访问 Android 中的串行端口
- Qt两个串行端口发送和接收
- 通过串行端口从GPS传感器读取
- 提升 asio 串行端口"end of file"
- 通过串行端口发送多个值
- 与QSerialPort配合使用的串行端口仿真
- 如何通过boost::asio和shared_ptr创建串行端口
- 串行端口编码
- 使用来自串行端口的字符串数据来操作振镜扫描仪在更高的速度下会出错
- 写入和读取十六进制 TRAM QT 串行端口
- Qt串行端口数据接收
- 无法使用SerialCommhelper在C 中打开/初始化串行端口
- Win API串行端口初始化后需要等待