Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I make Forth talk to a serial port?

687 views
Skip to first unread message

Bob

unread,
Jul 8, 2012, 5:08:27 PM7/8/12
to
Thirty years ago I used Z80-SIOs and 8250s in Forth. It was easy to
have Forths talk to each other ( screen sharing ) and talk to terminals.
I used simple interrupt routines to send from a buffer and receive
into a buffer. I knew the address of the uart and the registers and the
bit definitions from the part specs. Now Linux, Wine, and Windows
protect me from accessing my serial port.

Please direct me to some tutorial information and sample code of the
current typical practice. Specifically I'm trying to use Gforth on a
Linux laptop. I want to send and receive frequency programming
information to a 2 way mobile radio. If there is a better platform
please advise. I have searched in the ans documentation and the
documentation that comes with Gforth.

Things sure have changed since 1980 - 82. Coming back to Forth after
all these years is like looking up an old girl friend. She has put on
some weight, 83 pounds and then 94 more pounds. She is still
comfortable to be with, an old friend.

Krishna Myneni

unread,
Jul 8, 2012, 5:30:38 PM7/8/12
to
Please take a look at the serial port programming examples which are
included in the kForth package for Linux. The last release may be
found at,

http://ccreweb.org/software/kforth/

However, the latest development snapshot will have more up to date
files and examples. This may be found at,

ftp://ccreweb.org/software/kforth/linux/develop/1.5.x/

The following files are relevant:

modules.fs Modules framework for Forth
serial.4th Serial port interface module
serial-comm.4th High level serial interface module
terminal.4th Generic terminal module for serial communications
term.4th Terminal program with pluggable comm modules
hexterm.4th Display incoming serial data in hex form


Krishna Myneni


Bernd Paysan

unread,
Jul 8, 2012, 6:36:04 PM7/8/12
to
Bob wrote:

> Now Linux, Wine, and Windows
> protect me from accessing my serial port.

Hehe. If you have Gforth, look into arch/r8c/terminal.fs. It included
enough code to talk to a device on the serial port.

--
Bernd Paysan
"If you want it done right, you have to do it yourself"
http://bernd-paysan.de/

Krishna Myneni

unread,
Jul 8, 2012, 8:38:28 PM7/8/12
to
On Jul 8, 4:08 pm, Bob <b...@none.com> wrote:
> Thirty years ago I used Z80-SIOs and 8250s in Forth.  It was easy to
> have Forths talk to each other ( screen sharing ) and talk to terminals.
>   I used simple interrupt routines to send from a buffer and receive
> into a buffer.  I knew the address of the uart and the registers and the
> bit definitions from the part specs.  Now Linux, Wine, and Windows
> protect me from accessing my serial port.
>

Also, don't forget to set your group membership to the group permitted
read/write access to the /dev/ttyS* nodes. Typically, this is the
"dialout" group, but may depend on your linux distribution. You can
check with,

ls -l /dev/ttyS*


Krishna

Albert van der Horst

unread,
Jul 9, 2012, 11:12:02 AM7/9/12
to
In article <4ff9f6e4$0$22915$9a6e...@unlimited.newshosting.com>,
Bob <b...@none.com> wrote:
>Thirty years ago I used Z80-SIOs and 8250s in Forth. It was easy to
>have Forths talk to each other ( screen sharing ) and talk to terminals.
> I used simple interrupt routines to send from a buffer and receive
>into a buffer. I knew the address of the uart and the registers and the
>bit definitions from the part specs. Now Linux, Wine, and Windows
>protect me from accessing my serial port.
>
>Please direct me to some tutorial information and sample code of the
>current typical practice. Specifically I'm trying to use Gforth on a
>Linux laptop. I want to send and receive frequency programming
>information to a 2 way mobile radio. If there is a better platform
>please advise. I have searched in the ans documentation and the
>documentation that comes with Gforth.

Before trying to become an expert, let Linux "protect you" from
accessing your serial port.

This is a communication program I jotted down for communicating
with the MSP430 board containing the 4E4th forth.
It gets by with knowing the name of the serial device plus standard
Forth file I/O.
Connect the device and do ls -ltr /dev . The most recent device
is probably your usb.
Despite the ciforth-ism, lack of comment and hard coded
ports, you should get a feel that USB done well is really
easy. (The $11 handshake is a quirk of 4E4TH)

-----------8< ----------------------------------

REQUIRE R/W REQUIRE NEW-IF REQUIRE $-PREFIX
REQUIRE ls
REQUIRE CASE-SENSITIVE CASE-INSENSITIVE
REQUIRE THREAD-PET

VOCABULARY MSP-WORDLIST
MSP-WORDLIST DEFINITIONS

: NEW-OK CR "com>" TYPE ;
'NEW-OK 'OK 3 CELLS MOVE

VARIABLE (msp)
\ Return the FILEDESCRIPTOR of the MSP board.
: msp (msp) @ ;

: ?ERR ( ior -- ) -1 SWAP ?ERROR ;

: open-connection "/dev/ttyACM0" R/W OPEN-FILE ?ERR (msp) ! ;
: close-connection msp CLOSE-FILE ?ERR ;

: handshake 10 MS \ PAD DUP 84 msp READ-FILE ?ERR TYPE
BEGIN 0 DSP@ 1 msp READ-FILE ?ERR DROP DUP $11 <> WHILE EMIT REPEAT DROP ;

: line msp WRITE-FILE ?ERR ^M DSP@ 1 msp WRITE-FILE ?ERR DROP ;

: .S ".S" line handshake ;

: uploaded
GET-FILE open-connection
BEGIN OVER WHILE ^J $S -TRAILING line handshake ( .S ) REPEAT 2DROP
close-connection ;
: upload (WORD) uploaded ;

: communicate open-connection "" line handshake
BEGIN (ACCEPT) -TRAILING DUP WHILE line handshake REPEAT 2DROP
close-connection ;

'communicate ALIAS c
'upload ALIAS u
'ls ALIAS l

: HELP "C(ommunicate) U(pload $1) L(ist dir $1) " TYPE CR ;

: doit 'ERROR RESTORED POSTPONE MSP-WORDLIST QUIT ;
-----------8< ----------------------------------

>
>Things sure have changed since 1980 - 82. Coming back to Forth after
>all these years is like looking up an old girl friend. She has put on
>some weight, 83 pounds and then 94 more pounds. She is still
>comfortable to be with, an old friend.

And despite her weight she had become really fast.

Groetjes Albert

--
--
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

0 new messages