关于TCnRS232的建议(其实是spcomm的问题)
其实是spcomm的问题
1.StartComm方法中
hNewCommFile := CreateFile(PChar(CommName), GENERIC_READ or GENERIC_WRITE,
0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL or FILE_FLAG_OVERLAPPED, 0);
修改为
hNewCommFile := CreateFile(PChar('\\.\' + CommName), GENERIC_READ or GENERIC_WRITE,
0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL or FILE_FLAG_OVERLAPPED, 0);
{解决串口号大于10无法识别的问题}
2.CommWndProc中加上默认消息处理
procedure TCnRS232.CommWndProc(var Msg: TMessage);
begin
case Msg.Msg of
PWM_GOTCOMMDATA:
begin
ReceiveData(PChar(Msg.LPARAM), Msg.WPARAM);
LocalFree(Msg.LPARAM)
end;
PWM_RECEIVEERROR: ReceiveError(Msg.LPARAM);
PWM_MODEMSTATECHANGE: ModemStateChange(Msg.LPARAM);
PWM_REQUESTHANGUP: RequestHangup;
PWM_SENDDATAEMPTY: _SendDataEmpty;
else
with msg do //默认消息处理,解决win98无法正常退出问题
//(WM_QUERYENDSESSION和WM_ENDSESSION)
Result := DefWindowProc(FHWnd, Msg, WParam, LParam);
end;
end;
|