Calculator Sample in WCF using VB.Net
--
print /d:COM1 'file path'
type d:\abc.txt > COM1
type d:\abc.txt > lpt1
--
share your network printer, even though you will use it yourself
then use this command
net use lpt1: \\ownpcname\printersharename
now use this command again:
type d:\abc.txt > lpt1
Public Sub SendViaTCP(ByVal whatIP As String, ByVal whatPort As Integer, ByVal whatToSend As String)
Dim tcpSender As TcpClient = New TcpClient()
tcpSender.SendBufferSize = 4096
tcpSender.Connect(whatIP, whatPort)
If tcpSender.Connected = False Then
MessageBox.Show("Not connected")
tcpSender.Close()
Exit Sub
End If
Dim nStream As NetworkStream = tcpSender.GetStream()
If nStream.CanWrite = True Then
Dim SendBytes As [Byte]() = System.Text.Encoding.ASCII.GetBytes(whatToSend)
nStream.Write(SendBytes, 0, SendBytes.Length)
nStream.Flush()
End If
System.Threading.Thread.Sleep(500)
nStream.Close()
tcpSender.Close()
End Sub
--
Function ReceiveSerialData() As String
' Receive strings from a serial port.
Dim returnStr As String = ""
Dim com1 As IO.Ports.SerialPort = Nothing
Try
com1 = My.Computer.Ports.OpenSerialPort("COM1")
com1.ReadTimeout = 10000
Do
Dim Incoming As String = com1.ReadLine()
If Incoming Is Nothing Then
Exit Do
Else
returnStr &= Incoming & vbCrLf
End If
Loop
Catch ex As TimeoutException
returnStr = "Error: Serial Port read timed out."
Finally
If com1 IsNot Nothing Then com1.Close()
End Try
Return returnStr
End Function
Private Sub CheckLeapYear(ByVal Int_Year As Integer)
Dim Boo_LeapYear As Boolean
Boo_LeapYear = Date.IsLeapYear(Int_Year)
If Boo_LeapYear Then
MessageBox.Show(Int_Year & "閏年")
Else
MessageBox.Show(Int_Year & "不是閏年")
End If
End Sub