| Author |
Message |
zbasicandy
Joined: 26 Jan 2006
|
|
Posted: 01 April 2006, 2:55 AM Post subject: 'Super Com Z" Communication Support Routines |
|
|
I modified some of the routines to run on the "Super Com Z" 4 port communications board. You will find these general routines handy for serial port communications.
| Description: |
| General and board specific serial port communications routines |
|
 Download |
| Filename: |
ComSupport_R2.bas |
| Filesize: |
47.72 KB |
| Downloaded: |
2182 Time(s) |
|
|
| Back to top |
|
 |
mikep
Joined: 24 Sep 2005
Location: Austin, TX
|
|
Posted: 01 April 2006, 3:56 AM Post subject: |
|
|
There has got to be a more generic way to do this rather than duplicate and try to keep all the code in sync for each port. Here is some untested code that parameterizes the port number:
| Code: | private const InBufSize as INTEGER = 50 ' 41-byte buffer.
private const OutBufSize as INTEGER = 50 ' 41-byte buffer.
private const minLogicalPort as Byte = 3
private const maxLogicalPort as Byte = 6
public InBuf(1 To InBufSize, minLogicalPort to maxLogicalPort) as BYTE
public OutBuf(1 To OutBufSize, minLogicalPort to maxLogicalPort) as BYTE
'==============================================================================
Private Function getInputBuffer(ByVal buffer as UnsignedInteger, ByVal port as Byte) as Integer
getInputBuffer = CInt(buffer) + InBufSize * CInt(port - minLogicalPort)
End Function
Private Function getOutputBuffer(ByVal buffer as UnsignedInteger, ByVal port as Byte) as Integer
getOutputBuffer = CInt(buffer) + OutBufSize * CInt(port - minLogicalPort)
End Function
'=========================================================================================
'Subroutines - Generic for all ZX-xx's
'=========================================================================================
public sub OpenSerialPort(ByVal port as Byte, ByVal BaudRate as LONG)
' Opens serial port n at the specified baud rate.
CALL OpenQueue(CByteArray(getInputBuffer(Inbuf.DataAddress, port)), InBufSize)
CALL OpenQueue(CByteArray(getOutputBuffer(Outbuf.DataAddress, port)), OutBufSize)
CALL OpenCom(port, BaudRate, _
CByteArray(getInputBuffer(Inbuf.DataAddress, port)), _
CByteArray(getOutputBuffer(Outbuf.DataAddress, port)))
END sub
'===============================================================================
public sub PutByte(ByVal port as Byte, ByVal Value as BYTE)
' Sends one byte of binary data to serial port n. The byte is sent
' directly without translating it to a STRING type.
CALL PutQueueByte(CByteArray(getOutputBuffer(Outbuf.DataAddress, port)), Value)
END sub
...
....
and so on |
Note I also changed PutQueue to PutQueueByte.
This code could be even cleaner but MemAddress does not support a two-dimensional array. The documentation is not clear on this point.
|
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Location: Portland, OR
|
|
Posted: 01 April 2006, 5:12 AM Post subject: |
|
|
| Quote: | | MemAddress does not support a two-dimensional array |
I'm not sure I understand exactly what you mean. This code is perhaps simpler and seems to work correctly.
| Code: | Public Sub OpenSerialPort(ByVal port as Byte, ByVal BaudRate as Long)
If ((port >= minLogicalPort) And (port <= maxLogicalPort)) Then
' Opens serial port n at the specified baud rate.
Call OpenQueue(CByteArray(Inbuf(1, port).DataAddress), InBufSize)
Call OpenQueue(CByteArray(Outbuf(1, port).DataAddress), OutBufSize)
Call OpenCom(port, BaudRate, CByteArray(Inbuf(1, port).DataAddress), _
CByteArray(Outbuf(1, port).DataAddress))
End If
End Sub |
|
|
| Back to top |
|
 |
mikep
Joined: 24 Sep 2005
Location: Austin, TX
|
|
Posted: 01 April 2006, 5:26 AM Post subject: |
|
|
The code: | Code: | | MemAddress(Inbuf(1, port)) |
causes a compile error of: | Code: | Error: function "MemAddress" parameter 1, multi-dimension arrays cannot be passed as parameters
|
I thought I tried the variation of code you suggested with DataAddress and also got a compiler error. It obviously works.
I think there is enough information now for ZBasicAndy to rewrite his code to be more generic and take up less program memory. And he will appreciate the flexibility when ZBasic supports 12 serial ports
Last edited by mikep on 01 April 2006, 7:11 AM; edited 1 time in total |
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Location: Portland, OR
|
|
Posted: 01 April 2006, 6:14 AM Post subject: |
|
|
| Quote: | | MemAddress(Inbuf(1, port)) causes a compile error |
Indeed it does. I confirmed the the following code, embodying the same idea, compiles without error in BasicX.
| Code: | Dim u as new UnsignedInteger
Dim ai(1 to 5, 2 to 10) As Byte
Dim i as Integer
Sub Main()
u = MemAddressU(ai(1, i))
End Sub |
|
|
| Back to top |
|
 |
zbasicandy
Joined: 26 Jan 2006
|
|
Posted: 03 April 2006, 4:19 AM Post subject: |
|
|
Don, I tried your suggestion and I got several compiler errors:
Note: Mikep code works and compiles OK.
Note: ZBasic IDE Version: 1.0.4 / ZBasic Compiler version 1-1-18 / ZX-40 Firmware 1.1.6
Test_CommSupport.bas:201: Error: missing comma, operator or right parenthesis, identifier "CByteArray"
Test_CommSupport.bas:201: Error: missing comma, operator or right parenthesis, identifier "OpenQueue"
Test_CommSupport.bas:202: Error: missing comma, operator or right parenthesis, identifier "CByteArray"
Test_CommSupport.bas:202: Error: missing comma, operator or right parenthesis, identifier "OpenQueue"
Test_CommSupport.bas:203: Error: missing comma, operator or right parenthesis, identifier "CByteArray"
Test_CommSupport.bas:203: Error: missing comma, operator or right parenthesis, identifier "OpenCom"
| Quote: | Public Sub OpenSerialPort(ByVal port as Byte, ByVal BaudRate as Long)
If ((port >= minLogicalPort) And (port <= maxLogicalPort)) Then
' Opens serial port n at the specified baud rate.
Call OpenQueue(CByteArray(Inbuf(1, port).DataAddress), InBufSize)
Call OpenQueue(CByteArray(Outbuf(1, port).DataAddress), OutBufSize)
Call OpenCom(port, BaudRate, CByteArray(Inbuf(1, port).DataAddress), CByteArray(Outbuf(1, port).DataAddress))
End If
End Sub |
|
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Location: Portland, OR
|
|
Posted: 03 April 2006, 4:51 AM Post subject: |
|
|
I can compile the code below with v1.1.18 with no errors. Would you try this (limited to just the code shown) and see what you get? If this compiles OK then there is an interaction somewhere that needs to be isolated. I suspect that it may be an error prior to the code cited from which the compiler did not fully recover.
| Code: | private const InBufSize as INTEGER = 50 ' 41-byte buffer.
private const OutBufSize as INTEGER = 50 ' 41-byte buffer.
private const minLogicalPort as Byte = 3
private const maxLogicalPort as Byte = 6
public InBuf(1 To InBufSize, minLogicalPort to maxLogicalPort) as BYTE
public OutBuf(1 To OutBufSize, minLogicalPort to maxLogicalPort) as BYTE
Sub Main()
End Sub
Public Sub OpenSerialPort(ByVal port as Byte, ByVal BaudRate as Long)
If ((port >= minLogicalPort) And (port <= maxLogicalPort)) Then
' Opens serial port n at the specified baud rate.
Call OpenQueue(CByteArray(Inbuf(1, port).DataAddress), InBufSize)
Call OpenQueue(CByteArray(Outbuf(1, port).DataAddress), OutBufSize)
Call OpenCom(port, BaudRate, CByteArray(Inbuf(1, port).DataAddress), CByteArray(Outbuf(1, port).DataAddress))
End If
End Sub |
|
|
| Back to top |
|
 |
DH* Guest
|
|
Posted: 03 April 2006, 12:59 PM Post subject: |
|
|
This thread appears to address the issue I was pondering about 6 weeks back in the Queues for COM3, 4, 5, 6 thread in the ZBasic Language forum.
How do you use StatusQueue with the input queues defined in this manner?
It would be hepful if there were a system level nibble for all 4 queues so that one call would tell if there was any input to any of the 4 ports.
|
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Location: Portland, OR
|
|
Posted: 03 April 2006, 15:23 PM Post subject: |
|
|
| Quote: | | This thread appears to address the issue I was pondering about 6 weeks back ... |
I remember that. I should have thought of this technique then.
| Quote: | | How do you use StatusQueue with the input queues defined in this manner? |
The CByteArray() construction can be used anywhere an "array of Byte" parameter is required.
| Code: | Function SerialDataAvailable(ByVal port as Byte) as Boolean
SerialDataAvailable = StatusQueue(CByteArray(Inbuf(1, port).DataAddress))
End Function |
|
|
| Back to top |
|
 |
zbasicandy
Joined: 26 Jan 2006
|
|
Posted: 03 April 2006, 19:03 PM Post subject: Comm routine doesn't compile |
|
|
Don said
| Quote: | | I can compile the code below with v1.1.18 with no errors |
I tried it "all alone" on a blank project page - and it still fails with the same errors!
|
|
| Back to top |
|
 |
mikep
Joined: 24 Sep 2005
Location: Austin, TX
|
|
Posted: 03 April 2006, 19:37 PM Post subject: |
|
|
| zbasicandy wrote: | Don, I tried your suggestion and I got several compiler errors:
Note: ZBasic IDE Version: 1.0.4 / ZBasic Compiler version 1-1-18 / ZX-40 Firmware 1.1.6
Test_CommSupport.bas:201: Error: missing comma, operator or right parenthesis, identifier "CByteArray"
Test_CommSupport.bas:201: Error: missing comma, operator or right parenthesis, identifier "OpenQueue"
Test_CommSupport.bas:202: Error: missing comma, operator or right parenthesis, identifier "CByteArray"
Test_CommSupport.bas:202: Error: missing comma, operator or right parenthesis, identifier "OpenQueue"
Test_CommSupport.bas:203: Error: missing comma, operator or right parenthesis, identifier "CByteArray"
Test_CommSupport.bas:203: Error: missing comma, operator or right parenthesis, identifier "OpenCom"
| Quote: | Public Sub OpenSerialPort(ByVal port as Byte, ByVal BaudRate as Long)
If ((port >= minLogicalPort) And (port <= maxLogicalPort)) Then
' Opens serial port n at the specified baud rate.
Call OpenQueue(CByteArray(Inbuf(1, port).DataAddress), InBufSize)
Call OpenQueue(CByteArray(Outbuf(1, port).DataAddress), OutBufSize)
Call OpenCom(port, BaudRate, CByteArray(Inbuf(1, port).DataAddress), CByteArray(Outbuf(1, port).DataAddress))
End If
End Sub |
|
For Don. I can also compile this code which is why I pointed ZBasicAndy back to this forum.
|
|
| Back to top |
|
 |
zbasicandy
Joined: 26 Jan 2006
|
|
Posted: 03 April 2006, 20:07 PM Post subject: Comm routine doesn't compile |
|
|
I am "eat crow" on this one. My compiler was only 1.1.10 (last month) instead of the newer one 1.1.18. I found it by "double checking" the map file.
This brings up another point. With all the changes to each module e.g. compiler, IDE and firmware would it be possible to click on ONE button or help menu to show all three revision versions or maybe when it compiles, show at the bottom of the screen.
Another point, the release for 1.1.18 was just an exe and not an install exe. Would it also be possible to send with the version update an installer to update to module version in question. I am only talking from a newbee frame of mind!
|
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Location: Portland, OR
|
|
Posted: 03 April 2006, 20:41 PM Post subject: |
|
|
| Quote: | | Would it also be possible to send with the version update an installer...? |
It could be done that way. My thought was that it was simpler to just extract a file from a .zip archive.
| Quote: | | [W]ould it be possible to click on ONE button or help menu to show all three revision versions or maybe when it compiles, show at the bottom of the screen? |
It may be possible to modify the IDE so that the compiler version is displayed in the About box. Displaying the firmware version number is somewhat more difficult but it possibly could be done as well. In the interim, you could add the version display option to your .pjt file as shown in the sample below. This will cause the compiler version to be displayed as part of the output of every build.
| Code: | --version
--list=test.lst
test.bas |
|
|
| Back to top |
|
 |
DH* Guest
|
|
Posted: 05 April 2006, 20:45 PM Post subject: |
|
|
| dkinzer wrote: | | Quote: | | MemAddress(Inbuf(1, port)) causes a compile error |
Indeed it does. I confirmed the the following code, embodying the same idea, compiles without error in BasicX.
| Code: | Dim u as new UnsignedInteger
Dim ai(1 to 5, 2 to 10) As Byte
Dim i as Integer
Sub Main()
u = MemAddressU(ai(1, i))
End Sub |
|
Do you plan to change MemAddress so it will work with multi-dimensional arrays? For an old geezer who has to type with only one (arthritic) hand, the CByteArray construction is cruel and unusual punishment.
|
|
| Back to top |
|
 |
mikep
Joined: 24 Sep 2005
Location: Austin, TX
|
|
Posted: 05 April 2006, 21:04 PM Post subject: |
|
|
| dhouston wrote: | Do you plan to change MemAddress so it will work with multi-dimensional arrays? For an old geezer who has to type with only one (arthritic) hand, the CByteArray construction is cruel and unusual punishment.  |
I think you misunderstand what you have to code. The two versions are:
| Code: | | CByteArray(MemAddress(InBuf(1, port)) | and | Code: | | CByteArray(InBuf(1, port).DataAddress) | There are a few things that can help you (or anyone):
1. Use Ctrl-space to get an autocompletion list. For example I can type MemAddress with 4 keystrokes: M, e, Ctrl-space, Enter
2. ZBasic allows things to be mixed-case so don't worry about caps
I assume you are already using other tools to help with your physical impairment which reduce or made it easier to type.
|
|
| Back to top |
|
 |
|