您的位置:程序门 -> .net技术 -> c#



有做扫描枪的高手帮看看吗?


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


有做扫描枪的高手帮看看吗?
发表于:2007-03-27 21:55:03 楼主
using   system;
using   system.drawing;
using   system.collections;
using   system.componentmodel;
using   system.windows.forms;
using   system.data;
using   terminal.api;

namespace   he
{
///   <summary>
///   form1   的摘要说明。
///   </summary>
public   class   form1   :   system.windows.forms.form
{
private   system.windows.forms.textbox   txtbarcode1;
private   dcdevent   dcdevent;
public   static   dcdhandle   hdcd;
private   string   dcddata   =   string.empty;

public   form1()
{

initializecomponent();


dcdrequesttype   reqtype   =   (dcdrequesttype)1   ¦   dcdrequesttype.postrecurring   ;
dcdevent   =   new   dcdevent(   form1.hdcd,   reqtype);
dcdevent.scanned   +=   new   dcdscanned(dcdevent_scanned);
//this.closing   +=   new   canceleventhandler(acn_closing);
this.activated   +=   new   eventhandler(cashregister_activated);
}
void   cashregister_activated(object   sender,eventargs   e)
{
if(dcdevent   ==   null)
{
dcdrequesttype   reqtype   =   (dcdrequesttype)1   ¦   dcdrequesttype.postrecurring   ;
dcdevent   =   new   dcdevent(   form1.hdcd,   reqtype);
dcdevent.scanned   +=   new   dcdscanned(dcdevent_scanned);
}
}
//打开扫描头
private   void   dcdevent_scanned(object   sender,   dcdeventargs   e)
{
codeid   cid   =   codeid.nodata;  
dcddata   =   string.empty;
try
{
dcddata   =   form1.hdcd.readstring(e.requestid,   ref   cid);
}
catch(exception)
{
messagebox.show( "扫描出错 ");  
return;
}
if(dcddata.length   !=   0)
invoke(new   eventhandler(gobackmain));  
}
private   void   gobackmain(object   sender,eventargs   e)
{
//dcddata   =   dcddata.trimend(new   char[]{ '\r ', '\n ', '   ', ' '});  
dcddata   =   dcddata.trimstart(new   char[]{(char)2,(char)3});  
dcddata   =   dcddata.trimend(new   char[]{ '\r ', '\n ', '   ', ' ',(char)2,(char)3});  
if(txtbarcode1.focused)
{      
txtbarcode1.text   =   dcddata;
dcddata   =   string.empty;
//this.getbarcode(   txtbarcode1.text.trim());

}
}
///   <summary>
///   清理所有正在使用的资源。
///   </summary>
protected   override   void   dispose(   bool   disposing   )
{
base.dispose(   disposing   );
}
#region   windows   窗体设计器生成的代码
///   <summary>
///   设计器支持所需的方法   -   不要使用代码编辑器修改
///   此方法的内容。
///   </summary>
private   void   initializecomponent()
{
this.txtbarcode1   =   new   system.windows.forms.textbox();
//  
//   txtbarcode1
//  
this.txtbarcode1.location   =   new   system.drawing.point(24,   32);
this.txtbarcode1.multiline   =   true;
this.txtbarcode1.size   =   new   system.drawing.size(368,   256);
this.txtbarcode1.text   =   " ";
//  
//   form1
//  
this.controls.add(this.txtbarcode1);
this.text   =   "form1 ";

}
#endregion

///   <summary>
///   应用程序的主入口点。
///   </summary>

static   void   main()  
{
application.run(new   form1());
}
}
}

未处理的“system.nullreferenceexception”类型的异常出现在   terminal.api.dll   中。
里面的api是绝对没用问题的!有做扫描枪程序的朋友帮看看吗?
我这是写的一psc的扫描枪打开扫描头,然后获得条码显示到textbox上!
跪求!
发表于:2007-03-27 21:57:281楼 得分:0
真的没高手了????天那
发表于:2007-03-27 22:05:522楼 得分:0
哪行代码抛出的异常?
发表于:2007-08-07 13:58:403楼 得分:0
mark
发表于:2007-08-07 16:50:104楼 得分:0
什么嘛?     是条形码扫描仪吗?

那东西其实就相当于一个键盘,   最后一个字符是回车……

程序很好编的……


快速检索

最新资讯
热门点击