Activex在沒有電子秤api的狀況下獲取串口數據

大二作B/S架構的項目使用了安衡電子秤CHS-D+R和一款掃碼槍,兩個設備的串口使用同樣,這款電子秤是至關的坑,沒有開發的api,無奈只能本身開發Activex了,在B/S架構中進行引用Activex的Guid可以達到使用本地串口的最終目的.api

Activex中首先要進行安全簽名的設置安全

[ComImport, GuidAttribute("CB5BDC81-93C1-11CF-8F20-00805F2CD064")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
public interface IObjectSafety
{
[PreserveSig]
int GetInterfaceSafetyOptions(ref Guid riid, [MarshalAs(UnmanagedType.U4)] ref int pdwSupportedOptions, [MarshalAs(UnmanagedType.U4)] ref int pdwEnabledOptions);架構

[PreserveSig()]
int SetInterfaceSafetyOptions(ref Guid riid, [MarshalAs(UnmanagedType.U4)] int dwOptionSetMask, [MarshalAs(UnmanagedType.U4)] int dwEnabledOptions);
}ui

下面進行Activex的開發3d

private void serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
//string str = serialPort.ReadLine();
//ReceiveTbox1.Text += str;
string str = serialPort.ReadLine();
textBox3.Text = str.Substring(7);

}blog

public string GetData()
{
string str = serialPort.ReadLine();
return str;
}開發

相關文章
相關標籤/搜索