串口控制項注冊
㈠ 如何解決MS串口通信控制項MSCOMM32.OCX "建立空文檔失敗" 的問題
部件mscomm32.ocx不能正確注冊
通常有一些小程序是基於串口控制控制項MSCOMM32.OCX的,然而我們經常會遇到」部件mscomm32.ocx或其附件之一不能正確注冊「這樣的問題,而導致這些小程序無法運行。而解決辦法就是在計算機上重新注冊mscomm32.ocx組件。
具體步驟:
下載控制項所需件文件MSCOMM32.rar,解壓後得到文件MSCOMM32.OCX;
將文件MSCOMM32.OCX復制粘貼到C:\Windows\system32目錄下,如果是64位的系統,則放在C:\Windows\sysWOW64目錄下;
開始,運行cmd,打開命令行,粘貼代碼 regsvr32 C:\Windows\system32\MSComm32.ocx,然後按enter,稍後會提示注冊成功。如果是64位操作系統,則是運行代碼 regsvr32 C:\Windows\sysWOW64\MSComm32.ocx;
如果提示注冊成功,以下步驟可以忽略。
如果遇到提示」模塊。。。已載入,但對 DllRegisterServer 的調用失敗。。。錯誤代碼。。。「,一般Windows7系統都會產生這樣的問題,是因為Win7的安全性比較高,在運行里調出cmd命令行的時候實際上是沒有高級許可權的。因此,我們在操作運行中,輸入cmd,然後不要急於按下Enter回車鍵,而是按下Ctrl+Shift+Enter組合鍵,這種情況下,就會提示是否以管理員身份運行cmd了,點擊確定。然後再執行上面的第3步,就會發現成功了。
㈡ mfc串口控制項注冊32和64位的文件一樣嗎
VS2010本身並不自帶MSCOMM控制項,因此在Win7、win8/8.1系統中使用VS2010進行串口編程時,
在COM控制項一欄中沒法找到。
網上解決這個問題的文章很多,但嘗試了很多種方法都沒有解決,原因是很多文章都是沒有
具體的給出具體的細節,導致有些操作沒法進行。
這里依據自己的嘗試成功的例子給出方法。
(1)基於以下環境實現的
(環境對實際的情況有影響,win7以及VS2012/2013用戶可以使用該方法進行嘗試,但不保證能成功)
Windows 8.1 X64
VS2010
(2)下載MSCOMM控制項包
(3)將下載的文件解壓,並將其拷貝到 C:\Windows\SysWOW64 目錄下
本機器 C:\Windows\System32 下無法注冊成功,這里可以根據電腦的系統進行嘗試。
(4)可以先使用 管理員許可權 運行 Setup.bat 進行安裝和注冊,但本人使用此方法嘗試失敗。
最後使用以下方法注冊成功:
在 C:\Windows\SysWOW64 搜索到cmd.exe,使用 管理員許可權 打開,然後輸入
regsvr32 C:\Windows\SysWOW64\mscomm32.ocx
然後提示注冊成功。
(5)此時可以在VS2010中建立一個MFC工程,應該能夠在COM組件中看到
Microsoft communications control,version 6.0
將其勾選上之後,在工具欄就能看到 電話標志 的空間圖標了。
㈢ 串口控制項!!!!急!!!
你的代碼中len沒有賦值,在代碼safearray_inp=variant_inp;後面加入下面這句
len=(USHORT)safearray_inp.GetOneDimSize();
//得到有效數據長度
解釋以下你的疑問:
for(k=0;k
評論
0
0
載入更多
㈣ 介紹一下「串口控制項初始化程序」
在VB中編寫串口通信程序都是用MSComm 控制項
說明
MSComm 控制項提供下列兩種處理通訊的方式:
1、事件驅動通訊是處理串列埠交互作用的一種非常有效的方法。在許多情況下,在事件發生時需要得到通知,例如,在 Carrier Detect (CD) 或 Request To Send (RTS) 線上一個字元到達或一個變化發生時。在這些情況下,可以利用 MSComm 控制項的 OnComm 事件捕獲並處理這些通訊事件。OnComm 事件還可以檢查和處理通訊錯誤。所有通訊事件和通訊錯誤的列表。
2、在程序的每個關鍵功能之後,可以通過檢查 CommEvent 屬性的值來查詢事件和錯誤。如果應用程序較小,並且是自保持的,這種方法可能是更可取的。例如,如果寫一個簡單的電話撥號程序,則沒有必要對每接收一個字元都產生事件,因為唯一等待接收的字元是數據機的「確定」響應。
每個使用的 MSComm 控制項對應著一個串列埠。如果應用程序需要訪問多個串列埠,必須使用多個 MSComm 控制項。可以在 Windows「控制面板」中改變埠地址和中斷地址。
盡管 MSComm 控制項有很多重要的屬性,但首先必須熟悉幾個屬性。
屬性 描述
CommPort 設置並返回通訊埠號。
Settings 以字元串的形式設置並返回波特率、奇偶校驗、數據位、停止位。
PortOpen 設置並返回通訊埠的狀態。也可以打開和關閉埠。
Input 從接收緩沖區返回和刪除字元。
Output 向傳輸緩沖區寫一個字元串。
下面這個簡單的例子演示了用數據機進行基本的串列通訊:
Private Sub Form_Load ()
' 保存輸入子串的緩沖區
Dim Instring As String
' 使用 COM1。
MSComm1.CommPort = 1
' 9600 波特,無奇偶校驗,8 位數據,一個停止位。
MSComm1.Settings = "9600,N,8,1"
' 當輸入佔用時,
' 告訴控制項讀入整個緩沖區。
MSComm1.InputLen = 0
' 打開埠。
MSComm1.PortOpen = True
' 將 attention 命令送到數據機。
MSComm1.Output = "ATV1Q0" & Chr$(13) ' 確保
' 數據機以"OK"響應。
' 等待數據返回到串列埠。
Do
DoEvents
Buffer$ = Buffer$ & MSComm1.Input
Loop Until InStr(Buffer$, "OK" & vbCRLF)
' 從串列埠讀 "OK" 響應。
' 關閉串列埠。
MSComm1.PortOpen = False
End Sub
㈤ 請問你知道安裝包製作如何注冊ocx控制項嗎,使用VS2010
一般是通過regsvr32注冊,你轉換成對應的腳本語言就行。
㈥ 在64位機器上注冊串口控制項成功,為什麼不能定義控制項變數
樣你的注冊控制項就能順利在目標機器上注冊,能被其他程序鎖使用,反安裝的時候也不... 或者在Installation Designer-Media-Path Variables裡面查看其他變數定義 第二步:左邊
㈦ 關於MSFlexgrid控制項(注冊)的一個小問題
未安裝VC使用activeX控制項- -Tag: 串口控制項 注冊
在使用串口控制項時,在沒有裝VC的機器上碰到問題
regsvr32 注冊成功,但仍然不能使用,經查找是LicenseKey的問題
只需在創建控制項時增加下列幾行即可
WCHAR pwchLicenseKey[] =
{
0x0043, 0x006F, 0x0070, 0x0079, 0x0072, 0x0069,
0x0067, 0x0068, 0x0074, 0x0020, 0x0028, 0x0063,
0x0029, 0x0020, 0x0031, 0x0039, 0x0039, 0x0034,
0x0020
};
BSTR bstrLicense = ::SysAllocStringLen(pwchLicenseKey,
sizeof(pwchLicenseKey)/sizeof(WCHAR));
if(!m_ComPort.Create(NULL,0,CRect(0,0,0,0),AfxGetMainWnd(),
IDC_MSCOMM1,NULL,FALSE,bstrLicense))
{
AfxMessageBox("Failed to create OLE Communications Control\n");
return -1; //fail to create
}
......
::SysFreeString(bstrLicense);
具體參考原文見下:
-----------------------------------------------------------------------------------------------------
This article was previously published under Q151771
SUMMARYThe LicReqst sample illustrates how to use the IClassFactory2 interface to request an object's License key.
The following file is available for download from the Microsoft Download Center:
Licreqst.exe
For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:
119591 How to Obtain Microsoft Support Files from Online Services
Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file. NOTE: Use the -d option when running Licrqst.exe to decompress the file and recreate the proper directory structure.
MORE INFORMATIONThe LicReqst sample is a dialog-based MFC application that illustrates how to use the IClassFactory2 interface to request an object's License key. LicReqst displays the ProgID of each of the currently registered ActiveX controls in a Listbox. When one of the displayed ProgID's is selected, an instance of the corresponding control is created and then asked for it's License key. If a valid key is returned, LicReqst displays the key and enables the "Copy to Clipboard" button that allows the License key to be copied to the Clipboard. The License key can then easily be pasted into code that uses the CWnd::CreateControl method to dynamically create an instance of the Control.
LicReqst creates a textual version of the License key data in the form of a declaration of an array of WCHAR when ing the key to the Clipboard. This is done because the License key data could contain non-printable characters. A human-readable version of the License key data is also provided for reference and is included inside a Comment block in the final string that is copied to the Clipboard.
For example, if an object uses the string "Copyright (c) 1994" (without the quotes) for its License key, LicReqst would generate the following block of text that could be copied to and pasted from the Clipboard:
/*
Copyright (c) 1994
*/
WCHAR pwchLicenseKey[] =
{
0x0043, 0x006F, 0x0070, 0x0079, 0x0072, 0x0069,
0x0067, 0x0068, 0x0074, 0x0020, 0x0028, 0x0063,
0x0029, 0x0020, 0x0031, 0x0039, 0x0039, 0x0034,
0x0020
};
You can use the previous block of text in code that creates an instance of the Licensed object, and you can use the pwchLicenseKey variable to specify the object's License key.
For example, if MFC code is dynamically creating an instance of a Licensed ActiveX Control using the Create method of a Visual C++ Component Gallery generated wrapper class, the pwchLicenseKey variable can be used in the Create call like this:
BSTR bstrLicense = ::SysAllocStringLen(pwchLicenseKey,
sizeof(pwchLicenseKey)/sizeof(WCHAR));
m_MyControl.Create(NULL, WS_VISIBLE, CRect(10,10,10,10), this,
2, NULL, FALSE, bstrLicense);
::SysFreeString(bstrLicense);
Note how a BSTR is created from the pwchLicenseKey variable and how the BSTR is then used for the License key parameter in the Create call.
NOTE: The code in this sample that generates the text copied to the Clipboard makes the assumption that it is being executed on a little endian system (Intel x86-class processors). Because of this, it will not work correctly on big endian system. For these systems, it is still possible to use the Helper function used internally by the sample to request the License key from an object.
The sample uses a Helper function called RequestLicenseKey() to get the License key from an object based on its ProgID. The source code for the RequestLicenseKey() function is shown later in the Sample Code section.
To find other locations of interest in the sample source code, use the Find in Files feature of the Visual C++ Developer Studio to search for the string named SAMPLE CODE. This string has been used to tag each of the modified sections in the source code.
NOTE: Running the LicReqst sample on a licensed machine to obtain an object's License key, and then distributing that key to allow applications to be developed on other non-licensed machines, may be a violation of established rights. For more information and to determine if an object's License key can be legally redistributed, refer to the License Agreement provided with the object or contact the creator of the object. Sample Code// Compile options needed: none
///////////////////////////////////////////////////////////////////////
// SAMPLE CODE - Implementation of the RequestLicenseKey function
//
// The RequestLicenseKey function uses the IClassFactory2 interface
// to request a License key from an object specified by its ProgID.
//
// Parameters:
//
// [out] BSTR& bstrLicenseKey
// Upon return, this BSTR will contain either a valid
// License key or an error message. It is the caller's
// responsibility to call ::SysFreeString on this BSTR.
//
// [in] CString strProgID
// Specifies the ProgID of the object from which to request the
// License key.
//
//
// Return Value:
//
// A BOOL specifying success or failure. If TRUE is returned,
// the License key was retrieved successfully and the
// bstrLicenseKey parameter contains a valid License key. If
// FALSE is returned, the License key was not retrieved
// successfully and the bstrLicenseKey parameter contains a
// descriptive error string.
//
// Regardless of the return value, it is the responsibility of
// the caller to call ::SysFreeString on the returned bstrLicenseKey
// parameter.
//
BOOL RequestLicenseKey(BSTR& bstrLicenseKey, CString strProgID)
{
USES_CONVERSION;
LPCLASSFACTORY2 pClassFactory;
CLSID clsid;
BOOL bValidKeyReturned = FALSE;
// Get the CLSID of the specified ProgID.
if (SUCCEEDED(CLSIDFromProgID(T2OLE(strProgID), &clsid)))
{
// Create an instance of the object and query it for
// the IClassFactory2 interface.
if (SUCCEEDED(CoGetClassObject(clsid, CLSCTX_INPROC_SERVER, NULL,
IID_IClassFactory2, (LPVOID *)(&pClassFactory))))
{
LICINFO licinfo;
// Check to see if this object has a runtime License key.
if (SUCCEEDED(pClassFactory->GetLicInfo(&licinfo)))
{
if (licinfo.fRuntimeKeyAvail)
{
HRESULT hr;
// The object has a runtime License key, so request it.
hr = pClassFactory->RequestLicKey(0, &bstrLicenseKey);
if (SUCCEEDED(hr))
{
if(bstrLicenseKey == NULL)
bstrLicenseKey = ::SysAllocString(
L""); else // You have the license key. bValidKeyReturned = TRUE; } else // Requesting the License key failed. switch(hr) { case E_NOTIMPL: bstrLicenseKey = ::SysAllocString( L""); break; case E_UNEXPECTED: bstrLicenseKey = ::SysAllocString( L""); break; case E_OUTOFMEMORY: bstrLicenseKey = ::SysAllocString( L""); break; case CLASS_E_NOTLICENSED: bstrLicenseKey = ::SysAllocString( L""); break; default: bstrLicenseKey = ::SysAllocString( L""); } } else bstrLicenseKey = ::SysAllocString( L""); } else bstrLicenseKey = ::SysAllocString( L""); // Make sure you release the reference to the class factory. pClassFactory->Release(); } else bstrLicenseKey = ::SysAllocString( L""); } else bstrLicenseKey = ::SysAllocString( L""); // Return a BOOL specifying whether or not you were able to get a // valid license key. return bValidKeyReturned; }
㈧ 其他界面怎樣使用第一個界面的串口控制項我直接調用的時候提示串口未打開
在VB中是這樣用的
If Frmtest.MSComm2.PortOpen = True Then Frmtest.MSComm2.PortOpen = False
Frmtest.MSComm2.CommPort = SetInfo.LightPort
Frmtest.MSComm2.Settings = "2400,N,8,1"
Frmtest.MSComm2.InputLen = 0
Frmtest.MSComm2.InBufferCount = 0
Frmtest.MSComm2.InputMode = comInputModeBinary '數據通過 設置Inputmode 屬性以二進制形式取回。
Frmtest.MSComm2.PortOpen = True
窗體Frmtest應處於載入狀態
㈨ 從界面MScomm串口控制項如何初始化
procere TForm1.FormCreate(Sender: TObject);
begin
try
MSComm1.CommPort:=1;//設置串口號,即Com1口
MSComm1.Settings:='9600,N,8,1';
MSComm1.InputLen:=0;
MSComm1.InBufferSize:=1024;
MSComm1.InBufferCount:=0;
MSComm1.OutBufferCount:=0;
timer1.Enabled:=false;
// MSComm1.PortOpen:=false;
except
Application.MessageBox('串口初始化失敗!','提示',0) ;
Application.Terminate ;
end;
end;
㈩ DELPHI XE2 的串口控制項MSCOMM怎麼安裝和應用
Mscomm控制項默認存在於delphi的ActiveX面板上,如果不存在,需要先導入該控制項,步驟 :通過菜單 component---Import Activex component 打開Import Acitvex對話框。
如果列表中找不到該Microsoft Comm Control,那麼點Add按鈕找到Mscomm32.ocx,最後點Install..即可。