'USART settings for USART1
#define USART_BAUD_RATE 9600
#define USART_TX_BLOCKING
#define USART_DELAY OFF
Explanation:
HSerPrintList sends two or more values in a single statement, instead of writing one HSerPrint call per value. Each value can be a string, integer, long, word or byte, and each is sent using the matching typed HSerPrint call, in the order given, to the default comport. Because the compiler expands the list into ordinary HSerPrint calls, mixing types in one statement — a string, then a byte, then a word, and so on — works exactly as if each value had been sent with its own HSerPrint statement.
HSerPrintList does not send any new line characters. As with HSerPrint, follow the statement with HSerPrint 13 and HSerPrint 10 if the receiving terminal needs a new line.
An optional leading [comport] argument sends every value in the list to that comport instead of the default. comport must be a number or a defined constant, and a comma must follow the closing ] - HSerPrintList [2] a, b (no comma) is rejected with a compile error rather than silently accepted. Internally this passes the comport straight through to HSerPrint’s own existing comport parameter on each expanded call (HSerPrint value, comport), so HSerPrintList [2], a, b is exactly equivalent to writing HSerPrint a, 2 and HSerPrint b, 2 by long hand. This type comport argument is not available on Ser1PrintList, Ser2PrintList or Ser3PrintList, since a software-serial channel has no comport to select.
Note
The compiler merges a repeated, identical comport setup across consecutive expanded calls, so HSerPrintList [2], a, b, c only sets the comport once in the generated code rather than once per value (PIC and AVR both). This optimisation is automatically disabled for the whole program if it defines an Interrupt sub, since an interrupt could otherwise fire between two calls and change the comport for its own purposes without the compiler being able to see that from this code alone.
Example:
#chip 16F877A, 20
#define USART_BAUD_RATE 9600
#define USART_TX_BLOCKING
#define USART_DELAY OFF
Dim Txt_Heading As String * 12 = "Send North"
Dim SignalLevel As Byte = 87
Dim SampleCount As Word = 4213
Do
HSerPrintList "{STAT,", Txt_Heading, ",", SignalLevel, ",", SampleCount, "}", 13, 10 ' <<< the HSerPrintList instruction
Wait 1 s
Loop
Key line: the single HSerPrintList call above sends a string literal, a string variable, another string literal, a byte, another string literal, a word, a closing brace and a CR/LF pair — nine values in total — as nine typed HSerPrint calls, without writing any of them out by hand.
A new way to optimise sending lots of serial instructions avaliable in build 1651.
Syntax:
Enabling Constants:
The same enabling constants as HSerPrint apply.
Explanation:
HSerPrintList sends two or more values in a single statement, instead of writing one HSerPrint call per value. Each value can be a string, integer, long, word or byte, and each is sent using the matching typed HSerPrint call, in the order given, to the default comport. Because the compiler expands the list into ordinary HSerPrint calls, mixing types in one statement — a string, then a byte, then a word, and so on — works exactly as if each value had been sent with its own HSerPrint statement.
HSerPrintList does not send any new line characters. As with HSerPrint, follow the statement with HSerPrint 13 and HSerPrint 10 if the receiving terminal needs a new line.
An optional leading [comport] argument sends every value in the list to that comport instead of the default. comport must be a number or a defined constant, and a comma must follow the closing ] - HSerPrintList [2] a, b (no comma) is rejected with a compile error rather than silently accepted. Internally this passes the comport straight through to HSerPrint’s own existing comport parameter on each expanded call
(HSerPrint value, comport), soHSerPrintList [2], a, bis exactly equivalent to writingHSerPrint a, 2andHSerPrint b, 2by long hand. This type comport argument is not available on Ser1PrintList, Ser2PrintList or Ser3PrintList, since a software-serial channel has no comport to select.Note
The compiler merges a repeated, identical comport setup across consecutive expanded calls, so
HSerPrintList [2], a, b, conly sets the comport once in the generated code rather than once per value (PIC and AVR both). This optimisation is automatically disabled for the whole program if it defines an Interrupt sub, since an interrupt could otherwise fire between two calls and change the comport for its own purposes without the compiler being able to see that from this code alone.Example:
Key line: the single HSerPrintList call above sends a string literal, a string variable, another string literal, a byte, another string literal, a word, a closing brace and a CR/LF pair — nine values in total — as nine typed HSerPrint calls, without writing any of them out by hand.
Example with a comport:
Key line: every value in the HSerPrintList call is sent to comport 2 (via the MyPort constant), instead of the default comport.
A really good example of the HSerPrintList capability.
Last edit: Anobium 1 hour ago