At Wed, 27 Sep 2017 20:56:41 +0200 Gerhard Reithofer <
gerhard....@tech-edv.co.at> wrote:
>
> Hi TCLers,
> I woud like to communicate with my new 3d printer using the existing USB
> interface. The hardware is proprietary and no detailed information
> exists about the USB interface, except the serial line configuration
> values.
>
> TCL's "open" manpage: "Valid values for fileName to open a serial port
> are generally of the form /dev/ttyX, where X is a or b, but the name of
> any pseudo-file that maps to a serial port may be used ..."
Note: What Tcl calls a "Serial Port" is a RS232 or RS485 port, what on an
"old" PC would have been a DB-25 (really old PC) or a DB-9 (moderatly old PC).
These ports would be commonly connected to something like a telephone modem
(remember those?) or even a teletype device (usually a "glass" successor to a
Model 33, eg a VT52, VT100, or something like that). There were (back in the
day) other devices that used the RS232 interface: some serial printers, serial
mice, and other things (I have a EPROM programmer that uses the RS232
interface, a DCC interface that uses RS232, and several C/MRI SuperMini boards
that use the RS485 interface).
The USB interface is something *completely different* and bears absolutely no
relation to a "Serial Port". A USB "port" is NOT a "Serial Port".
There is a "class" of USB devices that bind to psuedo RS232-ish "serial
ports". These are either devices that have a good old DB-9 connector (just
like on those moderately old PCs) or they have the RS232 "pins" 'wired' into a
uProcessor (this is what the Arduino does, as is also the case for some USB
connected modems and various other interesting devices (like all of the USB
connected DCC devices, the CTI Acela, the RR Cirkits LCC Buffer-USB, to name a
few). All of these devices show up as either a /dev/ttyACMn (if they are
using a modem-flavored chip) or /dev/ttyUSBn (otherwise -- basicly it is the
driver's choise). All of these devices can be treated just like a real live
RS232 device and Tcl is happy to open them up and do all of the Serial Port
things with them. Note: not all "Serial Port" chips are supported in all
Linux kernels. If this thing really is a "Serial Port", you might need to get
a kernel driver module for it. What verison of Linux are you running? What
does 'uname -a' spit out?
>
> Using the device information I can find the USB device path and I tried
> it to open it as serial device:
>
> $ lsusb -d 2b71:
> Bus 002 Device 027: ID 2b71:0001
>
> $ ls -l /dev/bus/usb/002/027
> crw-rw-rw- 1 root root 189, 154 Sep 27 16:31 /dev/bus/usb/002/027
>
> $ tclsh
> % set conn [open /dev/bus/usb/002/027 {RDWR}]
> file3
> % fconfigure $conn -mode "115200,8,n,1" -handshake "none"
> bad option "-mode": should be one of -blocking, -buffering, -buffersize,
> -encoding, -eofchar, or -translation
>
> My question is: How does TCL recognize that this pseudo-file is no
> serial device?
Short answer wrong driver interface. (See above for the long answer.)
>
> And further: Any ideas to make this access possible?
1) beg, borrow, or steal a copy of the Mess-Windows device driver or SDK:
You may be able to get away with the "SDK" for this device -- *some*
companies offer a free SDK package that you can use to reverse engineer a
"driver". You can then write a user-mode driver in C/C++ using libusb and
create a Tcl interface binding with SWIG. I did this with the PI
Engineering Raildriver (later rewrote things to use the HID API, because
that was a more cross-platform option). (I also did this with the Azatrax
MRD2 devices -- there I was approached by the designer for just that
purpose and he provided detailed docs.) (All of the code for this is
available on GitHub:
https://github.com/RobertPHeller/ModelRRSystem and
there are pure Tcl coded "drivers" for various serial port flavered devices
as well.)
2) you could get lucky: check what dmesg blathers about when you plug the
device in:
a) unplug the device
b) type in a terminal window:
'tail -f /var/log/dmesg'
(alternitively, type 'dmesg | tail -30' *after* pluging in the device).
Then plug the device in. There will be blather about a 'new' USB device.
*If* the blather talks about /dev/ttyACM<mumble> or /dev/ttyUSB<mumble>,
you have a shot of accessing the device directly from Tcl without
resorting to the C/C++ compiler, libusb, and fun with the likes of SWIG.
Note: you will still need to know or figure out the "protocol" used to
talk to the device (control character fun? Lines of ASCII text? Async
fun? etc.), so it might be worth the beg/borrow/steal game
mentioned above.
>
> TIA,
> Gerhard
>
--
Robert Heller --
978-544-6933
Deepwoods Software -- Custom Software Services
http://www.deepsoft.com/ -- Linux Administration Services
hel...@deepsoft.com -- Webhosting Services