Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
|
en:bs2_setslavebaudrate [2024/02/16 12:23] mwkim created |
en:bs2_setslavebaudrate [2024/10/23 16:27] (current) mwkim created |
||
|---|---|---|---|
| Line 5: | Line 5: | ||
| ===== BS2_SetSlaveBaudrate ===== | ===== BS2_SetSlaveBaudrate ===== | ||
| - | [+ 2.9.6] Set the baudrate of the slave device in the RS485 network. \\ | + | [+ 2.9.8] Set the RS-485 baud rate of a slave device connected to a master device. \\ |
| + | To reconnect with the slave, the RS-485 baud rate of the master device must also be changed to match the baud rate of the slave. | ||
| ==== Declaration ==== | ==== Declaration ==== | ||
| <code cpp> | <code cpp> | ||
| #include "BS_API.h" | #include "BS_API.h" | ||
| - | int BS2_SetSlaveBaudrate(void* context, BS2_DEVICE_ID deviceId, BS2_DEVICE_ID slaveId, uint32_t baudrate); | + | int BS2_SetSlaveBaudrate(IntPtr context, UInt32 deviceId, UInt32 slaveId, UInt32 baudrate); |
| </code> | </code> | ||
| ==== Parameter ==== | ==== Parameter ==== | ||
| * [In] ''//context//'' : Context | * [In] ''//context//'' : Context | ||
| - | * [In] ''//deviceId//'' : Master device Identifier | + | * [In] ''//deviceId//'' : Device ID |
| - | * [In] ''//slaveId//'' : Slave device Identifier | + | * [In] ''//slaveId//'' : Slave device ID |
| - | * [In] ''//baudrate//'' : The baud rate to be changed | + | * [In] ''//baudrate//'' : RS-485 baud rate |
| ==== Return Value ==== | ==== Return Value ==== | ||
| - | If successfully done, ''BS_SDK_SUCCESS''will be returned. If the slave device is not connected, ''BS_SDK_ERROR_SLAVE_NOT_READY'' will be returned. | + | If successfully done, ''BS_SDK_SUCCESS'' will be returned. \\ |
| - | + | If there is an error, the corresponding error code will be returned. | |
| - | ==== Sample Code(C++) ==== | + | |
| - | + | ||
| - | <file cpp 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); | + | |
| - | } | + | |
| - | </file> | + | |
| - | + | ||
| - | ==== Sample Code(C#) ==== | + | |
| - | <file csharp 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); | + | |
| - | } | + | |
| - | </file> | + | |