On 10/31/2014 06:17 PM, Bernd Paysan wrote:
Am Freitag, 31. Oktober 2014, 18:13:58 schrieb Jerry DeLisle:
On 10/31/2014 05:57 PM, Bernd Paysan wrote:
---snip---

No, if you want to have direct access to open, use a special C interface.
I think I should add open and fdopen (to get an fd) to the serial.fs
code, so that you can use open directly, and try different flags.  We
also found that on some serial ports, you don't even want to use fdopen,
because it sets some things which the serial port driver can't handle...
this means, you also need read/write to access the port.

If you like, I will attempt to add some things to serial.fs and send to you
for a look.  It should not take too much.

Yes, do so; check out the current git; I've already added open, fdopen, read,
and write.  You'll have to define the macros, and modify open-port (probably
factoring into an open-port-fd, which will give you a fd for read/write, and
open-port gives you the FILE*, to be backward compatible).


Attached is a small patch that fixes a bug in serial.fs I found, adds close, and a couple constants I am using. I am still learning my way around git. You may have updated since I did this. I plan to do more, I have just been sick with head cold for last week or so.

I also have some words to set and clr some control bits if interested:

variable result
0 result !

HEX
5415 CONSTANT TIOCMGET
5418 CONSTANT TIOCMSET
002  CONSTANT TIOCM_DTR
004  CONSTANT TIOCM_RTS
020  CONSTANT TIOCM_CTS
100  CONSTANT TIOCM_DSR
DECIMAL

: get-ioctl  ( fd -- n )
    TIOCMGET result ioctl 0< abort" IOCTL GET Failed." result @ ;

: set-ioctl  ( fd n -- )
    result ! TIOCMSET result ioctl 0< abort" IOCTL SET Failed." ;

: set-dtr  ( fd -- )
    dup get-ioctl TIOCM_DTR or set-ioctl ;

: clr-dtr  ( fd -- )
    dup get-ioctl TIOCM_DTR invert and set-ioctl ;

: set-rts  ( fd -- )
    dup get-ioctl TIOCM_RTS or set-ioctl ;

: clr-rts  ( fd -- )
    dup get-ioctl TIOCM_RTS invert and set-ioctl ;

: get-cts  ( fd -- n )
    get-ioctl TIOCM_CTS and ;

: get-dsr  ( fd -- n )
    get-ioctl TIOCM_DSR and ;

I have tested most of these and I am using them for an application i am working on. They seemed useful to me. I hope the factoring looks OK.

Regards,

Jerry
diff --git a/unix/serial.fs b/unix/serial.fs
index 27960e6..4ae1611 100644
--- a/unix/serial.fs
+++ b/unix/serial.fs
@@ -16,6 +16,7 @@ c-library serial
     c-function fdopen fdopen n a -- a ( fd mode -- file )
     c-function read read n a n -- n ( fd addr u -- u' )
     c-function write write n a n -- n ( fd addr u -- u' )
+    c-function close close n -- n ( fd -- r )
 end-c-library
 
 [IFDEF] android
@@ -84,6 +85,8 @@ base @ 8 base !
 000000010017 Constant CBAUD
 000000000001 Constant IGNBRK
 000000000004 Constant IGNPAR
+000000000400 Constant NOCTTY
+000000004000 Constant NODELAY
 base !
 
 5 Constant VTIME
@@ -102,7 +105,7 @@ $541B Constant FIONREAD
     r> 0 t_buf tcsetattr drop ;
 
 : reset-baud ( fd -- )
-    t_old 0 rot tcsetattr drop ;
+    0 t_old tcsetattr drop ;
 
 : check-read ( fd -- n )  >r
     0 sp@ r> fileno FIONREAD rot ioctl drop ;

Reply via email to