'Super Com Z" Com Support Routines "Port parameter

Here you can share completed projects or parts of projects that may be useful to others. You may post files relevant to ZBasic - source code, schematics, etc.
Post Reply
zbasicandy
Posts: 193
Joined: 25 January 2006, 19:56 PM

'Super Com Z" Com Support Routines "Port parameter

Post by zbasicandy »

These "beta" routines should work for general serial communications using 1 to 4 serial I/O ports. Due to the complex nature of these routines they are subject to change on the minute!
Attachments
ComSupport_R4.bas
Com Support routines for the "Super Comm Z" with 4 serial ports.
(28.49 KiB) Downloaded 4169 times
stevech
Posts: 715
Joined: 22 February 2006, 20:56 PM

Post by stevech »

(I've never used BasicX)

Are the unusal codings for PutL and Put floats etc. as they are because of BasicX compatibility?

ZBasic would not need all this arcane code.
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

I would suggest the alternate implementations below. Something similar could be used for outputting Single values unless the required format can't be produced by CStr() or Fmt().

Code: Select all

Public Sub PutStr(ByVal port as Byte, ByRef Tx as STRING)
	' Outputs a STRING type to serial port n.

	Dim Length as Integer
	Dim I as Integer

	Length = Len(Tx)
	For I = 1 To Length
		Call PutByte(port, Asc(Tx, I))
	Next I
End Sub

Public Sub PutL(ByVal port as Byte, ByVal Operand as Long)
	Dim s as BoundedString(11)
	s = CStr(Operand)
	Call PutStr(port, s)
End Sub

Public Sub PutUL(ByVal port as Byte, ByVal Operand as UnsignedLong)
	Dim s as BoundedString(10)
	s = CStr(Operand)
	Call PutStr(port, s)
End Sub
Except for the use of the second parameter on the Asc() function and the syntax for defining the bounded string, the same coding would work for BasicX. An alternate method for fetching string characters in BasicX is:

Code: Select all

		Call PutByte(port, RamPeek(MemAddress(Tx) + I + 1))
- Don Kinzer
stevech
Posts: 715
Joined: 22 February 2006, 20:56 PM

Post by stevech »

Code: Select all

Public Sub PutL(ByVal port as Byte, ByVal Operand as Long)
   Dim s as BoundedString(11)
   s = CStr(Operand)
   Call PutStr(port, s)
End Sub 
would be useful as a sub if it saved code space, rather than just coding in-line in the application:

call PutStr(port, CStr(number)) // dynamic string allocation in ZBasic

which with the VM, is probably not significantly different, esp. considering that it uses less call/return/parameter passing stack.
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

Code: Select all

Call PutStr(port, CStr(number))
You are correct that this consumes less stack space than allocating the bounded string. I should have made that reduction, too.
- Don Kinzer
Post Reply