zoukankan      html  css  js  c++  java
  • Activex在没有电子秤api的情况下获取串口数据

    大二做B/S架构的项目使用了安衡电子秤CHS-D+R和一款扫码枪,两个设备的串口使用一样,这款电子秤是相当的坑,没有开发的api,无奈只能自己开发Activex了,在B/S架构中进行引用Activex的Guid能够达到使用本地串口的最终目的.

    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);
    }

    下面进行Activex的开发

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

    }

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

  • 相关阅读:
    重点解说--MVVM指南(课程学习)
    模块划分--MVVM指南(课程学习)
    开发步骤--MVVM指南(课程学习)
    MVVM指南(课程学习)
    centos vi和vim用法
    阿里云centos系统上安装ftp
    thinkphp的ip地址定位
    thinkphp方便分页的page方法
    thinkphp data方法
    thinkphp i方法
  • 原文地址:https://www.cnblogs.com/wangxiaokui/p/11197246.html
Copyright © 2011-2022 走看看