Showing posts with label Windows Mobile. Show all posts
Showing posts with label Windows Mobile. Show all posts

Tuesday, 17 July 2012

Print from mobile application directly into a network printer

In this article i will explain how we can print a report directly from a mobile application connected through wireless network to the printer, so try the code below.


Dim strPrintData As String = "" 'Contains the string to be printed
Dim DataBytes() As Byte 'Contains the String converted into bytes
Dim PrintedStream AsNetworkStream 'Stream to transmit the bytes to the Network printer
Dim HostIPAddress AsSystem.Net.IPAddress 'IP Address of the Printer
Dim PrinterPort As NewSystem.Net.Sockets.TcpClient 'TCPClient to comunicate
'HostIPAddress = System.Net.IPAddress.Parse("192.168.201.201")
HostIPAddress = System.Net.IPAddress.Parse(dvWarehouseKeepers(0)("PCADDRESS").ToString)

          
          

strPrintData += Chr(27) &"&l1O"
     
strPrintData += "Hello world" & vbCrLf

Dim Unicode As NewSystem.Text.UnicodeEncoding
DataBytes = System.Text.Encoding.ASCII.GetBytes(strPrintData)

'If Not connected then connect
If NotPrinterPort.Client.Connected Then
'Printer Port 9100 for HP JetDirects
PrinterPort.Connect(HostIPAddress, 9100)
End If

PrintedStream = PrinterPort.GetStream
'Send the stream to the printer
 If PrintedStream.CanWriteThen
     PrintedStream.Write(DataBytes, 0, DataBytes.Length)
 End If
'Close the connections
PrintedStream.Close()
PrinterPort.Close()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Happy coding

Monday, 12 March 2012

Windows Mobile set the device date and time


 <DllImport("coredll.dll")> _
   Private Function SetSystemTime(ByRef time As SYSTEMTIME) As Boolean
    End Function


Public Sub setDeviceDateTime(ByVal dt As DateTime)
        Dim ServerTime As New SYSTEMTIME

        ServerTime.Day = dt.ToUniversalTime.Day
        ServerTime.Month = dt.ToUniversalTime.Month
        ServerTime.Year = dt.ToUniversalTime.Year
        ServerTime.Hour = dt.ToUniversalTime.Hour
        ServerTime.Minute = dt.ToUniversalTime.Minute
        ServerTime.Second = dt.ToUniversalTime.Second

        SetSystemTime(ServerTime)
    End Sub
    Public Structure SYSTEMTIME
        Public Year As Short
        Public Month As Short
        Public DayOfWeek As Short
        Public Day As Short
        Public Hour As Short
        Public Minute As Short
        Public Second As Short
        Public Milliseconds As Short
    End Structure