문서의 이전 판입니다!


Slave Control API > BS2_SetSlaveBaudrate


[+ 2.9.6] RS485 네트워크에서 슬레이브 장치의 baudrate을 변경합니다.

함수

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

파라미터

  • [In] context : Context
  • [In] deviceId : 마스터 장치 식별자
  • [In] slaveId : 슬레이브 장치 식별자
  • [In] baudrate : 변경할 baudrate

반환값

성공적으로 변경했을 경우 BS_SDK_SUCCESS를 반환하고, 슬레이브 장치가 연결되어 있지 않은 경우 BS_SDK_ERROR_SLAVE_NOT_READY를 반환합니다.

샘플코드(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);
}

샘플코드(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);
}