Socket을 이용한 바코드 프린터 출력 예제 소스입니다.
SATO 프린터를 이용한 예제이며, 만약 다른 제조사의 바코드 프린터를 이용할 경우 해당 커맨드를 이용하여 전송하면 됩니다.
아래의 소스에서 커맨드 부분만 수정하면 모든 바코드 프린터에서 동일하게 사용 할 수 있습니다.
using System.Net.Sockets;
using System.Net;
using System.IO;
private void button1_Click(object sender, EventArgs e)
{
Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IAsyncResult result = client.BeginConnect("xxx.xxx.xxx.xxx", 9100, null, null);//프린터 IP, PORT SET
bool bSuccess = result.AsyncWaitHandle.WaitOne(5000, true); //5초대기
if (!bSuccess)
{
MessageBox.Show("네트워크 연결 실패하였습니다. \n다시 확인하세요.");
client.Close();
return;
}
NetworkStream ns = client.GetStream();
StreamWriter writer = new StreamWriter(ns);
char c = Convert.ToChar((int)27);
//SATO COMMNAD
writer.WriteLine(c + "A" + c + "V050" + c + "H200" + c + "L0202" + c + "P02" + c + "XMABC" + c + "V150" + c + "H200" + c + "B102150*12345*" + c + "Q1" + c + "Z");
writer.Flush();
client.Close();
client.Close();
}
'C#' 카테고리의 다른 글
[C#]PictureBox의 PreviewKeyDown 이벤트 (0) | 2016.01.19 |
---|---|
[C#]File to Byte Array Convert(Byte 형변환) 소스 코드 (0) | 2016.01.19 |
[C#/PDA]ListView Column Sorting 예제 소스 (0) | 2016.01.19 |
[C#]바코드 생성 프로그램(Barcode Generator) (0) | 2016.01.18 |
PDA 화면 캡쳐 유틸프로그램 (0) | 2016.01.18 |