如何在ASP.NET中构建读取条形码表单 [英] How to building read barcode form comport in ASP.NET

查看:60
本文介绍了如何在ASP.NET中构建读取条形码表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在构建网站阅读条码表单扫描器comport我在msdn中找到源代码写c#winform我不知道如何更改为asp.net。我希望有一个人可以帮助我。非常感谢。

和代码C#winform。






I'am building website read barcode form scanner comport and I find source in msdn write c# winform I don't know how to I can change to asp.net. I hope someone can help me. thank so much.
and here code C# winform.


public partial class Form1 : Form  
{  
     SerialPort _serialPort;  
  
     private delegate void SetTextDeleg(string text);  
  
     private void Form1_Load(object sender, EventArgs e)  
     {  
           _serialPort = new SerialPort("COM1", 19200, Parity.None, 8, StopBits.One);  
           _serialPort.Handshake = Handshake.None;  
           _serialPort.DataReceived += new SerialDataReceivedEventHandler(sp_DataReceived);  
           _serialPort.ReadTimeout = 500;  
           _serialPort.WriteTimeout = 500;  
           _serialPort.Open();  
     }  
  
     private void btnStart_Click(object sender, EventArgs e)  
     {  
           try  
           {  
                if(!_serialPort.IsOpen)  
                     _serialPort.Open();  
  
                _serialPort.Write("SI\r\n");  
           }  
           catch (Exception ex)  
           {  
                MessageBox.Show("Error opening/writing to serial port :: " + ex.Message, "Error!");  
           }  
     }  
  
     void sp_DataReceived(object sender, SerialDataReceivedEventArgs e)  
     {  
          Thread.Sleep(500);  
          string data = _serialPort.ReadLine();  
          this.BeginInvoke(new SetTextDeleg(si_DataReceived), new object[] { data });  
     }  
  
     private void si_DataReceived(string data)  
     {  
           textBox1.Text = data.Trim();  
     }  
}  





我的尝试:





What I have tried:

public partial class Form1 : Form  
{  
     SerialPort _serialPort;  
  
     private delegate void SetTextDeleg(string text);  
  
     private void Form1_Load(object sender, EventArgs e)  
     {  
           _serialPort = new SerialPort("COM1", 19200, Parity.None, 8, StopBits.One);  
           _serialPort.Handshake = Handshake.None;  
           _serialPort.DataReceived += new SerialDataReceivedEventHandler(sp_DataReceived);  
           _serialPort.ReadTimeout = 500;  
           _serialPort.WriteTimeout = 500;  
           _serialPort.Open();  
     }  
  
     private void btnStart_Click(object sender, EventArgs e)  
     {  
           try  
           {  
                if(!_serialPort.IsOpen)  
                     _serialPort.Open();  
  
                _serialPort.Write("SI\r\n");  
           }  
           catch (Exception ex)  
           {  
                MessageBox.Show("Error opening/writing to serial port :: " + ex.Message, "Error!");  
           }  
     }  
  
     void sp_DataReceived(object sender, SerialDataReceivedEventArgs e)  
     {  
          Thread.Sleep(500);  
          string data = _serialPort.ReadLine();  
          this.BeginInvoke(new SetTextDeleg(si_DataReceived), new object[] { data });  
     }  
  
     private void si_DataReceived(string data)  
     {  
           textBox1.Text = data.Trim();  
     }  
}  

推荐答案

可能你不能:一个网站作为客户端/服务器运行方法,而且代码是WinForms。

问题是网站中的C#代码在服务器而不是客户端运行 - 所以它只能访问服务器硬件资源,并期望连接扫描仪到服务器COM端口 - 它无法访问连接到客户端的任何扫描仪。由于用户坐在千里之外的客户端计算机上,他无法向扫描仪提供条形码进行处理。



我认为你需要看一下你正在努力做的事情更加密切:在互联网上找到随机代码并希望它能够正常工作,因为它是用你知道的语言不起作用。
Probably, you can't: a web site runs as a client / server approach, and that code is WinForms.
The problem is that C# code in a website runs on the server, not the client - so it can only access server hardware resources, and expects the scanner to be connected to the server COM port - it can't access any scanner connected to the client. And since the user is sitting at the client computer a thousand miles away he can't present a barcode to the scanner for processing.

I think you need to look a lot more closely at what you are trying to do: finding random code on the internet and hoping it will work because it's in a language you know just isn't going to work.


这篇关于如何在ASP.NET中构建读取条形码表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆