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;
}
上一篇: C# 邮箱mail 发送类
下一篇: 历史上真正的“如懿”,3年生育了3胎