Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
en:software:devices:sercom [2017/01/04 16:36] – [6.2. Ricezione di una stringa] qem103 | en:software:devices:sercom [2020/07/13 15:00] (current) – qem103 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== DEVICE SERCOM ====== | ||
+ | |||
+ | |||
+ | ====== - Introduction ====== | ||
+ | |||
+ | The SERCOM device is a tool established in the CPU that allows to transmit and receive data via serial communication ports. The received data are stored in a buffer of adjustable size. Also receiving can be adjusted automatically by the application of the XON-XOFF protocol. To transmit data using fixed memory area formed by 64 byte. Since that receive and send buffers are different, you can create a shortcut both Half-Duplex and Full-Duplex links.\\ | ||
+ | Using the capabilities of the low level of this device you can implement in your QCL code the highest level communication protocol allowing serial communication with different equipment (example: bar-code reader, linear position sensors with serial data transmission, | ||
+ | |||
+ | |||
+ | ===== - Installation ===== | ||
+ | |||
+ | ==== - Device declaration in the configuration file (.CNF) ==== | ||
+ | |||
+ | Declaration of the used device (internal device): device name assigned, SERCOM, sampling time, serial port, size of receive buffer. | ||
+ | |||
+ | <code QCL> | ||
+ | ; | ||
+ | ;Internal device declaration | ||
+ | ; | ||
+ | INTDEVICE | ||
+ | ... | ||
+ | < | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | Where: | ||
+ | |INTDEVICE|is a keyword indicating the beginning of the definition of internal devices,| | ||
+ | |< | ||
+ | |SERCOM|is the keyword that identifies the device described in this document,| | ||
+ | |TCamp|is the sampling time of the device,| | ||
+ | |serial_port|is the definition of the type of serial port connected (0 = Prog, 1 = User, the ID\\ number of the other serial portsdepends on the hardware and firmware of the instrument used).| | ||
+ | |dim_buffer_rx|is the number of bytes to use for the receive circular buffer. If the number\\ is omitted from the X character, or is less than the minimum of 48,\\ It is set to the minimum value. The maximum value allowed is 32000.| | ||
+ | |||
+ | The Declaration of the hardware used in the " | ||
+ | <code QCL> | ||
+ | Example | ||
+ | ; | ||
+ | ;Internal device declaration | ||
+ | ; | ||
+ | INTDEVICE | ||
+ | ... | ||
+ | DevSer | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== - Receive and send buffer ===== | ||
+ | |||
+ | The receive and transmit buffers are distinguished, | ||
+ | |||
+ | ==== - Receive buffer ==== | ||
+ | |||
+ | The receive buffer is a memory FIFO type (First Input First Output). The device provides a parameter (ibyte1 ), in response to a command (RECEIVED), the first data received. There is also a parameter that contains the number of received data and in the buffer ( nrx ). With this informations it is easy to write a program in QCL which might " | ||
+ | The buffer is " | ||
+ | The receive buffer size can be set in the configuration file at the time of the device declaration. It's important to correctly adjust the receive buffer to prevent the data loss. For example, if a instrument normally broadcasts a 100 characters string and the buffer has a capacity to store 50 characters, or stops the transmission of the string or you lose the data. If the transmitter instrument manages the XON-XOFF protocol the device interrupts its transmission by sending the XOFF character, reactivating the XON character when buffer space is freed. | ||
+ | |||
+ | ==== - Transmission buffer ==== | ||
+ | |||
+ | The transmit buffer is fixed-size. It is composed from variables "// | ||
+ | |||
+ | ==== - Flow control ==== | ||
+ | |||
+ | The device uses a software flow control, composed from send/ | ||
+ | The threshold of //XOn// and //XOff// are respectively set by the parameters: //xonlim// and // | ||
+ | |||
+ | |||
+ | ===== - Commands and parameters table ===== | ||
+ | |||
+ | ==== - Symbols used ==== | ||
+ | |||
+ | The parameter name, condition or command is shown back to the left side of the table. | ||
+ | |||
+ | **R**\\ | ||
+ | Indicates if its parameter or state is retentive (upon initialization of the device maintains the previously defined state), or the state assumes upon initialization of the device.\\ If the device does not require initialization the " | ||
+ | R = Retentive\\ | ||
+ | 0 = Upon initialization of the device the value is forced to zero.\\ | ||
+ | 1 = Upon initialization of the device the value is forced to one.\\ | ||
+ | - = Upon initialization of the device is presented significant value. | ||
+ | |||
+ | **D**\\ | ||
+ | Indicates the size of the parameter.\\ | ||
+ | F = Flag\\ | ||
+ | B = Byte\\ | ||
+ | W = Word\\ | ||
+ | L = Long\\ | ||
+ | S = Single Float | ||
+ | |||
+ | === - Conditions === | ||
+ | |||
+ | Describes all the conditions necessary so that the parameter is considered correct or because the command is accepted.\\ | ||
+ | In some cases, limit values are specified for the acceptance of the parameter: if introduced any values outside the limits set, the data is however accepted; therefore appropriate controls of the application must be provided to ensure the proper functioning.\\ | ||
+ | For the execution of a command, all conditions must be met; otherwise the command does not executed. | ||
+ | |||
+ | **A**\\ | ||
+ | Indicates the access mode.\\ | ||
+ | R = Read.\\ | ||
+ | W = Write.\\ | ||
+ | RW = Read / Write. | ||
+ | |||
+ | ==== - Commands ==== | ||
+ | |||
+ | The available commands to manage the device are listed under the priority order descending. The device executes all commands received within the same sampling time starting from the one with the highest priority. For example if the device receives the same sampling time CLOSECOM and OPENCOM commands, first execute the OPENCOM command and than CLOSECOM command leaving the communication port closed. | ||
+ | |||
+ | ^ Name ^ D ^ R ^ A ^ Conditions | ||
+ | | OPENCOM | ||
+ | | CLOSECOM | ||
+ | | SEND | / | / | / | ntx > 0\\ st_opencom = 1 | **Send**\\ Send the composite string in the transmission buffer for the number of characters set in the " | ||
+ | | RECEIVED | ||
+ | | FLUSH | ||
+ | | CLRWDATA | ||
+ | | CLRWCMD | ||
+ | |||
+ | ==== - Parameters ==== | ||
+ | |||
+ | ^ Name ^ D ^ R ^ A ^ Conditions | ||
+ | | mode | B | R | RW | - | **Mode**\\ Defines the operating mode of the device as:\\ **0** = Normal, without the flow control\\ **1** = Software flow control (Xon - Xoff)\\ **2** = A special mode to speed up the extraction of characters from the buffer. The command RECEIVED the characters received are presented in the obyte1÷64 parameters instead of the ibyte parameter. This new mode does not support the XO-XOFF (then resumes operation of mode 0).\\ Valid range: 0 ÷ 2.\\ N.B.: changing the operating mode, | ||
+ | | brate | L | R | RW | - | **Baud rate**\\ Serial baud rate.\\ Valid values: 4800, 9600, 19200, 38400, 57600. | ||
+ | | datab | B | R | RW | - | **Data bit** Valid values: 7, 8 | | ||
+ | | stopb | B | R | RW | - | **Stop bit** Valid values: 1, 2 | | ||
+ | | par | B | R | RW | - | **Parity** (0 ÷ 2)\\ **0** = none,\\ **1** = even,\\ **2** = odd. | | ||
+ | | xonlim | ||
+ | | xofflim | ||
+ | | ntx | W | 0 | RW | - | **Number Trasmitted Bytes** (1 ÷ 64)\\ It is the number of characters to be sent with the SEND command. | ||
+ | | nrx | W | 0 | R | ||
+ | | ibyte1 | ||
+ | | obyte1÷64 | ||
+ | | err | ||
+ | | serr | - | - | - | - | **Serial Errors**\\ Indicates if errors occurred in serial communication.\\ The parameter is updated for each error encountered.\\ The value persists until a subsequent error or to a writing on the same with the QCL.\\ **0** = no errors\\ **1** = parity error\\ **2** = framing error\\ **3** = overrun error | | ||
+ | | st_sended | ||
+ | | st_rxoff | ||
+ | | st_txoff | ||
+ | | wdata | F | 0 | R | ||
+ | | wcmd | F | 0 | R | ||
+ | | st_opencom | ||
+ | |||
+ | |||
+ | ===== - Limitations ===== | ||
+ | |||
+ | The following is a list of some limitations on the use of SERCOM device: | ||
+ | * You cannot use the device with the systems that control the time-out between characters, if the length of the message to be transmitted exceeds the size of the transmit buffer; between the sending of the first 64 bytes, and the next, the QCL should intervene to rewrite the transmit buffer. | ||
+ | * The maximum speed is 57600 baud, the minimum is 4800; | ||
+ | * If the connection is made to systems that use flow controls other than XOn/XOff, you must implement the control itself using the QCL. If systems use a hardware flow control, they aren't linkable; | ||
+ | * If the connection is made towards systems in a daisy-chain where each component execute the echo of received characters, you must be attention to the propagation speed of the data because the echo function should be performed using the QCL. | ||
+ | * Not all combinations of values of DataBits, StopBits and ParityBit parameters are enable. If you use a combination of not enabled values, When you try to open the serial port using the OPENCOM command the device generates a warning command. | ||
+ | Below is a diagram of the combinations: | ||
+ | |||
+ | ^ ^DataBits^StopBits^ParityBit^ | ||
+ | |Combinations May Not Work|7|1|0| | ||
+ | |:::|7|1|1| | ||
+ | |:::|7|1|2| | ||
+ | |:::|7|2|0| | ||
+ | |:::|7|2|1| | ||
+ | |:::|7|2|2| | ||
+ | |:::|8|2|0| | ||
+ | |:::|8|2|1| | ||
+ | |:::|8|2|2| | ||
+ | |||
+ | |||
+ | ===== - Application example ===== | ||
+ | |||
+ | The following are some examples of how to use the device.\\ | ||
+ | In the examples the device will be DevSer. | ||
+ | |||
+ | ==== - Transmission of a string ==== | ||
+ | |||
+ | Transmission of a control string in ASCII format to a instrument series DIN HB237.04A. | ||
+ | |||
+ | The string to be transmitted is: **{13QL1234561000@** | ||
+ | |||
+ | The code you have to write is as follows: | ||
+ | <code QCL> | ||
+ | DevSer:mode = 0 | ||
+ | ... | ||
+ | address = 13 | ||
+ | quota = 123456 | ||
+ | ... | ||
+ | DevSer: | ||
+ | tmp = address | ||
+ | tmp1 = tmp / 10 | ||
+ | DevSer: | ||
+ | tmp = tmp - (tmp1 * 10) | ||
+ | DevSer: | ||
+ | DevSer: | ||
+ | DevSer: | ||
+ | tmp = quota | ||
+ | tmp1 = tmp / 100000 | ||
+ | DevSer: | ||
+ | tmp = tmp - (tmp1 * 100000) | ||
+ | tmp1 = tmp / 10000 | ||
+ | DevSer: | ||
+ | tmp = tmp - (tmp1 * 10000) | ||
+ | tmp1 = tmp / 1000 | ||
+ | DevSer: | ||
+ | tmp = tmp - (tmp1 * 1000) | ||
+ | tmp1 = tmp / 100 | ||
+ | DevSer: | ||
+ | tmp = tmp - (tmp1 * 100) | ||
+ | tmp1 = tmp / 10 | ||
+ | DevSer: | ||
+ | tmp = tmp - (tmp1 * 10) | ||
+ | DevSer: | ||
+ | DevSer: | ||
+ | DevSer: | ||
+ | DevSer: | ||
+ | DevSer: | ||
+ | DevSer: | ||
+ | |||
+ | DevSer:ntx = 16 ; sets the send of 16 characters | ||
+ | |||
+ | SEND DevSer | ||
+ | WAIT DevSer: | ||
+ | </ | ||
+ | |||
+ | ==== - Receiving a string ==== | ||
+ | |||
+ | Receiving a string from an HB237.04A instrument in ASCII format and executing the echo of each character received. | ||
+ | |||
+ | The string to be received is: **[13RS123456123456@** | ||
+ | |||
+ | The code you have to write is: | ||
+ | <code QCL> | ||
+ | DevSer:mode = 0 | ||
+ | sequence = 0 | ||
+ | ... | ||
+ | WAIT DevSer: | ||
+ | RECEIVED DevSer | ||
+ | DevSer: | ||
+ | DevSer:ntx = 1 ; sets of 1 character sending | ||
+ | SEND DevSer | ||
+ | IF sequence EQ 0 | ||
+ | IF DevSer: | ||
+ | address = 0 | ||
+ | sequence = 1 | ||
+ | ENDIF | ||
+ | ENDIF | ||
+ | IF sequence EQ 1 | ||
+ | address = DevSer: | ||
+ | sequence = 2 | ||
+ | ENDIF | ||
+ | IF sequence EQ 2 | ||
+ | address = address + DevSer: | ||
+ | IF address EQ 13 ; check address value | ||
+ | sequence = 3 | ||
+ | ELSE | ||
+ | sequence = 0 | ||
+ | ENDIF | ||
+ | ENDIF | ||
+ | ... | ||
+ | WAIT DevSer: | ||
+ | </ | ||
+ | |||