cforth icon indicating copy to clipboard operation
cforth copied to clipboard

access to serial port linux

Open arblake opened this issue 3 years ago • 1 comments

Not a bug but use difficulty I wish to access the serial port on linux. I tried this, what is wrong?

variable serid 9600 constant baudrate create buf 59 cells allot 0 open-com serid swap ! buf 25 100 serid @ timed-read-com

The device sends a string ever second.

arblake avatar Feb 28 '21 09:02 arblake

  • I don't understand the "swap" after open-com . The stack diagram for ! is ( n address -- )
  • Your code has no error check of the value returned by open-com . If the return value is -1, the operation failed. I do not know whether or not that happened, from what you report.
  • As an alternative to "create buf 59 cells allot", it is better to allocate buffers with "59 cells buffer: buf" . That works better for code that will ultimately be compiled, because the space is dynamically allocated as needed, instead of going in the dictionary, which might be partially in read-only FLASH on some systems.
  • timed-read-com returns the number of bytes actually received. If the operation times out without having received any bytes, timed-read-com returns 0. You did not say what value timed-read-com returned, so I cannot tell what it did.

MitchBradley avatar Mar 05 '21 19:03 MitchBradley