ZX1280n issue with code V4.3.10

Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
Post Reply
dkg
Posts: 3
Joined: 25 February 2013, 9:57 AM

ZX1280n issue with code V4.3.10

Post by dkg »

Hello Don,

I have an issue with the following code for the ZX1280n (I am using your development board). On ZBasic Ver 3.3.3 this prints ok to the serial port, on Ver 4.3.10 it prints nothing after the ZBasic identifier. Would you kindly take a look and see what it happening? A similar thing on Ver 3.3.3 required Call CloseCom(1,0,0) to output to the serial port, but this does not seem to be the problem with the Ver 4.3.10. My application uses COM1,2,7, and 8 so if you can check those as well to see if a similar issue may exist.

Thanks, Don G

Code: Select all

Option TargetDevice ZX1280n

'Test Pgm for hang after ZBasic version identifier (no print from serial port)

Const COM1InputBufferSize As Integer=80
Const COM1OutputBufferSize As Integer=80
Dim COM1InputBuffer(1 To COM1InputBufferSize) As Byte
Dim COM1OutputBuffer(1 To COM1OutputBufferSize) As Byte


'-----------------------------Main------------------------------------------

Sub Main()

 'Open COM1 Serial Port for Zbasic communication and profibus address setting
 'add CloseCom line to allow working with ZBasic Ver 3.3.3 
   Call CloseCom(1,0,0)
   Call OpenQueue(COM1InputBuffer, COM1InputBufferSize)
   Call OpenQueue(COM1OutputBuffer, COM1OutputBufferSize)
   Call DefineCom(1,0,0,&H00,1)
   Call OpenCom(1,19200, COM1InputBuffer, COM1OutputBuffer)
   Call PutQueueStr(COM1OutputBuffer,"Starting..." + Chr(13) + Chr(10))   
   
 Do

  Delay(1.00)
  
  Call PutQueueStr(COM1OutputBuffer,"Hello" + Chr(13) + Chr(10))
 
 Loop

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

Re: ZX1280n issue with code V4.3.10

Post by dkinzer »

dkg wrote:[...] on Ver 4.3.10 it prints nothing after the ZBasic identifier. Would you kindly take a look and see what it happening?
I don't know yet what is causing the problem but it can be resolved by adding the following line near the beginning of your main module.

Code: Select all

Option ConsoleSpeed 0
Separate from the fact that it resolves the issue, it is recommended to do this when you create the Com1 input and output queues in your code rather than using the default queues. Without that compiler directive, the default queues are still present and, thus, memory is wasted. Note that suppressing the automatic preparation of Com1 also suppresses the sign-on message.

Another way to achieve the same result is to use the compiler directives that set the Com1 queue sizes as illustrated in the alternative implementation below.

Code: Select all

' set the Com1 queue sizes
Option RxQueueSize 80
Option TxQueueSize 80

' define an alias to the default Com1 queues
Dim COM1InputBuffer() As Byte Based Register.RxQueue
Dim COM1OutputBuffer() As Byte Based Register.TxQueue

Const CRLF as String = Chr(13) + Chr(10)

Sub Main()
   Call PutQueueStr(COM1OutputBuffer, "Starting..." + CRLF)   
   Do
      Delay(1.00)
      Call PutQueueStr(COM1OutputBuffer, "Hello" + CRLF)
   Loop
End Sub
In this alternate implementation, since the default Com1 preparation is performed, if you dont' want the sign-on message you'll need to add the compiler directive Option SignOn Off.
- Don Kinzer
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

Another strategy for avoiding the problem is to ensure that all serial data has been transmitted before closing the channel. It is recommended to always do this.

Code: Select all

Sub Main()
   Do While CBool(StatusCom(1) And &H04)
   Loop
   Call CloseCom(1, 0, 0)
   [...]
End Sub
As an aside, what is the purpose of the DefineCom() call? It looks like the intent is to set the number of stop bits to 1 (which is the default). Further, since the bit count specified by the flags parameter is invalid (must be 5 to 8 for a HW channel) the call does nothing anyway.
- Don Kinzer
dkg
Posts: 3
Joined: 25 February 2013, 9:57 AM

Post by dkg »

Don,

Thanks for your help. The fix you indicated solved the problem.

I need to review the use of DefineCom, this is older code, I tend to cut and paste into new projects if things seem to work, apparently I did not see my usage was incorrect at that time.

Thanks again.

Don G
Post Reply