串口编程 [英] Serial Port Programming
问题描述
大家好,
我为热敏打印机(EPSON)开发串行端口编程。程序很简单。我将命令发送到直接连接到我的计算机的热敏打印机。并让它打印。虽然第二次可以打印,但第三次打印机无法打印。我尝试了很多次但仍然不能第三次。所以我插上电缆再插上打印机打印第三次结果。
i不知道发生了什么。
请帮助:omg:
我的代码在这里:< br $>
串口BaudRate是9600
DiscardNull False
DtrEnable False
握手无
奇偶校验无
奇偶校验替换63
ReadBufferSide 4096
RtnEnable False
StopBits One
WriteBufferSize 2048
Hi all,
I develop Serial Port programming for Thermal Printer(EPSON). Program is simple. i send the command to thermal Printer that directly connect to my computer. and let it print. Although firt and second time can print, third time the printer cannot print. i tried many time but still cannot for third time. so i plug out cable and plug in again the printer print the third time result.
i don't know what happen.
pls, help :omg:
My Code is here :
Serial BaudRate is 9600
DiscardNull False
DtrEnable False
Handshake None
Parity None
Parity Replace 63
ReadBufferSide 4096
RtnEnable False
StopBits One
WriteBufferSize 2048
Private Sub frmCheckWriteAndRead_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SerialPort1.PortName = "COM5"
SerialPort1.Open()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sendData As String
Dim strResult As String
'Escape character required by ESCPOS code
Dim ESC As String = Chr(27)
'File Separator character required by ESCPOS code
Dim FS As String = Chr(28)
'Group Separator character required by ESCPOS code
Dim GS As String = Chr(29)
'Line feed character required by ESCPOS code
Dim LF As String = Chr(10)
'sendData = Chr(2) & "S23" & Chr(3)
sendData = ESC & "@" & FS & "." & ESC & "!" & Chr(8 + 1) & LF
sendData = sendData & Chr(2) & "S23" & Chr(3)
sendData = sendData & "dsfasdfasdfasdfasdfasdfasdfasdf" & LF
sendData = sendData & "sdfasdfasdfasdfasdfasdfasdfasdfa" & LF
sendData = sendData & "sdfasdfasdfasdfasdfasdfasdfasdf" & LF
sendData = sendData & LF & LF & GS & "V" & Chr(0) & GS & "r" & Chr(1)
SerialPort1.WriteLine(sendData)
strResult = SerialPort1.ReadExisting()
Me.Text = strResult
End Sub
推荐答案
我会说你的代码坏了。不确定你还想听到什么。听起来你的代码没有做它应该做的事情,并且以某种方式断开连接,直到你通过断开打印机重置它。
没有人能给你一个破解代码的真正解决方案,无需查看代码。
I'd say that your code is broken. Not sure what else you'd like to hear. Sounds like your code doesn't do what it should, and somehow breaks the connection until it's reset by your disconnecting the printer.
There's no way anyone can give you a real solution to your broken code, without seeing the code.
我在代码中看不到端口初始化。
对于你的串口参数:
- 字大小缺少值通常为7或8位。
- 这不是传统的参数。
I don't see port initialisation in your code.
For you serial port parameters:
- The word size is missing the value is usually 7 or 8 bits.
- and this is not traditional parameter.
奇偶校验替换63
如果打印机给你一个消息的答案,你必须等待答案,串口通讯很慢。
你应该用一台带终端仿真的电脑更换你的打印机看看你的打印机正在接收什么。
回到DOS的时候,我使用了一个名为Breakout的特殊软件,带有一个特殊的电缆enabl监视双向通信,包括信号。
查看打印机手册以确保使用正确的com参数。
If the printer gives you an answer for your message, you have to wait for the answer, serial communication is slow.
You should replace your printer with a computer with terminal emulation in order to see what your printer is receiving.
Back in the time of DOS, I was using a special software named "Breakout" with a special cable enabling to spy the bi-directional communication, including signals.
Look at printer manual to ensure you are using the right com parameters.
这篇关于串口编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!