參考1
參考2
---------
My.Settings.DirectPrint_Port 是设置的打印机端口。
可以为 LPT1,LPT2,com1,com2
---------
Try
Dim iHandle As IntPtr
Try
If My.Settings.DirectPrint_Port.Length <> 0 Then
iHandle = CreateFile(My.Settings.DirectPrint_Port, GENERIC_READ Or GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0)
'iHandle = CreateFile("\\.\USB002", GENERIC_READ Or GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0) '打开USB句柄
Else
iHandle = CreateFile("LPT1", GENERIC_READ Or GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0)
End If
Catch ex As Exception
iHandle = CreateFile("LPT1", GENERIC_READ Or GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0)
End Try
'If "GAINSCHA GP(Aopos)"
If (iHandle.ToInt32 = -1) Then
MsgBox("没有连接打印机或者打印机端口不是LPT1")
Exit Sub
Else
' MsgBox("打印机连接成功!")
Dim fs As New FileStream(iHandle, FileAccess.ReadWrite)
Dim sr As New StreamReader(fs) '读数据
Dim sw As New StreamWriter(fs, System.Text.Encoding.Default) '写数据
Dim ESC2 As String = Chr(27)
Dim GS As String = Chr(29)
Dim LF As String = Chr(10)
Dim SEND As String = ESC2 & "@"
Dim footSpace As String = ""
Try
Dim i As Integer
For i = 0 To My.Settings.NumericUpDownEndTicket
footSpace = footSpace & CRLF
Next
Catch ex As Exception
End Try
SEND = SEND & strOutputData & footSpace & CRLF & CRLF & GS & "V" & Chr(1) '& LF & LF & LF & LF & LF
sw.Write(SEND)
If My.Settings.LOG_LPT Then
Dim log_filename As String = AppPath & "\" & Now.Year & Now.Month & "OrderLogLPT.txt"
My.Computer.FileSystem.WriteAllText(log_filename, strOutputData & Chr(13) & Chr(10), True)
End If
'If cajon Then sw.Write((Chr(27)).ToString() + "p" + (Chr(0)).ToString() + ((Chr(60))).ToString() + ((Chr(255))).ToString()) '''''''开钱箱
sw.Close()
fs.Close()
End If
Catch ex As Exception
MsgBox("没有连接打印机!")
End Try
沒有留言:
張貼留言