Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Compact Framework / April 2006

Tip: Looking for answers? Try searching our database.

Simple Text Printing Using IrDA

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ron Weiner - 19 Apr 2006 19:56 GMT
I am stuck in an application that I am developing using VS 2003 - VB.Net for
a Symbol MC50 PPC2003SE.  The application needs to print to a IrDA printer
(O'Neil Microflash 2t)  and I am having a duce of a time getting something
seemingly so simple to work.  So far I have tried two different methods to
make the connection, and print text, but have failed.  I did download an
application from O'Neil that is able to copy a simple text file to the
printer using the IrDA port so I know that all of the hardware is OK.

The first method I tried was using a reference to System.Net.IrDA  That I
found on Microsoft's site.  Below find the code I try'd.

Private Sub cmdIRSend_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdIRSend.Click
       ' Align the infrared ports of the devices.
       ' Click the Receive button first, then click Send.

       Dim irClient As New IrDAClient
       Dim irServiceName As String = "microFlash2"
       Dim irDevices() As IrDADeviceInfo
       Dim buffersize As Integer = 256

       ' Create a collection of devices to discover.
       irDevices = irClient.DiscoverDevices(2)

       ' Show the name of the first device found.
       If irDevices.Length = 0 Then
           ' <<< This is as far as it gets - Device not found >>>
           MsgBox("No remote infrared devices found.")
           Return
       End If

       Try
           Dim irEndP As New IrDAEndPoint(irDevices(0).DeviceID, _
               irServiceName)
           Dim irListen As New IrDAListener(irEndP)
           irListen.Start()
           irClient = irListen.AcceptIrDAClient()
           MsgBox("Connected!")

       Catch exSoc As SocketException
           MsgBox("Couldn't listen on service " & irServiceName & ": " _
              & exSoc.ErrorCode)
       End Try

       ' Open a file to send and get its stream.
       Dim fs As Stream
       Try
           fs = New FileStream("\\Program Files\ShowTrak\2I_Invoice",
FileMode.Open)
       Catch exFile As Exception
           MsgBox("Cannot open " & exFile.ToString())
           Return
       End Try

       ' Get the underlying stream of the client.
       Dim baseStream As Stream = irClient.GetStream()

       ' Get the size of the file to send
       ' and write its size to the stream.
       Dim length As Byte() = BitConverter.GetBytes(fs.Length)
       baseStream.Write(length, 0, length.Length)

       ' Create a buffer for reading the file.
       Dim buffer(buffersize) As Byte

       Dim fileLength As Integer = CInt(fs.Length)

       Try
           ' Read the file stream into the base stream.
           While fileLength > 0
               Dim numRead As Int64 = fs.Read(buffer, 0, buffer.Length)
               baseStream.Write(buffer, 0, numRead)
               fileLength -= numRead
           End While
           MsgBox("File sent")
       Catch exSend As Exception
           MsgBox(exSend.Message)
       End Try

       fs.Close()
       baseStream.Close()
       irClient.Close()
   End Sub

This above code does make the printer wake up (i.e. turn itself on) but
that's it!  The Msoft example was designed to demonstrate how to transfer a
file between two devices.  I figured that I would only need the Send part.
I guess I figured wrong.

My next attempt was to include a reference to OpenNETCF and use the Serial
communication library.  My first task was to try and find what port that the
MC50 used with the IRDA interface.  So I tried ALL of the ports From Com1:
through Com8:.  The only ports that did not throw an exception were Com3:
(which woke the printer up) and Com5: which did not cause the printer to do
anything.  Armed with this knowledge I am assuming that Com3: is where I
want to spend the rest of my effort.  When I print a Print Comfit from the
printer it shows the following:

Baud Rate     = 19.2K
Parity            = None
Data Bits       = 8
Handshake    = Both

Here is the code I am using to test the Serial Communication:

  Private Sub cmdShowOut_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdShowOut.Click
       Dim OutputData(0) As Byte
       Dim strOut As String, i As Integer
       Dim SerPort As New OpenNETCF.IO.Serial.Port("COM3:")

       With SerPort
           .Settings.BaudRate = OpenNETCF.IO.Serial.BaudRates.CBR_19200
           .Settings.ByteSize = 8
           .Settings.Parity = OpenNETCF.IO.Serial.Parity.none
           .Settings.StopBits = OpenNETCF.IO.Serial.StopBits.one
           .DetailedSettings.OutCTS = False
           .DetailedSettings.OutDSR = False
           .DetailedSettings.DTRControl =
OpenNETCF.IO.Serial.DTRControlFlows.enable
           .DetailedSettings.DSRSensitive = False
           .DetailedSettings.TxContinueOnXOff = False
           .DetailedSettings.InX = False
           .DetailedSettings.OutX = False
           .DetailedSettings.ReplaceErrorChar = False
           .DetailedSettings.DiscardNulls = False
           .DetailedSettings.RTSControl =
OpenNETCF.IO.Serial.RTSControlFlows.enable
           .DetailedSettings.AbortOnError = False
           If .IsOpen = False Then
               .Open()
           End If
           System.Threading.Thread.Sleep(500)  ' Wait for the Printer to
awaken
           strOut = vbCrLf & "Printer Test" & vbCrLf & Chr(12)
           For i = 0 To strOut.Length - 1
               ' Send the bytes down to the Printer
               OutputData(0) = CByte(Asc(strOut.Substring(i, 1)))
               .Output = OutputData
           Next
           System.Threading.Thread.Sleep(500)  ' Wait for the Printer to
finish
           .Close()
       End With
   End Sub

This code also wakes up the printer, but that's it, nothing prints.  I am
starting to loose what little hair I have left over this.  Can anyone help?

Signature

Ron W
www.WorksRite.com

r_z_aret@pen_fact.com - 20 Apr 2006 23:54 GMT
>I am stuck in an application that I am developing using VS 2003 - VB.Net for
>a Symbol MC50 PPC2003SE.  The application needs to print to a IrDA printer
[quoted text clipped - 3 lines]
>application from O'Neil that is able to copy a simple text file to the
>printer using the IrDA port so I know that all of the hardware is OK.

I've made a few unsuccessful attempts to print via IrDA to an O'Neil
printer. It should be simple, so I assume I'm doing something
"stupid". Fortunately, very few of our customers need such support.
And the one customer that really cares is willing to use Printer CE
from Field Software, which I do support. That utility has worked
flawlessly, and Field Software has provided fast, clear, and useful
support the few times I needed it.

>The first method I tried was using a reference to System.Net.IrDA  That I
>found on Microsoft's site.  Below find the code I try'd.
[quoted text clipped - 136 lines]
>This code also wakes up the printer, but that's it, nothing prints.  I am
>starting to loose what little hair I have left over this.  Can anyone help?

-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).

Robert E. Zaret, eMVP
PenFact, Inc.
20 Park Plaza, Suite 478
Boston, MA 02116
www.penfact.com

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.