资源简介
c#打开pos钱箱(usb,lpt端口testprint,实用。
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Net.NetworkInformation;
using System.IO.Ports;
using System.Drawing.Printing;
namespace testprint
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender EventArgs e)
{
Int32 port = 9100;
string bigFont = ((char)27).ToString() + ((char)33).ToString() + ((char)213).ToString();//放大字体
TcpClient client = new TcpClient();
try
{
client.Connect(“192.168.0.200“ port);
Byte[] data = new byte[]{0x1B0x76};
NetworkStream stream = client.GetStream();
stream.Write(data 0 data.Length);
//data = System.Text.Encoding.Default.GetBytes(bigFont);
//stream.Write(data 0 data.Length);
//data = System.Text.Encoding.Default.GetBytes(“打印机测试/n“);
//stream.Write(data 0 data.Length);
//data = System.Text.Encoding.Default.GetBytes(“- -/n“);
//stream.Write(data 0 data.Length);
//data = System.Text.Encoding.Default.GetBytes(“- -/n“);
//stream.Write(data 0 data.Length);
stream.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
//如果打印机没开或者异常在此处增加处理代码我通常是把异常数据放到一个DataTable中加个Timer来判断打印机正常就把
//数据发给打印机并从表中移除.
//打印机缺纸或者纸匣打开时不会出现异常不用特殊代码判断数据不会丢失.
}
finally
{
client.Close();
}
}
private void button2_Click(object sender EventArgs e)
{
Ping p1 = new Ping(); //只是演示,没有做错误处理
PingReply reply = p1.Send(this.textBox1.Text);//
displayReply(reply);
}
private void displayReply(PingReply reply) //显示结果
{
StringBuilder sbuilder ;
if (reply.Status == IPStatus.Success)
{
sbuilder = new StringBuilder();
sbuilder.Append(string.Format(“Address: {0} “ reply.Address.ToString ()));
sbuilder.Append(string.Format(“RoundTrip time: {0} “ reply.RoundtripTime));
sbuilder.Append(string.Format(“Time to live: {0} “ reply.Options.Ttl));
sbuilder.Append(string.Format(“Don‘t fragment: {0} “ reply.Options.DontFragment));
sbuilder.Append(string.Format(“Buffer size: {0} “ reply.Buffer.Length));
listBox1.Items.Add(sbuilder.ToString());
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 81920 2007-03-15 11:09 testprint\bin\Debug\POSDLL.dll
文件 12800 2013-02-24 23:39 testprint\bin\Debug\testprint.exe
文件 26112 2013-02-24 23:39 testprint\bin\Debug\testprint.pdb
文件 11600 2013-02-24 23:39 testprint\bin\Debug\testprint.vshost.exe
文件 6589 2013-02-24 23:39 testprint\Form1.cs
文件 4996 2013-02-24 23:39 testprint\Form1.Designer.cs
文件 5817 2013-02-24 23:39 testprint\Form1.resx
文件 4501 2013-02-24 18:47 testprint\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
文件 6399 2013-02-24 23:39 testprint\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 380 2013-02-24 23:39 testprint\obj\x86\Debug\GenerateResource.read.1.tlog
文件 866 2013-02-24 23:39 testprint\obj\x86\Debug\GenerateResource.write.1.tlog
文件 1006 2013-02-24 23:39 testprint\obj\x86\Debug\testprint.csproj.FileListAbsolute.txt
文件 12800 2013-02-24 23:39 testprint\obj\x86\Debug\testprint.exe
文件 180 2013-02-24 23:39 testprint\obj\x86\Debug\testprint.Form1.resources
文件 26112 2013-02-24 23:39 testprint\obj\x86\Debug\testprint.pdb
文件 180 2013-02-24 23:39 testprint\obj\x86\Debug\testprint.Properties.Resources.resources
文件 490 2013-02-24 01:04 testprint\Program.cs
文件 1350 2013-02-24 01:04 testprint\Properties\AssemblyInfo.cs
文件 2868 2013-02-24 01:04 testprint\Properties\Resources.Designer.cs
文件 5612 2013-02-24 01:04 testprint\Properties\Resources.resx
文件 1094 2013-02-24 01:04 testprint\Properties\Settings.Designer.cs
文件 249 2013-02-24 01:04 testprint\Properties\Settings.settings
文件 5671 2013-02-24 20:36 testprint\RawPrinterHelper.cs
文件 3724 2013-02-24 23:39 testprint\testprint.csproj
文件 869 2013-02-24 01:04 testprint.sln
目录 0 2013-02-24 01:04 testprint\obj\x86\Debug\TempPE
目录 0 2013-02-24 23:39 testprint\obj\x86\Debug
目录 0 2013-02-24 23:39 testprint\bin\Debug
目录 0 2013-02-24 01:04 testprint\obj\x86
目录 0 2013-02-24 23:38 testprint\bin
............此处省略6个文件信息
- 上一篇:NPOI组件
- 下一篇:C# 获取大量文件名
评论
共有 条评论