SerialOut command not available on ZX-24?

Discussion specific to the 24-pin ZX microcontrollers, e.g. ZX-24r, ZX-24s and ZX-24t.
Post Reply
lwcyb
Posts: 11
Joined: 11 September 2013, 7:12 AM

SerialOut command not available on ZX-24?

Post by lwcyb »

I'm trying to port a program made originally in PBasic over to ZBasic, and it looks like the ZX-24 does not support the SerialOut function? Are there alternatives to this command?
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: SerialOut command not available on ZX-24?

Post by dkinzer »

lwcyb wrote:I'm trying to port a program made originally in PBasic over to ZBasic, and it looks like the ZX-24 does not support the SerialOut function?
Yes, neither SerialOut() nor SerialIn() are supported on VM-mode devices like the ZX-24, ZX-24a, ZX-24p and ZX-24r. They are supported on native mode devices like the ZX-24n and ZX-24s. It should be noted that the functionality of SerialOut() is similar to but not identical to that of SEROUT in PBasic.

Which 24-pin ZX device are you actually using?
lwcyb wrote:Are there alternatives to this command?
Depending on what it is you're trying to do, using one of the software serial channels (Com3-Com6) may work perfectly.

If you haven't seen it, you may find the PBasic Conversion Guide useful.
- Don Kinzer
lwcyb
Posts: 11
Joined: 11 September 2013, 7:12 AM

Post by lwcyb »

I'm trying to send hexadecimal codes to a micro oled screen using a ZX-24p, I believe I've defined and opened a com channel successfully, my only question now is what command to use to send the hexadecimal characters?
GTBecker
Posts: 616
Joined: 17 January 2006, 19:59 PM
Location: Cape Coral

SerialOut command not available on ZX-24?

Post by GTBecker »

> ... what command to use to send the hexadecimal characters?

That depends upon the OLED device you're using. What is it?

Tom
Tom
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

lwcyb wrote:I believe I've defined and opened a com channel successfully, my only question now is what command to use to send the hexadecimal characters?
To send any data out the serial channel, all you need to do is to add it to the output queue that you associated with the serial channel when you opened it. The data will be sent in the order that you add it to the queue, e.g.

Code: Select all

PutQueueByte(oq, Asc("A"))
PutQueueByte(oq, &H41)
PutQueueByte(oq, 65)
These three calls all have the same effect, i.e. to put the character code for capital A in the queue oq. Note, too, that you can send a sequence of characters by using PutQueueStr().
- Don Kinzer
lwcyb
Posts: 11
Joined: 11 September 2013, 7:12 AM

Post by lwcyb »

I am using a 4D uOLED screen.

Code: Select all

        Dim str as String = &HFF & " " & &HD7 
	Dim outQueue(1 to 40) as Byte

	Call OpenQueue(outQueue, SizeOf(outQueue))
	Call ComChannels(1, 9600)
	Call DefineCom(4, 0, 8, &H08)
	Call OpenCom(4, 9600, 0, outQueue)

	Call Delay(2.7)
	Call PutQueueStr(outQueue, str)
        Debug.print str

	str = &H00 & " " & &H0C & " " & &H00 & " " & &H00
	Call PutQueueStr(outQueue, str)
	Debug.print str
FF and D7 are used to clear the screen, and 00, 0C, 00, 00 is used to disable the screen saver that appears. The 2.7 second delay is placed there because this is recommended by 4D (the oled screen manufacturer). I've confirmed I'm using the correct # pin (pin 8) for transmitting, but I'm not seeing the screen clear itself. In PBasic serial commands the hexadecimal codes are separated by commas, is there a character I'm missing here that I should be using instead of an empty space (" ")?

Thank you both for your assistance.
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

lwcyb wrote: I've confirmed I'm using the correct # pin (pin 8) for transmitting, but I'm not seeing the screen clear itself.
One problem is that you're using ComChannels() to tell the compiler that there will be just one SW serial port (which will be Com3) but then you use Com4 which is, of course, not valid.

You only need to use ComChannels() if you plan to use a SW serial channels beyond Com3. The additional channels are Com4, Com5 and Com6 but those are only valid if the first parameter to ComChannels() is large enough, e.g. for Com4 it must be at least 2, for Com5 it must be at least 3, and for Com6 it must be 4. The second parameter to ComChannels() is used to indicate the maximum baud rate that any open channel will use.

Note that the function StatusCom() gives information about a serial channel including if it is valid or not. If you were to insert the line below after the ComChannels() call you'll discover that Com4 isn't valid at that point.

Code: Select all

  Debug.Print "Com4 is "; IIF(CBool(StatusCom(4) And &H01), "", "not "); "valid"
lwcyb wrote:In PBasic serial commands the hexadecimal codes are separated by commas, is there a character I'm missing here that I should be using instead of an empty space (" ")?
In PBasic, the commas are required to separate the digits of the character codes. In the code you've shown, the ampersand serves the save function. I doubt that the space characters are needed.

It would be easier to help if you could post a link to the documentation for the device.
- Don Kinzer
lwcyb
Posts: 11
Joined: 11 September 2013, 7:12 AM

Post by lwcyb »

http://www.4dsystems.com.au/downloads/S ... REV1.3.pdf

Stupid mistake on my end, I switched the RX and TX pins around. Still doesn't function 100% but now it is actually responding. The default scrolling screensaver is affected by the code - it is not disabled and does not clear but it does reset itself. I'll have to play around a little bit more with this.

Thanks again for the clarifications.
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

lwcyb wrote:Stupid mistake on my end, I switched the RX and TX pins around.
There is still the issue with using an invalid comm channel. I presume that you fixed that, too?
lwcyb wrote:[...] and does not clear but it does reset itself.
My hunch that the space characters weren't needed is correct. Try this:

Code: Select all

Const oledChan as Byte = 3
Sub Main()
   Dim outQueue(1 to 40) as Byte

   Call OpenQueue(outQueue, SizeOf(outQueue))
   Call DefineCom(oledChan, 0, 8, &H08)
   Call OpenCom(oledChan, 9600, 0, outQueue)

   Call Delay(2.7)
   Call PutQueueStr(outQueue, Chr(&Hff) & Chr(&Hd7))

   Call Delay(1.0)
   Call PutQueueStr(outQueue, Chr(&H00) & Chr(&H0c) & Chr(&H00) & Chr(&H00))
End Sub
I added the delay between the two PutQueueStr() calls to allow the device time to clear the screen. I believe that you wouldn't have to do this if you create an input queue and wait for an acknowledgement from the display. As I read the command set description, it doesn't send the ack until it has finished.

Also, if you were using a native mode device, like the ZX-24s, you could use the Arduino or C libraries provided by 4D Systems. I haven't looked at the functionality available in those libraries but it is likely that it would save you a lot of time and frustration.
- Don Kinzer
lwcyb
Posts: 11
Joined: 11 September 2013, 7:12 AM

Post by lwcyb »

Yes, I fixed the issue with the com channel as you suggested. Everything appears to be working great now, commands are being received and the screen is operating correctly. This helped a ton with my understanding of Zbasic, thanks very much.
Post Reply