Hi everybody, im trying to do the LEDs experiment in linux but in
kinda stuck. I saw that in Windows there is a package to access the
parallel port and turn certain pins on/off at will.
Can somebody please tell me how to do this on linux? I read somewhere
that i just need to open the device ( /dev/parpoert[n] ) as a regular
file and just write a string into it... Its true? What kind of string?
A regular text one or a binary one?
Thank you very much.
Regards
JB
|
|
0
|
|
|
|
Reply
|
Javier
|
2/9/2011 9:56:35 PM |
|
On Feb 9, 10:56=A0pm, Javier Basisty <javier.basi...@gmail.com> wrote:
> Hi everybody, im trying to do the LEDs experiment in linux but in
> kinda stuck. I saw that in Windows there is a package to access the
> parallel port and turn certain pins on/off at will.
>
> Can somebody please tell me how to do this on linux? I read somewhere
> that i just need to open the device ( /dev/parpoert[n] ) as a regular
> file and just write a string into it... Its true? What kind of string?
> A regular text one or a binary one?
Hmm, this seems to imply that it's a bit more involved (mandatory
ioctls):
http://people.redhat.com/twaugh/parport/html/x916.html
The Tcl way of doing that, in this case, would be to [open |cmd r+],
where "cmd" is some standalone executable doing the necssary ioctls
and I/O (like netcat deos for sockets). Dunno whether such a beast
exists...
Alternatively, you can use Ffidl and directly call ioctl(). But
definitely less elegant than we'd like :/
-Alex
|
|
0
|
|
|
|
Reply
|
Alexandre
|
2/9/2011 10:34:11 PM
|
|
Alexandre Ferrieux wrote:
> On Feb 9, 10:56 pm, Javier Basisty <javier.basi...@gmail.com> wrote:
>
>>Hi everybody, im trying to do the LEDs experiment in linux but in
>>kinda stuck. I saw that in Windows there is a package to access the
>>parallel port and turn certain pins on/off at will.
>>
>>Can somebody please tell me how to do this on linux? I read somewhere
>>that i just need to open the device ( /dev/parpoert[n] ) as a regular
>>file and just write a string into it... Its true? What kind of string?
>>A regular text one or a binary one?
>
>
> Hmm, this seems to imply that it's a bit more involved (mandatory
> ioctls):
>
> http://people.redhat.com/twaugh/parport/html/x916.html
>
> The Tcl way of doing that, in this case, would be to [open |cmd r+],
> where "cmd" is some standalone executable doing the necssary ioctls
> and I/O (like netcat deos for sockets). Dunno whether such a beast
> exists...
>
> Alternatively, you can use Ffidl and directly call ioctl(). But
> definitely less elegant than we'd like :/
>
> -Alex
you can reduce it to a simple setup if you are happy with 8 bit bang lines:
connect Strobe (1) to Ack (10) . connect D0 .. D7 to your liking.
see to it that no printer service is using your port /dev/lpX
rccups stop ... ; rclpd stop ...
see to it that you have proper access rights to your port.
set fd [ open /dev/lpX w ]
# configure for no buffering and no translation
fconfigure $lp -buffering none -translation none
set bitpattern {11101011}
puts -nonewline [ binary format b* $bitpattern ]
rinse repeat banging away on your port bits ;-)
I've used the ppdev functionality extensively ( but with c code )
could be interesting to have a swig wrapper for that.
uwe
|
|
0
|
|
|
|
Reply
|
Uwe
|
2/10/2011 8:03:10 AM
|
|
"Uwe Klein" <uwe_klein_habertwedt@t-online.de> wrote in message
news:umic28-oho.ln1@klein-habertwedt.de...
> you can reduce it to a simple setup if you are happy with 8 bit bang
> lines:
>
> connect Strobe (1) to Ack (10)
I'm guessing that's to satisfy the need for handshaking, which is ON by
default. When I had a similar need to write to a parallel port without
handshaking, I wrote a little C library that implements a [nohandshake]
command in Tcl so you can turn off handshaking with an ioctl instead of a
loopback. Here's the code (written for Solaris, but it demonstrates the
concept):
/*
Tcl Parallel Port Extension
This code compiles into a shared library which is loadable by Tcl and
implements the [nohandshake] command to disable handshaking on a
parallel port. The command takes exactly one argument, the name of
a channel to a writable parallel port. If successful, the command
returns the unix file handle; otherwise it returns nothing. If it was
compiled with DEBUG turned on, it prints portParms.write_handshake on
stdout before and after. A typical use of the command would be:
load ../tclbpp/tclbpp.so ;# load this library
set demod [open /dev/bpp0 w] ;# open parallel port for writing
If you write to the parallel port at this point, it will hang!
The default handshaking is BPP_ACK_HS, and the demod doesn't provide
any handshaking. You can load the library and open the port in either
order. Continue as follows:
nohandshake $demod ;# disable handshaking
puts $demod [stuff] ;# write to parallel port
010918 jjs - Created.
*/
#include <tcl.h>
#include <unistd.h>
#include <sys/bpp_io.h>
/*
This is the implementation of the "nohandshake" command itself.
*/
int
nhsCmd(ClientData clientData, Tcl_Interp *interp, int objc,
Tcl_Obj *CONST objv[])
{
Tcl_Channel chan;
int eid;
struct bpp_transfer_parms portParms;
/* Must be invoked with 1 arg */
if (objc != 2)
{
Tcl_WrongNumArgs(interp, 1, objv, "channel");
return TCL_ERROR;
}
/* Get channel specified by arg */
chan = Tcl_GetChannel(interp, Tcl_GetString(objv[1]), NULL);
if (chan == NULL)
{
return TCL_ERROR;
}
/* Get handle for channel */
if (Tcl_GetChannelHandle(chan, TCL_WRITABLE, &eid) == TCL_ERROR)
{
return TCL_ERROR;
}
/* Get port parameters */
if (ioctl(eid, BPPIOC_GETPARMS, &portParms) < 0)
{
return TCL_ERROR;
}
#ifdef DEBUG
printf("was %d\n", (int) portParms.write_handshake);
#endif
/* Configure for no handshaking; it's normally BPP_ACK_HS */
portParms.write_handshake = BPP_NO_HS;
/* Set port parameters */
if (ioctl(eid, BPPIOC_SETPARMS, &portParms) < 0)
{
return TCL_ERROR;
}
#ifdef DEBUG
/* Get port parameters for verification */
if (ioctl(eid, BPPIOC_GETPARMS, &portParms) < 0)
{
return TCL_ERROR;
}
printf("now %d\n", (int) portParms.write_handshake);
#endif
/* Return file handle */
Tcl_SetObjResult(interp, Tcl_NewIntObj(eid));
return TCL_OK;
}
/*
This is the initialization function called when Tcl loads the library.
*/
int
Tclbpp_Init(Tcl_Interp *interp)
{
int i;
/* Install the "nohandshake" command */
Tcl_CreateObjCommand(interp, "nohandshake", nhsCmd,
(ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
/* Publicize the package info */
Tcl_PkgProvide(interp, "tclbpp", "0.1");
return TCL_OK;
}
|
|
0
|
|
|
|
Reply
|
John
|
2/10/2011 8:22:34 PM
|
|
Hi,
I used the parashell
(http://linux.softpedia.com/get/Science/parashell-33240.shtmlexecutable)
for that from the tcl script to control the parallel port.
Br,
Torsten
Am 09.02.2011 23:34, schrieb Alexandre Ferrieux:
> The Tcl way of doing that, in this case, would be to [open |cmd r+],
> where "cmd" is some standalone executable doing the necssary ioctls
> and I/O (like netcat deos for sockets). Dunno whether such a beast
> exists...
> -Alex
|
|
0
|
|
|
|
Reply
|
T
|
2/10/2011 9:47:52 PM
|
|
|
4 Replies
419 Views
(page loaded in 0.087 seconds)
|