Forum Index
HomeZBasic Home   Forum RulesForum Rules   Forum FAQForum FAQ   MemberlistMemberlist   UsergroupsUsergroups   RSS FeedRSS Feed
Site SearchSite Search   LinksLinks   DownloadDownload   Digests and SubscriptionsDigests and Subscriptions
ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in   RegisterRegister
Problem Reading from a Queue

 
Post new topic   Reply to topic    Forum Index -> ZX-24
Author Message
sturgessb



Joined: 25 Apr 2008
Posts: 246
Location: Norwich, UK

Posted: 05 August 2008, 23:19 PM    Post subject: Reply with quote

ok here's a weird one.....

Code:
'OPTIONS
Option Com1Speed 38400
Option TxQueueSize 100
Option RxQueueSize 100

'Comm setup
Public com2TXQueue(1 to 100) as Byte
Public com2RXQueue(1 to 100) as Byte

'test
Public teststring as String

Public Sub Main()
   'queue / com setup
   Register.Console.Echo = False

   'Setup Comm
   Call OpenQueue(com2RXQueue, SizeOf(com2RXQueue))
   Call OpenQueue(com2TXQueue, SizeOf(com2TXQueue))
   Call OpenCom(2, 38400, com2RXQueue, com2TXQueue)

   Do
         teststring = "ben"
         Call PutQueueStr(com2TXQueue, teststring)
         Call Delay(1.0)
         DEBUG.PRINT GetQueueStr(com2TXQueue)
   Loop
End Sub



The data showing both from the DEBUG.PRINT and from a serial port monitor on com2 is gibberish, like the baud rate is wrong. However serial baud rate is 38400, so its correct.

Why is even the GetQueueStr showing rubbish. Attached Image of output.



output.jpg
 Description:

Download
 Filename:  output.jpg
 Filesize:  24.45 KB
 Downloaded:  3294 Time(s)

Back to top
sturgessb



Joined: 25 Apr 2008
Posts: 246
Location: Norwich, UK

Posted: 05 August 2008, 23:22 PM    Post subject: Reply with quote

If i do the same but writing and reading from the com2RXQueue, it works as expected. just not the TX queue
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR

Posted: 05 August 2008, 23:35 PM    Post subject: Reply with quote

sturgessb wrote:
If i do the same but writing and reading from the com2RXQueue, it works as expected. just not the TX queue
The problem is that when you have a queue assigned as the transmit queue for a Com channel, characters are being taken from it by the serial transmission ISR for the Com channel. Attempting to read characters from the same queue at same time simply doesn't work as you've discovered. You can confirm this by commenting out the OpenCom() call in your example.

I realize now that it isn't stated anywhere that you should regard transmit queue for Com channels as "write-only" and you should regard receive queues for Com channels are "read-only". I'll see about changing the documentation to reflect that and also look into what it would take to enforce the read-only and write-only aspects of the Com channel queues.
Back to top
sturgessb



Joined: 25 Apr 2008
Posts: 246
Location: Norwich, UK

Posted: 05 August 2008, 23:38 PM    Post subject: Reply with quote

ok that makes sence from regards of reading the queue in software.

But what about when I hook the TX line of com2 up to my PC serial port, i get the same weird output?

This is what I get on the serial port monitor.



output2.jpg
 Description:
 Filesize:  15.29 KB
 Viewed:  5547 Time(s)

output2.jpg


Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR

Posted: 05 August 2008, 23:45 PM    Post subject: Reply with quote

sturgessb wrote:
But what about when I hook the TX line of com2 up to my PC serial port, i get the same weird output?
Clearly, something is not right. How is the Tx line of Com2 connected to the PC? Is the baud rate on the PC serial port set correctly?

You must use an RS-232 level converter of some sort to send serial data to a PC because the PC expects an inverted signal with a logic 1 represented as -3 to -12 volts and a logic 0 represented as +3 to +12 volts. Most PC serial ports will correctly recognize a serial signal with a logic 1 of near zero volts and a logic zero of near 5 volts. You can exploit that fact to implement a simple level converter using a 74xx04 type inverter. The alternative is to use a full RS-232 level converter like the MAX232.

There is a spare pair of Rx/Tx converters available on the ZX-1280 development board that you can use for Com2. See the documentation for more details.
Back to top
sturgessb



Joined: 25 Apr 2008
Posts: 246
Location: Norwich, UK

Posted: 05 August 2008, 23:55 PM    Post subject: Reply with quote

Im just using the same usb-RS232 adaptor I always use with the zx. It works fine for Com1 monitoring, programming etc.

Is com2 different?

baud is correctly set.
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR

Posted: 06 August 2008, 0:52 AM    Post subject: Reply with quote

sturgessb wrote:
Is com2 different?
No. The same rules apply to all serial ports. On many ZX devices, the converter is already built-in for Com1 but it isn't for any other Com ports. If you make connections to any other Com ports you must make certain that either the external device is compatible with non-inverted TTL-level signals or, alternatively, you connect the correct level converter to provide the logic sense and voltage levels that the external device expects.

Most likely, the Serial-USB converter that you're using requires inverted signals; almost certainly so if it is designed to connect to a standard DB-9 serial port. It may accept 0V/5V for the logic 1/logic zero levels; there is no way to know without trying it unless you have a specification for it.

It may help if you were to be more explicit as to how you're connecting the USB-Serial converter to Com2. A simple diagram would suffice. I've attached an example of a converter using the MAX202. If you're using the ZX-1280 Dev board, one set of converters is available for your use at J13. The RS-232 side of the spare converters is connected to the DB-9 connector J26.



Com Conversion.jpg
 Description:
TTL to RS-232 Signal Conversion
 Filesize:  34.15 KB
 Viewed:  5530 Time(s)

Com Conversion.jpg


Back to top
Display posts from previous:   
Post new topic   Reply to topic    Forum Index -> ZX-24 Time synchro. with the server - Timezone/DST with your computer
Page 1 of 1

 


All content Copyright © 2005-2012 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group