Console.ReadLine and getqueuestr
Console.ReadLine and getqueuestr
Hi Guys
Am I missing something or is it not possible to use Console.ReadLine on a com port other than Com1?
getqueuestr is not as useful in my application as I want to easily read complete lines terminated by LF.
Cheers
Ben
Am I missing something or is it not possible to use Console.ReadLine on a com port other than Com1?
getqueuestr is not as useful in my application as I want to easily read complete lines terminated by LF.
Cheers
Ben
Re: Console.ReadLine and getqueuestr
The console functions and Debug.Print are restricted to Com1 (the system queues) and are provided as a convenience. You will need to do your own parsing of the data on other COM ports.
Mike Perks
Re: Console.ReadLine and getqueuestr
The function shown below extracts characters from a queue and transfers them to a line accumulation queue. When a linefeed is transferred, the contents of the line accumulation queue is returned as a string and the accumulation queue is cleared. A zero length string is returned on all calls before the linefeed is seen. The downside of this method is that it incurs the additional storage for the line accumulation queue.sturgessb wrote:I want to easily read complete lines terminated by LF.
Code: Select all
Function GetQueueLine(ByRef iq() as Byte, ByRef lq() as Byte) as String
GetQueueLine = ""
Do While (StatusQueue(iq))
Dim b as Byte
Call GetQueue(iq, b, SizeOf(b))
Call PutQueueByte(lq, b)
If (b = &H0a) Then
' extract the accumulated line from the queue and clear it
GetQueueLine = GetQueueStr(lq)
Call ClearQueue(lq)
Exit Do
End If
Loop
End Function
Generally speaking, using code that is dependent on implementation details is not recommended. However, it is unlikely that the details of the queue implementation will change.
Code: Select all
#c
/*
** GetQueueLineLength
*
* This function returns the number of bytes up to and including
* the first linefeed in a given queue. If the queue is empty or
* does not yet contain a linefeed, zero is returned.
*
* Interrupts are disable during the scanning process.
*
*/
uint16_t
GetQueueLineLength(uint8_t *q)
{
uint16_t len = 0;
Queue *qp = (Queue *)q;
if (qp != NULL)
{
uint8_t sreg = SREG;
cli();
uint16_t cnt = qp->cnt;
uint16_t idx = qp->tail;
while (cnt--)
{
if (++idx >= qp->cap)
idx = 0;
if (qp->queue[idx] == 0x0a)
{
// found a linefeed, compute line length
len = qp->cnt - cnt;
break;
}
}
SREG = sreg;
}
return(len);
}
#endc
Declare Function GetQueueLineLength(ByRef q() as Byte) as UnsignedInteger
- Don Kinzer
Re: Console.ReadLine and getqueuestr
This topic got me to thinking that it might be useful to have a function that will search a queue for an arbitrary character, returning the "index" of the first occurrence. The API could be something like this:sturgessb wrote:I want to easily read complete lines terminated by LF.
Code: Select all
Function FindQueue(ByRef q() as Byte, ByVal val as Byte) as UnsignedInteger
- Don Kinzer
Code: Select all
Function GetQueueLine(ByRef iq() as Byte, ByRef lq() as Byte) as String
GetQueueLine = ""
Do While (StatusQueue(iq))
debug.print "1"
Dim b as Byte
debug.print "2"
Call GetQueue(iq, b, SizeOf(b))
debug.print "3"
Call PutQueueByte(lq, b)
debug.print "4"
If (b = &H0a) Then
' extract the accumulated line from the queue and clear it
GetQueueLine = GetQueueStr(lq)
Call ClearQueue(lq)
Exit Do
End If
Loop
End Function
I know that 'b' has a value at that point and the lq queue exists
If I change it so that its saving the data into a string rather than a queue it works, odd.
Cheers
Ben
hmm when i said it worked with string i was jumping the gun a bit, here is the output.
As you can see its bit of a mess, each line should begin with a letter, so it seems im missing data[/code]
Code: Select all
T,1,11.34
C,1412,1590,1522,1540,0,0,0,0
S,443,222,0,28,0
G,0,90.0,0.0,137.0,0,0,0
G,0,90.0,0.0,137.0,0,0,0
.34
C,1412,1590,1522,1540,0,0,0,0
,443,221,0,29,0