Chapter 13
// Uncomment one of these lines to indicate the method of controlling the RS-485
// driver-enable line.
private bool softwareDriverEnable = true; // software control
//private bool softwareDriverEnable = false; // hardware control
private bool driverDisable;
private void Send_Command( string node, string command, string address, string data )
{
string dataSent = null;
string response = null;
// Define LF as the NewLine character for serial data.
myComPort.NewLine = System.Convert.ToString((char)10);
if (softwareDriverEnable)
{
Rs485DriverEnableControl(true);
}
// Write a command to the serial port.
myComPort.WriteLine( ":" + node + command + address + data );
if (softwareDriverEnable)
{
// Read back what was transmitted to ensure that all of the data goes out.
// Then disable the RS-485 driver.
// The RS-485 transceiver's receiver must be permanently enabled
// in hardware.
dataSent = myComPort.ReadLine();
Rs485DriverEnableControl(false);
}
// Read and decode the response.
response = myComPort.ReadLine( );