Private driverDisable As Boolean
' Uncomment one of these lines to indicate the method of controlling the RS-485
' driver-enable line.
Private softwareDriverEnable As Boolean = False ' software control
'Private softwareDriverEnable As Boolean = True ' hardware control
Private Sub Send_Command(ByVal node As String, ByVal command As String, _
ByVal address As String, ByVal data As String)
Dim dataSent As String
Dim response As String
' Define LF as the NewLine character for serial data.
myComPort.NewLine = System.Convert.ToString((char)10)
If softwareDriverEnable Then
Rs485DriverEnableControl(True)
End If
' Write a command to the serial port.
myComPort.WriteLine(":" + node + command + address + data)
An RS-485 Network
289
If softwareDriverEnable Then
' Read back what was transmitted to ensure that all of the data
' has gone out.
' Then disable the RS-485 driver.
' The RS-485 transceiver's receiver must be permanently enabled
' in hardware.
dataSent = myComPort.ReadLine()
Rs485DriverEnableControl(False)
End If
' Read and decode the response.
response = myComPort.ReadLine()
If response.StartsWith(":") Then
If response.Substring(1, 1) = node Then
Select Case command
Case "1"
' write_byte command
Console.WriteLine _
("write_byte command acknowledged.")
Case "2"
' read_byte command. Display the received data.
Console.WriteLine("read_byte response data: " + _
response.
Pages:
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313