yetanotherdjmorris <> [2010-10-12 20:57:47]:
> I have a TS-7260 trying to communicate with an RS232 device (a motor). I
> can open my port, set my baud, send data to the device, the motor moves,
> sends a response back, which I can read. Then I start a polling loop where
> I continually call iReturn = ioctl(fd, FIONREAD, &iBytesAvail) and then
> sleep for 20ms. Eventually (like after 100 iterations), this returns -1
> with an errno = EIO (input/output error). I can close the port and reopen
> and it works, but again, only for a few seconds before I get that error
> again.
>
> Any thoughts?
I'm repeating myself, but why is everybody reinventing the wheel again and
again? I know, that using RS232 port is such a common task, that I wrote a
library[1] for it, licensed it under very liberal MIT license, so everybody
can use it. You can use it in the same way under Linux, Windows and even under
Windows CE/Mobile. There's even a Lua bindings, so you can use it for fast
prototyping, example (-- is one line comment in Lua):
:~/$ lua
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
> rs232 = require("luars232") -- loads the RS232 library
>
> error, port = rs232.open("/dev/ttyAM0") -- opens the port
> port:set_baud_rate(rs232.RS232_BAUD_115200) -- sets baudrate to 115200
>
> read = 5 -- read just bytes
> timeout = 20 -- miliseconds
> error, data, len = port:read(read, timeout) -- read the data
> if len == read then -- if we've read 5 bytes, send OK to the sender
> port:write("OK\n")
> end
> port:close() -- cleanup
BTW Lua is really fast, so in most of the cases, I would say in 99%, you don't
even need to write any C code, you'll just need to compile the luars232
library and Lua. You can even prototype it on the desktop PC and then just
copy the final Lua script to the device and it should work in the same way as
it was working on the desktop. Easy, fast.
1. http://github.com/ynezz/librs232
-- ynezz
------------------------------------
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/ts-7000/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/ts-7000/join
(Yahoo! ID required)
<*> To change settings via email:
<*> To unsubscribe from this group, send an email to:
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|