当前位置: 移动技术网 > IT编程>开发语言>.net > Activex在没有电子秤api的情况下获取串口数据

Activex在没有电子秤api的情况下获取串口数据

2019年07月17日  | 移动技术网IT编程  | 我要评论

漫画搜,白河县政府网,人生励志篇章

大二做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;
}

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网