write_buf()
Description
Write data to selected peripheral.
Syntax
write_buf(id, length, source[]);
In case SMS id was used, then syntax looks like so:
write_buf(id, length, phone_number, source[]);
Parameters
Variable | Input |
|---|---|
| Sensor_STRING1 - Write data into Sensor_STRING1. Sensor_STRING2 - Write data into Sensor_STRING2. Sensor_STRING3 - Write data into Sensor_STRING3. Sensor_STRING4 - Write data into Sensor_STRING4. RS232 - Writes data into RS232 peripheral. RS485 - Writes data into RS485 peripheral. SMS - Sends SMS message. Kline - Writes data into one wire peripheral. |
| Number of data bytes to be sent/written in (decimal number). |
| This variable only applies for SMS ID. This is where you should write phone number into which data will be sent. |
| Data which will be written to sensor or peripheral. |
Returns
Return value | Return explanation |
SCRIPT_OPERATION_SUCCESS | Success |
SCRIPT_OPERATION_FAILED | Failed |
SCRIPT_NO_ACCESS | Peripheral not initialized. |
SCRIPT_PARAM_INVALID | Passed parameters invalid. |
Function call example
Example of writing to RS232 buffer
new rs[10] = ''IN4 //use double single commas for writing string into buffer
main()
{
Init(RS232, 9600, WORDLENGTH_8, STOPBITS_1, PARITY_NONE);
while(1)
{
if(get_val(Sensor_SignalIN4) == 0)
{
write_buf(RS232, 7 ,"IN4 OFF"); //write 7 bytes of data to RS232 by writing directly
}
if(get_val(Sensor_SignalIN4) == 1)
{
write_buf(RS232, 6 ,rs); //write 6 bytes of data to RS232 by writing via preset array
}
Delay(1000); // Delay 1 sec.
}
}Notes and Warnings
Please do use double single commas (' and ') instead of single double comma (") for writing string into peripheral. If used single double comma, then data might get corrupted.