gforth
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gforth] Debugging serial I/O to USB RS232 port


From: Jerry DeLisle
Subject: [gforth] Debugging serial I/O to USB RS232 port
Date: Fri, 31 Oct 2014 17:21:24 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.7.0

I have found a curious problem.

I have two different USB to RS-232 devices I am testing with on Linux based 
system.

With one of the devices the following works without problem, the other hangs.

0 Value port
: open-port  ( addr u -- )  r/w open-file throw to port ;

s" /dev/ttyUSB0" open-port

Using the device that hangs requires a Ctrl-C at the gforth command terminal to bring back the "ok" prompt.

The following C code works for both devices.

int
open_port (void)
{
  int fd; /* File descriptor for the port */

  fd = open ("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY);
  if (fd == -1) /* Could not open the port.  */
    perror("open_port: Unable to open /dev/ttyUSB0 ");
  else
    fcntl (fd, F_SETFL, 0);

  return (fd);
}

To attempt to emulate the working C code I tried the following:

256  CONSTANT noctty
2048 CONSTANT ndelay
0 Value port
: open-port  ( addr u -- )  r/w noctty ndelay + +
    open-file throw to port ;

s" /dev/ttyUSB0" open-port

This also hangs with the one device.

Looking through the gforth engine code, support.c (guessing this is the spot)

I see where I think the wfam is being truncated, at line 113:

fd = open(s, flags|ufileattr[wfam & 0x0F], (wfam >> 4) ^ 0666);
                             ^^^^^^^^^^^
I would prefer to not add additional interface C code to gforth.

Am I understanding this correctly?

Any suggestions on how to pass those flags to an open?

Is there another primitive I should be using instead?


Regards,

Jerry





reply via email to

[Prev in Thread] Current Thread [Next in Thread]