This is an old revision of the document!


Slave Control API > BS2_SetSlaveBaudrate


[+ 2.9.6] Set the baudrate of the slave device in the RS485 network.

Declaration

#include "BS_API.h"
 
int BS2_SetSlaveBaudrate(void* context, BS2_DEVICE_ID deviceId, BS2_DEVICE_ID slaveId, uint32_t baudrate);

Parameter

  • [In] context : Context
  • [In] deviceId : Master device Identifier
  • [In] slaveId : Slave device Identifier
  • [In] baudrate : The baud rate to be changed

Return Value

If successfully done, BS_SDK_SUCCESSwill be returned. If the slave device is not connected, BS_SDK_ERROR_SLAVE_NOT_READY will be returned.

Sample Code(C++)

sample_bs2_setslavebaudrate.cpp
int setSlaveBaudrate(void* context, const DeviceList& devices)
{
	CommControl cm(context);
 
	Utility::displayConnectedDevices(devices, true);
	BS2_DEVICE_ID masterID = Utility::getInput<BS2_DEVICE_ID>("Please enter the master device ID:");
	BS2_DEVICE_ID slaveID = Utility::getInput<BS2_DEVICE_ID>("Please enter the slave device ID:");
 
	string msg = "Please select a baudrate. (9600, 19200, 38400, 57600, 115200)";
	uint32_t baudrate = Utility::getInput<uint32_t>(msg);
 
	return BS2_SetSlaveBaudrate(context_, masterID, slaveID, baudrate);
}

Sample Code(C#)

sample_bs2_setslavebaudrate.cs
public void setSlaveBaudrate(IntPtr sdkContext, UInt32 deviceID, bool isMasterDevice)
{
	List<UInt32> slaveDeviceList = new List<UInt32>();
 
	Console.WriteLine("What slave device will the baudrate be set to?");
	foreach (var slave in searchedSlave)
	{
		Console.WriteLine("    {0} ({1})", slave.Item1, slave.Item2);
	}
	Console.Write(">> ");
	UInt32 slaveID = Util.GetInput((UInt32)0);
	if (0 == slaveID)
		return;
 
	Console.WriteLine("Please select a baudrate. (9600, 19200, 38400, 57600, 115200)");
	Console.Write(">> ");
	UInt32 baudrate = Util.GetInput((UInt32)9600);
 
	Console.WriteLine("Trying to set slave baudrate.");
	BS2ErrorCode result = (BS2ErrorCode)API.BS2_SetSlaveBaudrate(sdkContext, deviceID, slaveID, baudrate);
}