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

  • 相关阅读:
    第十一章 练习。内附100道练习题URL
    第八章 模块;第九章 文件
    mysql union和join 的使用
    第七章 循环
    第六章 课后习题
    第六章 字符串操作
    第五章 课后习题
    第五章 容器之字典
    实战智能推荐系统笔记
    协同过滤推荐算法的原理及实现
  • 原文地址:https://www.cnblogs.com/wangxiaokui/p/11197246.html
Copyright © 2020-2023  润新知