PutQueueStr Question
PutQueueStr Question
I've checked the docs & can't find an answer to this.
When using PutQueueStr, if the string contains Chr(13) (Carriage Return) will that automagically terminate the output, even though there are more characters in the string? My testing indicates that this is true, but I might be missing something.
If so, what method or work around is there? The application I am working on requires me to be able to include Carriage Return, Linefeed, and Null in the strings (it's a long story).
Thanks.
Mike
When using PutQueueStr, if the string contains Chr(13) (Carriage Return) will that automagically terminate the output, even though there are more characters in the string? My testing indicates that this is true, but I might be missing something.
If so, what method or work around is there? The application I am working on requires me to be able to include Carriage Return, Linefeed, and Null in the strings (it's a long story).
Thanks.
Mike
Re: PutQueueStr Question
No. The entire string is sent to the queue irrespective of its content.iamajoat wrote:When using PutQueueStr, if the string contains Chr(13) (Carriage Return) will that automagically terminate the output, even though there are more characters in the string?
I have never observed such behavior nor has it been reported here. Can you produce a simple test case that demonstrates the problem you have observed?iamajoat wrote:My testing indicates that this is true.
The test case below demonstrates that CR, LF and null are treated like any other character.
Code: Select all
Sub Main()
Dim q(1 to 40) as Byte
Dim s as String
Call OpenQueue(q, SizeOf(q))
Debug.Print "Before, the queue has "; GetQueueCount(q); " bytes."
s = "abc" & Chr(&H0d) & Chr(&H0a) & Chr(0) & "def"
Call foo(q, s)
Debug.Print "After, the queue has "; GetQueueCount(q); " bytes."
Debug.Print "The string has "; Len(s); " bytes."
End Sub
Private Sub foo(ByRef q() as Byte, ByVal s as String)
Call PutQueueStr(q, s)
End Sub
- Don Kinzer
Re: PutQueueStr Question
Don,
Thanks for the reply.
I ran the code you provided (with a few mods)
and got the following results:
Before, the queue has 0 bytes.
abc
[NUL]def
After, the queue has 0 bytes.
The string has 9 bytes.
So it is working in your example. Here's a piece of what I'm working on:
and the output I get:
ZBasic v2.3
UTUTUTUTUTUTUTUTUTUT
Velocimeter Simulator Complete
It appears that my code should be working, but I can't figure out why it isn't.
Mike
Thanks for the reply.
I ran the code you provided (with a few mods)
Code: Select all
Sub Main()
Dim q(1 to 40) as Byte
Dim s as String
Call OpenQueue(q, SizeOf(q))
Debug.Print "Before, the queue has "; CStr(GetQueueCount(q)); " bytes."
s = "abc" & Chr(&H0d) & Chr(&H0a) & Chr(0) & "def"
Call foo(q, s)
Debug.Print "After, the queue has "; CStr(GetQueueCount(q)); " bytes."
Debug.Print "The string has "; CStr(Len(s)); " bytes."
End Sub
Private Sub foo(ByRef q() as Byte, ByVal s as String)
Call OpenCom(1,19200,0,q)
Call PutQueueStr(q, s & Chr(13))
End Sub
Before, the queue has 0 bytes.
abc
[NUL]def
After, the queue has 0 bytes.
The string has 9 bytes.
So it is working in your example. Here's a piece of what I'm working on:
Code: Select all
Public Const velSuffix as String = Chr(13) & Chr(10) & Chr(0) & Chr(0) & Chr(62)
Public Const EndVelHdr as String = Chr(13) & Chr(10) & Chr(0) & Chr(0)
Public Const strMT101 as String = "UT" & EndVelHdr & "MEASURE UNIT FEET/SEC " & velSuffix
Sub Main()
Dim strGMCP as String 'holder for messages from/to GCS OP
Dim queueCount as Integer 'counter to check for input
Dim n as Integer 'counter to get out of the no comms loop
Dim inQueue(1 to 16) as Byte 'queue for input, max of 7 plus 9 for overhead
Dim outQueue(1 to 44)as Byte 'queue for output, max of 35 plus 9 for overhead
' make sure everything is empty/zeroed out
strGMCP = ""
queueCount = 0
n = 0
Call OpenQueue(inQueue, SizeOf(inQueue))
Call OpenQueue(outQueue, SizeOf(outQueue))
Call ClearQueue(inQueue)
Call ClearQueue(outQueue)
Call OpenCom(1,19200,inQueue,outQueue) 'change to 9600 later
Do While queueCount = 0
'if we are here, we are standalone mode
queueCount = GetQueueCount(inQueue)
If queueCount > 0 Then
Exit Do
End If
Delay(1.0)'change to ten seconds later
strGMCP = strMT101
Call PutQueueStr(outQueue,strGMCP)
Call ClearQueue(outQueue)
strGMCP = ""
n = n + 1
if n = 10 Then 'change to higher value later
Exit Do
End If
Loop
' If queueCount > 0 Then
'if we are here the GCS OP sent us something
' strGMCP = GetQueueStr(inQueue,queueCount)
' Call PutQueueStr(outQueue,strGMCP)
' strGMCP = ""
' queueCount = 0
' Call ClearQueue(inQueue)
' Else
' strGMCP = "No Input" & Chr(13)
' Call PutQueueStr(outQueue,strGMCP)
' Call ClearQueue(outQueue)
' End If
Call CloseCom(1,inQueue, outQueue)
Debug.Print Chr(13) & "Velocimeter Simulator Complete"
End Sub
ZBasic v2.3
UTUTUTUTUTUTUTUTUTUT
Velocimeter Simulator Complete
It appears that my code should be working, but I can't figure out why it isn't.
Mike
Re: PutQueueStr Question
COM1 is opened by default before a program starts to run. If you want to change the baudrate or attach your own queues as you have done, then you need to first close the port using CloseCom. See this thread for an example.iamajoat wrote:Code: Select all
Call OpenQueue(inQueue, SizeOf(inQueue)) Call OpenQueue(outQueue, SizeOf(outQueue)) Call ClearQueue(inQueue) Call ClearQueue(outQueue) Call OpenCom(1,19200,inQueue,outQueue) 'change to 9600 later
Mike Perks
Re: PutQueueStr Question
Mike,mikep wrote: COM1 is opened by default before a program starts to run. If you want to change the baudrate or attach your own queues as you have done, then you need to first close the port using CloseCom. See this thread for an example.
Thanks for the reply. I tried doing that, but it makes no difference in the output of my code.
I still can't see why Don's example works and mine doesn't.
Mike
Re: PutQueueStr Question
One suggestion I have is sort of painful. It is what I do when I can't find the source of an error. Start with the functioning code, and add your own code to it until either you get it fully functioning or until you make it fail. If you get it to do everything, then the prtoblem is solved (but not necessarily answered), and if it fails, then the last piece of added code must the be culprit.iamajoat wrote:Mike,
Thanks for the reply. I tried doing that, but it makes no difference in the output of my code.
I still can't see why Don's example works and mine doesn't.
Mike
-Tony
Re: PutQueueStr Question
Your code is executing correctly - it's probably not what you intended, though. Perhaps you can explain your intent for the sequence below:iamajoat wrote:It appears that my code should be working, but I can't figure out why it isn't.
Code: Select all
Call PutQueueStr(outQueue,strGMCP)
Call ClearQueue(outQueue)
By the way, you don't need the ClearQueue() calls after the OpenQueue() calls (early in the program). After OpenQueue(), a queue is guaranteed to be empty.
- Don Kinzer
Re: PutQueueStr Question
Don,dkinzer wrote:Your code is executing correctly - it's probably not what you intended, though. Perhaps you can explain your intent for the sequence below:The ClearQueue() call deletes whatever is in the queue, including what you just added (except for the characters already transmitted).Code: Select all
Call PutQueueStr(outQueue,strGMCP) Call ClearQueue(outQueue)
By the way, you don't need the ClearQueue() calls after the OpenQueue() calls (early in the program). After OpenQueue(), a queue is guaranteed to be empty.
I was being careful. I assumed (there I go again) that the clear function wouldn't run until the put was done. Now thinking about it, I realize that I didn't take into account the delay in serial transmission.
Thanks for the responses and clarifications.
Mike
Re: PutQueueStr Question
If you want to wait until all of the characters have been removed from the queue (for transmission) you can use this:iamajoat wrote:I didn't take into account the delay in serial tansmission.
Code: Select all
Do While StatusQueue()
Loop
Code: Select all
Do While CBool(StatusCom(1) And &H04)
Loop
- Don Kinzer