Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #13730

Re: How do I make Forth talk to a serial port?

Newsgroups comp.lang.forth
From Albert van der Horst <albert@spenarnc.xs4all.nl>
Subject Re: How do I make Forth talk to a serial port?
Date 2012-07-09 15:12 +0000
Message-ID <m6wfk2.7fs@spenarnc.xs4all.nl> (permalink)
Organization Dutch Forth Workshop
References <4ff9f6e4$0$22915$9a6e19ea@unlimited.newshosting.com>

Show all headers | View raw


In article <4ff9f6e4$0$22915$9a6e19ea@unlimited.newshosting.com>,
Bob  <bob@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

Back to comp.lang.forth | Previous | NextPrevious in thread | Find similar


Thread

How do I make Forth talk to a serial port? Bob <bob@none.com> - 2012-07-08 17:08 -0400
  Re: How do I make Forth talk to a serial port? Krishna Myneni <krishna.myneni@ccreweb.org> - 2012-07-08 14:30 -0700
  Re: How do I make Forth talk to a serial port? Bernd Paysan <bernd.paysan@gmx.de> - 2012-07-09 00:36 +0200
  Re: How do I make Forth talk to a serial port? Krishna Myneni <krishna.myneni@ccreweb.org> - 2012-07-08 17:38 -0700
  Re: How do I make Forth talk to a serial port? Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-07-09 15:12 +0000

csiph-web