Init(RS232,....)
Description
Initializes RS232 interface for data transfer and monitoring.
Syntax
Init(RS232, speed, word_length, stop_bits, parity);
Parameters
Variable | Input |
|---|---|
| This is serial port data transfer speed in bit/s. Speed (baud rate) can be one of the following: 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 56000, 57600, 115200, 128000 or 256000 |
| This is data size in bits. For example: WORDLENGTH_7 - 7 bit long data packet. Can be: WORDLENGTH_7, WORDLENGTH_8 or WORDLENGTH_9 |
| This number of bits that shows end of a single packet. Can be: STOPBITS_1 or STOPBITS_2 |
| Parity is error detection bit, which show that data is made out of even or odd number of ones. Parity is either - PARITY_NONE, PARITY_EVEN, PARITY_ODD |
Returns
Return value | Return explanation |
SCRIPT_OPERATION_SUCCESS | Success |
SCRIPT_OPERATION_FAILED | Failed |
SCRIPT_NO_ACCESS | Peripheral already initialized. |
SCRIPT_PARAM_INVALID | Passed invalid init parameters. |
Function call example
RS232 initialization example
new string[50];
main(){
Init(RS232, 9600, WORDLENGTH_8, STOPBITS_1, PARITY_NONE);
while(1){
write_buf(RS232, 12 ,"Hello world "); //write some data. See write_buf documentation for more detail
read_buf(RS232, 6, string); //read some data. See read_buf documentation for more detail
Delay(100);
}
}Notes and Warnings
WARNING: Do not initialize RS232 on separate threads. In order to use RS232 on separate threads first do DeInit on thread where it was previously initialized.