IDK MSD-804FD Series Command Manual page 8

Presentation switcher
Hide thumbs Also See for MSD-804FD Series:
Table of Contents

Advertisement

Example of programing with Microsoft Visual Basic.NET 2008
1:
Imports System
2:
Imports System.Net.Sockets
3:
Public Class Form1
4:
Private stClient As TcpClient
5:
Private stns As System.Net.Sockets.NetworkStream 'Stream
6:
Public Function mOpen(ByVal pHostName As String, ByVal pPortNum As Integer) As
Boolean
7:
'********************************************************
8:
'
Open
9:
'
Return value
10:
'********************************************************
11:
mOpen = False
12:
Try
13:
'Opening Client
14:
stClient = New System.Net.Sockets.TcpClient(pHostName, pPortNum)
15:
stClient.NoDelay = True
16:
stns = stClient.GetStream()
17:
If stns.CanTimeout Then
18:
19:
End If
20:
mOpen = True
21:
Catch ex As Exception
22:
Console.WriteLine(ex.Message)
23:
End Try
24:
25: End Function
26: Private Function mSendMessege(ByVal pMsg As String) As String
27:
'********************************************************
28:
'
Sending message
29:
'
pMsg
30:
'
Return value
31:
'********************************************************
32:
Dim dtBirth As DateTime
33:
Dim wNow As DateTime
34:
Dim pRecvMsg As String
35:
Dim bytes2(1024) As Byte
36:
Dim bytesRead1 As Integer
37:
Dim word As Byte() 'Store area for temporary written data at the time of system output
38:
39:
mSendMessege = "" 'Return value Clear
40:
pRecvMsg = "" 'Work Area Clear
41: :
42:
Try
43:
'----Transmit Checking----
44:
If stns.CanWrite Then
45:
46:
47:
48:
49:
Else
50:
51:
End If
52:
53:
'----Receive----
54:
dtBirth = DateTime.Now
55:
dtBirth = dtBirth.AddSeconds(3)
56:
Do
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
Succed: True Fail: False
stns.ReadTimeout = 1000
sending message
Returned Charactor
'Return message temporally store area (Byte type)
'Return message temporally store area (Integer type)
'character encode
word = System.Text.Encoding.Default.GetBytes (pMsg + vbCrLf)
'Output to socket
stns.Write(word, 0, word.Length)
Exit Function
wNow = DateTime.Now
If (wNow > dtBirth) Then
Exit Do
'Stop process when it exceeds the set time (time out)
End If
If stns.CanRead Then
'Read data
bytesRead2 = stns.Read(bytes2, 0, bytes2.Length)
'Encode
pRecvMsg = pRecvMsg & _
System.Text.Encoding.Default.GetString(bytes2, 0, bytesRead2)
If pRecvMsg <> "" Then
MSD-804FD Users Guide (Command Guide)
'Client
'Initial Value
'Invalid transmit / receive delay
'Open stream
'Time out (1000ms)
'Succeed
'Displaying unsual process
'Time out
'Current time
'Return message
'Be able to write?
'Time out after 3 sec.
'Compare to current time
'When readable
8

Advertisement

Table of Contents
loading

Table of Contents