Printing a text file from vb.net to serial port quitting after about 56 lines.
Posted on 2006-07-17
I’m using a streamreader to send data from a text file to an old Serial Plate Embosser connected to the computer’s serial port (using Generic Text driver). It reads and sends about 56 lines to the Embosser and then quits. (The files may have anywhere from a few lines to several hundred lines – each one with the data for one serial plate.) It sounds like what would fit on a “page” but that shouldn’t be the case? Any suggestions? Thanks.
We were previously using the computer as a terminal when the program was in VMS-Basic on an DEC/COMPAQ/HP Alpha and didn’t have this problem.
VB.NET 2003 code
Public Sub PrintFile(ByVal filePath as string)
streamToPrint = New StreamReader(filePath)
printFont = New Font(“Courier New”, 12)
dim pd as New PrintDocument
AddHandler pd.PrintPage, AddressOf pd_PrintPage
Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
Dim yPos As Single = 0
Dim leftMargin As Single = 0 'ev.MarginBounds.Left
Dim topMargin As Single = 0 'ev.MarginBounds.Top
Dim line As String = Nothing
' Iterate over the file, printing each line.
line = streamToPrint.ReadLine()
If line Is Nothing Then
yPos = topMargin + count * printFont.GetHeight(ev.Graphics)
ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, New StringFormat)
End Sub 'pd_PrintPage