meenbombs wrote:Well, I don't understand LF vs CR.
The ASCII codes &H0d and/or &H0a are often used, either individually or in combination, to signify an "end of line" or "end of command", etc.. They are often referred to as CR (Carriage Return) and LF (Line Feed), respectively. Different computer system recognize one or more combinations as a valid EOL indicator. For example, traditional DOS applications recognize
only CR followed by LF and they typically get confused or malfunction if only one of these codes appears in their input stream. In contrast, Unix and Linux systems have traditionally recognized LF as the EOL. Older Unix/Linux applications would typically get confused if the CR-LF combination was used but newer applications, especially Linux apps) are tolerant of the CR LF combination being used as the EOL. To add to the confusion, Mac applications (prior to OS X) traditionally recognized CR as the EOL character and would get confused by CR-LF or LF sequences.
When you're sending data to an external device such as the Vmusic2, you have to read its specifications to discover which line endings it recognizes and tolerates. I'm fairly certain that CR in Basic Stamp code is merely a predefined constant equal to 13 (i.e. &H0d). That leads me to believe that the Vmusic2 recognizes CR as an end-of-command character. It may or may not tolerate the presence of an LF following the CR.
meenbombs wrote:How do you break them apart? I had seen CR in the Stamp code and assumed Carriage return. I saw the CRLF in your code and assumed it was the ZX equivilent of CR in Stamp code.
CR and LF are individual character codes just as the codes "A" and "B" are. In the example code that I provided, I defined a string constant called "crlf" that consisted of the character codes for CR and LF. It would have been better, perhaps, to have defined a string constant called eolStr which could then be defined in one of the following ways depending on what is needed.
Code: Select all
' uncomment *one* of the three lines below to choose the appropriate EOL string
Const eolStr as String = Chr(&0d)
'Const eolStr as String = Chr(&H0a)
'Const eolStr as String = Chr(&H0d) & Char(&H0a)
meenbombs wrote:What is the difference between using writeline and the putqueue?
The PutQueue() and PutQueueStr() subroutines simply insert data into a queue. What happens to the data after that depends on how the queue is being used (more on this shortly). The Console.WriteLine() and Debug.Print methods are used to output information
exclusively to Com1.
A queue is one of the fundamental data structures used in programming. It is a generalised mechanism providing a data interface between a
producer of data and a
consumer of that data. The producer deposits data in the queue and then goes about other business. The consumer extracts data from the queue as it needs it. One defining characteristic of a queue is that it is a "first in, first out" (FIFO) mechanism. This means that the consumer gets the data in the order that it was placed in the queue by the producer.
Queues are used for the serial I/O channels in ZBasic because it allows an application to generate output data, place it in the output queue, and then go do other things while the data is being transmitted. In this case, your application is the producer and the serial channel is the consumer of the data. The input queue operates in reverse. When new data arrives on the serial receive line, the serial channel control code places that data in the associated input queue. When your application is ready for data, it checks the input queue and retrieves what it needs.
This is in stark contrast to the Basic Stamp where you must be sitting at a SERIN command when data arrives or you'll never see it. Similarly, when you use SEROUT, your program effectively halts until the the last character to be sent is on its way.