Re: [Gambas-user] Parallel Port - Illegal Seek -

2010-04-08 Thread Doriano Blengino
mike ha scritto:
 On 04/07/2010 02:47 PM, nando wrote:
   
 Seek will not change the address.


 -- Original Message ---
 From: Doriano Blenginodoriano.bleng...@fastwebnet.it
 To: nand...@nothingsimple.com, mailing list for gambas users
 gambas-user@lists.sourceforge.net
 Sent: Wed, 07 Apr 2010 11:06:42 +0200
 Subject: Re: [Gambas-user] Parallel Port - Illegal Seek -


 
 nando ha scritto:
  
   
 Using SEEK is not correct.
 If you think of the parallel port as a file, you cannot seek.
 It doesn't make sense.
 You can only read and write.
 What are you trying to accomplish ?
 -Fernando


 
 He is trying to do low level access to the parallel port, which has 3
 hardware addresses.
 In that respect, seek() would make sense to select which IO address to
 read from/write to.
 Whether this works or not, depends on how the kernel driver interprets
 the seeks, but the following listing makes it clear that somewhere
 (other OSes?) this behavior works.
 The error could also arise from other problems: permissions, missing
 modules, wrong major/minor numbers and so on...

 Regards,
 Doriano
   
How already stated in a previous email, it is possible to access I/O 
ports in different manners.
After a research, I discovered two viable ways - direct access (I don't 
know if gambas has I/O instructions), and /dev/port, which is a device. 
In this last case seek() is used to address a port.

 From http://tldp.org/HOWTO/IO-Port-Programming-2.html :

 Another way to access I/O ports is to |open()| |/dev/port| (a 
 character device, major number 1, minor 4) for reading and/or writing 
 (the stdio |f*()| functions have internal buffering, so avoid them). 
 Then |lseek()| to the appropriate byte in the file (file position 0 = 
 port 0x00, file position 1 = port 0x01, and so on), and |read()| or 
 |write()| a byte or word from or to it.

 Naturally, for this to work your program needs read/write access to 
 |/dev/port|. This method is probably slower than the normal method 
 above, but does not need compiler optimisation nor |ioperm()|. It 
 doesn't need root access either, if you give a non-root user or group 
 access to |/dev/port| --- but this is a very bad thing... [about 
 security]...
Using /dev/port can be problematic: can gambas do unbuffered I/O?

Other methods would be to use some external program or library (shared 
object). If gambas does not have I/O (peek  poke), then an external 
library is the most performant way, though not the simpler. Gambas can 
interface with external libraries using EXTERNAL declaration.

Googling about this issue, I found some interesting page:
http://tldp.org/HOWTO/IO-Port-Programming-2.html
http://www.epanorama.net/circuits/parallel_output.html
http://www.faqs.org/docs/Linux-mini/IO-Port-Programming.html
http://cyberelk.net/tim/parport/parport.html
http://people.redhat.com/twaugh/parport/html/ppdev.html

The best way would be to write a gambas component, having either 
internal I/O instructions (a C component) or relying to an external 
library (a gambas component calling an external library; may be there is 
something already done somewhere).

Hey, gambas gurus out there... someone has the time? I do not.

Regards,
Doriano


--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Parallel Port - Illegal Seek -

2010-04-08 Thread Benoît Minisini
 Hi All,
 
 I am writing a parallel port interface, however I am struggling with how to
 write to the parallel port.  Below I have included the code that I have
 used.  Following that I have included the BASIC code that I am
 bastardizing.
 
 My Gambas version is Gambas2.13
 I am running Linux Mint 8
 I do have a parallel port on my PC. It is '0378' - '037a' and '0778' -
 '077a'
 The error code I am getting is System error. illegal seek
 
 Thanks in advance for any help anyone can give.
 -GAMBAS
 2 CODE FOLLOWS-- '
 Gambas module file
 PUBLIC SUB Main()
 
 DIM N AS Integer
 DIM pin AS Integer
 DIM pinout AS Integer[] = [0, 0, 0, 0, 0, 0, 0, 0]
 DIM pump AS Integer
 DIM Ptime AS Integer
 DIM Clock AS Integer
 DIM UClock AS Integer
 DIM DClock AS Integer
 DIM commit AS Integer
 DIM poweron AS Integer
 DIM switch AS Integer
 DIM gate AS File
 DIM base0, base1, base2 AS Integer
 
 base0 = 0
 base1 = 1
 base2 = 2
 poweron = 64
 commit = 144
 switch = 17
 UClock = 130
 DClock = 128
   gate = OPEN /dev/parport0 FOR READ WRITE
   SEEK #gate, base0
   WRITE #gate, poweron
   FOR Ptime = 1 TO 2000 STEP 1
   NEXT
 
   SEEK #gate, base2
   WRITE #gate, switch
 
   GOTO START
 CommitChanges:
   FOR N = 0 TO 7 STEP 1
 pump = CInt(100  pinout[Fix(N)])
 Clock = CInt(101  pinout[Fix(N)])
 SEEK #gate, base0
 WRITE #gate, pump
 FOR Ptime = 1 TO 2000 STEP 1
 NEXT
 SEEK #gate, base0
 WRITE #gate, Clock
 FOR Ptime = 1 TO 2000 STEP 1
 NEXT
 SEEK #gate, base0
 WRITE #gate, pump
   NEXT
 FOR Ptime = 1 TO 2000 STEP 1
 NEXT
 
   FOR N = 1 TO 16 STEP 1
 SEEK #gate, base0
 WRITE #gate, UClock
 FOR Ptime = 1 TO 2000 STEP 1
 NEXT
 SEEK #gate, base0
 WRITE #gate, DClock
   NEXT
 FOR Ptime = 1 TO 2000 STEP 1
 NEXT
   SEEK #gate, base0
   WRITE #gate, commit
 FOR Ptime = 1 TO 2000 STEP 1
 NEXT
   SEEK #gate, base0
   WRITE #gate, poweron
   GOTO PrintPinout
 
 PrintPinout:
   FOR N = 0 TO 7 STEP 1
 PRINT pinout[Fix(N)]
   NEXT
   GOTO START
 
 PinSelectFail:
   PRINT You have selected a pin that does not exist, careful as this may
 cause a divide by 0 and end the universe,  Select between pin 0 and pin 7
   GOTO START
 
 START:
   PRINT What input do you want to toggle? (pins 0 - 7 are outputs, Pin 8
 is the activation sequence)
   INPUT pin
   IF pin  0 OR pin  8 THEN
 GOTO PinSelectFail
   ELSE IF pin = 8 THEN
 GOTO CommitChanges
   ELSE IF pinout[Fix(pin)] = 0 THEN
 pinout[Fix(pin)] = 1
   ELSE IF pinout[Fix(pin)] = 1 THEN
 pinout[Fix(pin)] = 0
   ENDIF
 GOTO PrintPinout
 END
 -Gambas
 2
 END---
 -
 
 
 
 
 -BASIC
 CODE FOLLOWS--
 
 BASE0=H378
 
 'SWITCH POWER AND OUTPUTS ON
 OUT BASE0, H80
 OUT BASE0 + 2, 11
 
 'DEFINE ALL DIGITAL OUTPUTS [OUT(N)] AS BEING OFF (0)
 FOR N = 0 TO 7
 DOUT(N) = 0
 NEXT N
 DOUT=0
 
 START:
 INPUT WHICH DIGITAL OUTPUT DO YOU WANT TO TOGGLE (0 TO 7); N
 IF N  0 OR N  7 THEN GOTO START
 N = FIX(N)
 DOUT9N0=ABS(NOT (-DOUT(N))) ' THIS LINE TOGGLES THE OUTPUT
 
 
 'CREATE COMPLETE BYTE FOR IC3 CALLED DOUT
 FOR N = 0 TO 7
 IF DOUT(N) = 0 THEN
 DOUT = DOUT AND NOT (2^N)
 ELSE
 DOUT = DOUT OR 2^N
 ENDIF
 NEXT N
 
 'SEND 8 CLOCK PULSES AND DIGITAL OUT DATA (ALL ZERO'S)
 FOR BIT = 1 TO 8
 B = 8 - BIT
 BYTE = ((DOUT AND 2^B) / 2^B) OR H80
 OUT BASE0, BYTE
 OUT BASE0, BYTE OR 2
OUT BASE0 BYTE
 NEXT BIT
 
 'SEND ANOTHER 16 CLOCK PULSES TO SHIFT THE DATA INTO IC3
 FOR BIT = 9 TO 24
 OUT BASE0, H82
 OUT BASE0, H80
 NEXT BIT
 
 'LOAD IC3
 OUT BASE0, H90
 OUT BASE0, h80]
 
 -BASIC
 END
 
 
 Bjorn Macintosh

Have you read http://gambasdoc.org/help/howto/parport?

Your program should work as expected if you open /dev/port, not 
/dev/parport0, if you seek at the true port address, and if you write bytes.

DIM poweron AS Byte ' -- note that

gate = OPEN /dev/parport0 FOR READ WRITE
SEEK #gate, H378
poweron = 1
WRITE #gate, poweron

And if you need to wait a little, use the SLEEP or WAIT instruction. See the 
documentation for details on these instructions.

I imagine that if you write Integer instead of Byte, then you will actually 
write the four bytes of the integer to four successive ports.

Regards,

-- 
Benoît Minisini

--
Download Intel#174; Parallel Studio Eval
Try the new software 

Re: [Gambas-user] Parallel Port

2010-04-08 Thread Les Hardy

Hi there, I don't have a program to offer you. All my old code is in 
other languages.
I did however write a little working example for you.
You will need to use port, not parport0.
For some reason that is unknown to me, I too, am unable to get parport 
to work correctly from gambas.

I tested the code below, and it does work. I ran it a few times on a 
system with Ubuntu 9.04, gambas 2.20, and a little parallel port tester 
I made 20 years ago.

Unless you have already sorted out permission to access 'port', you will 
need to be root to run it, either start gambas as root, or compile it 
and then run the executable as root.

PUBLIC SUB Main()
' Gambas module file
DIM pport AS File
DIM bi, bo AS Byte

pport = OPEN /dev/port FOR READ WRITE

FOR bo = 32 TO 122
  SEEK #pport, 888
  WRITE #pport, bo
  SEEK #pport, 888
  READ #pport, bi
  PRINT Chr(bi)   
  WAIT 0.05
NEXT
 CLOSE #pport

END

Just a quick mention about seek on ports.
Seek simply takes you to the port address. Notice I used a seek before 
each read or write.

888  (0x378): Data
889  (0x379): Status
890  0x37A) : Control



Hope this helps
Regards
Les Hardy


Bjorn Macintosh wrote:
 Hi all,

 Does anyone have a program that interfaces with the parallel port, one
 written in Gambas.  If you do would you be willing to share this program
 with me as I am trying to write a parallel port interface and am struggling
 to get my head around a few concepts.  mainly how to write to the port and
 how to select pin's base 0 base1 and base2.

 Any help would be greatly appreciated.  I sent a post two days ago holding
 the full details on my program and what I am trying to do if you  need any
 clarification.

 Thanks
 Bjorn Macintosh

   


--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Parallel Port

2010-04-08 Thread Benoît Minisini
 Hi there, I don't have a program to offer you. All my old code is in
 other languages.
 I did however write a little working example for you.
 You will need to use port, not parport0.
 For some reason that is unknown to me, I too, am unable to get parport
 to work correctly from gambas.
 
 I tested the code below, and it does work. I ran it a few times on a
 system with Ubuntu 9.04, gambas 2.20, and a little parallel port tester
 I made 20 years ago.
 
 Unless you have already sorted out permission to access 'port', you will
 need to be root to run it, either start gambas as root, or compile it
 and then run the executable as root.
 
 PUBLIC SUB Main()
 ' Gambas module file
 DIM pport AS File
 DIM bi, bo AS Byte
 
 pport = OPEN /dev/port FOR READ WRITE
 
 FOR bo = 32 TO 122
   SEEK #pport, 888
   WRITE #pport, bo
   SEEK #pport, 888
   READ #pport, bi
   PRINT Chr(bi)   
   WAIT 0.05
 NEXT
  CLOSE #pport
 
 END
 
 Just a quick mention about seek on ports.
 Seek simply takes you to the port address. Notice I used a seek before
 each read or write.
 
 888  (0x378): Data
 889  (0x379): Status
 890  0x37A) : Control
 
 
 
 Hope this helps
 Regards
 Les Hardy
 

And you can even look in the Linux kernel source code to see how /dev/port is 
implemented: a few lines of code in '/usr/src/linux/drivers/char/mem.c'.

Regards,

-- 
Benoît Minisini

--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Parallel Port - Illegal Seek -

2010-04-07 Thread Doriano Blengino
nando ha scritto:
 Using SEEK is not correct.
 If you think of the parallel port as a file, you cannot seek.
 It doesn't make sense.
 You can only read and write.
 What are you trying to accomplish ?
 -Fernando
   
He is trying to do low level access to the parallel port, which has 3 
hardware addresses.
In that respect, seek() would make sense to select which IO address to 
read from/write to.
Whether this works or not, depends on how the kernel driver interprets 
the seeks, but the following listing makes it clear that somewhere 
(other OSes?) this behavior works.
The error could also arise from other problems: permissions, missing 
modules, wrong major/minor numbers and so on...

Regards,
Doriano



 -- Original Message ---
 From: Bjorn Macintosh bjorn.macint...@gmail.com
 To: gambas-user@lists.sourceforge.net
 Sent: Fri, 2 Apr 2010 21:09:58 +1300
 Subject: [Gambas-user] Parallel Port - Illegal Seek -

   
 Hi All,

 I am writing a parallel port interface, however I am struggling with how to
 write to the parallel port.  Below I have included the code that I have
 used.  Following that I have included the BASIC code that I am bastardizing.

 My Gambas version is Gambas2.13
 I am running Linux Mint 8
 I do have a parallel port on my PC. It is '0378' - '037a' and '0778' -
 '077a'
 The error code I am getting is System error. illegal seek

 Thanks in advance for any help anyone can give.
 -GAMBAS2
 CODE FOLLOWS--
 ' Gambas module file
 PUBLIC SUB Main()

 DIM N AS Integer
 DIM pin AS Integer
 DIM pinout AS Integer[] = [0, 0, 0, 0, 0, 0, 0, 0]
 DIM pump AS Integer
 DIM Ptime AS Integer
 DIM Clock AS Integer
 DIM UClock AS Integer
 DIM DClock AS Integer
 DIM commit AS Integer
 DIM poweron AS Integer
 DIM switch AS Integer
 DIM gate AS File
 DIM base0, base1, base2 AS Integer

 base0 = 0
 base1 = 1
 base2 = 2
 poweron = 64
 commit = 144
 switch = 17
 UClock = 130
 DClock = 128
   gate = OPEN /dev/parport0 FOR READ WRITE
   SEEK #gate, base0
   WRITE #gate, poweron
   FOR Ptime = 1 TO 2000 STEP 1
   NEXT

   SEEK #gate, base2
   WRITE #gate, switch

   GOTO START
 CommitChanges:
   FOR N = 0 TO 7 STEP 1
 pump = CInt(100  pinout[Fix(N)])
 Clock = CInt(101  pinout[Fix(N)])
 SEEK #gate, base0
 WRITE #gate, pump
 FOR Ptime = 1 TO 2000 STEP 1
 NEXT
 SEEK #gate, base0
 WRITE #gate, Clock
 FOR Ptime = 1 TO 2000 STEP 1
 NEXT
 SEEK #gate, base0
 WRITE #gate, pump
   NEXT
 FOR Ptime = 1 TO 2000 STEP 1
 NEXT

   FOR N = 1 TO 16 STEP 1
 SEEK #gate, base0
 WRITE #gate, UClock
 FOR Ptime = 1 TO 2000 STEP 1
 NEXT
 SEEK #gate, base0
 WRITE #gate, DClock
   NEXT
 FOR Ptime = 1 TO 2000 STEP 1
 NEXT
   SEEK #gate, base0
   WRITE #gate, commit
 FOR Ptime = 1 TO 2000 STEP 1
 NEXT
   SEEK #gate, base0
   WRITE #gate, poweron
   GOTO PrintPinout

 PrintPinout:
   FOR N = 0 TO 7 STEP 1
 PRINT pinout[Fix(N)]
   NEXT
   GOTO START

 PinSelectFail:
   PRINT You have selected a pin that does not exist, careful as this may
 cause a divide by 0 and end the universe,  Select between pin 0 and pin 7
   GOTO START

 START:
   PRINT What input do you want to toggle? (pins 0 - 7 are outputs, Pin 8
 is the activation sequence)
   INPUT pin
   IF pin  0 OR pin  8 THEN
 GOTO PinSelectFail
   ELSE IF pin = 8 THEN
 GOTO CommitChanges
   ELSE IF pinout[Fix(pin)] = 0 THEN
 pinout[Fix(pin)] = 1
   ELSE IF pinout[Fix(pin)] = 1 THEN
 pinout[Fix(pin)] = 0
   ENDIF
 GOTO PrintPinout
 END
 -Gambas2
 END

 -BASIC
 CODE FOLLOWS--

 BASE0=H378

 'SWITCH POWER AND OUTPUTS ON
 OUT BASE0, H80
 OUT BASE0 + 2, 11

 'DEFINE ALL DIGITAL OUTPUTS [OUT(N)] AS BEING OFF (0)
 FOR N = 0 TO 7
 DOUT(N) = 0
 NEXT N
 DOUT=0

 START:
 INPUT WHICH DIGITAL OUTPUT DO YOU WANT TO TOGGLE (0 TO 7); N
 IF N  0 OR N  7 THEN GOTO START
 N = FIX(N)
 DOUT9N0=ABS(NOT (-DOUT(N))) ' THIS LINE TOGGLES THE OUTPUT

 'CREATE COMPLETE BYTE FOR IC3 CALLED DOUT
 FOR N = 0 TO 7
 IF DOUT(N) = 0 THEN
 DOUT = DOUT AND NOT (2^N)
 ELSE
 DOUT = DOUT OR 2^N
 ENDIF
 NEXT N

 'SEND 8 CLOCK PULSES AND DIGITAL OUT DATA (ALL ZERO'S)
 FOR BIT = 1 TO 8
 B = 8 - BIT
 BYTE = ((DOUT AND 2^B) / 2^B) OR H80
 OUT BASE0, BYTE
 OUT BASE0, BYTE OR 2
OUT BASE0 BYTE
 NEXT BIT

 'SEND ANOTHER 16 CLOCK PULSES TO SHIFT THE DATA INTO IC3
 FOR BIT = 9 TO 24
 OUT BASE0, H82
 OUT BASE0, H80
 NEXT BIT

 'LOAD IC3
 OUT BASE0, H90
 OUT BASE0, h80

Re: [Gambas-user] Parallel Port - Illegal Seek -

2010-04-07 Thread nando
Seek will not change the address.


-- Original Message ---
From: Doriano Blengino doriano.bleng...@fastwebnet.it
To: nand...@nothingsimple.com, mailing list for gambas users
gambas-user@lists.sourceforge.net
Sent: Wed, 07 Apr 2010 11:06:42 +0200
Subject: Re: [Gambas-user] Parallel Port - Illegal Seek -

 nando ha scritto:
  Using SEEK is not correct.
  If you think of the parallel port as a file, you cannot seek.
  It doesn't make sense.
  You can only read and write.
  What are you trying to accomplish ?
  -Fernando

 He is trying to do low level access to the parallel port, which has 3 
 hardware addresses.
 In that respect, seek() would make sense to select which IO address to 
 read from/write to.
 Whether this works or not, depends on how the kernel driver interprets 
 the seeks, but the following listing makes it clear that somewhere 
 (other OSes?) this behavior works.
 The error could also arise from other problems: permissions, missing 
 modules, wrong major/minor numbers and so on...
 
 Regards,
 Doriano
 
 
 
  -- Original Message ---
  From: Bjorn Macintosh bjorn.macint...@gmail.com
  To: gambas-user@lists.sourceforge.net
  Sent: Fri, 2 Apr 2010 21:09:58 +1300
  Subject: [Gambas-user] Parallel Port - Illegal Seek -
 

  Hi All,
 
  I am writing a parallel port interface, however I am struggling with how to
  write to the parallel port.  Below I have included the code that I have
  used.  Following that I have included the BASIC code that I am 
  bastardizing.
 
  My Gambas version is Gambas2.13
  I am running Linux Mint 8
  I do have a parallel port on my PC. It is '0378' - '037a' and '0778' -
  '077a'
  The error code I am getting is System error. illegal seek
 
  Thanks in advance for any help anyone can give.
  -GAMBAS2
  CODE FOLLOWS--
  ' Gambas module file
  PUBLIC SUB Main()
 
  DIM N AS Integer
  DIM pin AS Integer
  DIM pinout AS Integer[] = [0, 0, 0, 0, 0, 0, 0, 0]
  DIM pump AS Integer
  DIM Ptime AS Integer
  DIM Clock AS Integer
  DIM UClock AS Integer
  DIM DClock AS Integer
  DIM commit AS Integer
  DIM poweron AS Integer
  DIM switch AS Integer
  DIM gate AS File
  DIM base0, base1, base2 AS Integer
 
  base0 = 0
  base1 = 1
  base2 = 2
  poweron = 64
  commit = 144
  switch = 17
  UClock = 130
  DClock = 128
gate = OPEN /dev/parport0 FOR READ WRITE
SEEK #gate, base0
WRITE #gate, poweron
FOR Ptime = 1 TO 2000 STEP 1
NEXT
 
SEEK #gate, base2
WRITE #gate, switch
 
GOTO START
  CommitChanges:
FOR N = 0 TO 7 STEP 1
  pump = CInt(100  pinout[Fix(N)])
  Clock = CInt(101  pinout[Fix(N)])
  SEEK #gate, base0
  WRITE #gate, pump
  FOR Ptime = 1 TO 2000 STEP 1
  NEXT
  SEEK #gate, base0
  WRITE #gate, Clock
  FOR Ptime = 1 TO 2000 STEP 1
  NEXT
  SEEK #gate, base0
  WRITE #gate, pump
NEXT
  FOR Ptime = 1 TO 2000 STEP 1
  NEXT
 
FOR N = 1 TO 16 STEP 1
  SEEK #gate, base0
  WRITE #gate, UClock
  FOR Ptime = 1 TO 2000 STEP 1
  NEXT
  SEEK #gate, base0
  WRITE #gate, DClock
NEXT
  FOR Ptime = 1 TO 2000 STEP 1
  NEXT
SEEK #gate, base0
WRITE #gate, commit
  FOR Ptime = 1 TO 2000 STEP 1
  NEXT
SEEK #gate, base0
WRITE #gate, poweron
GOTO PrintPinout
 
  PrintPinout:
FOR N = 0 TO 7 STEP 1
  PRINT pinout[Fix(N)]
NEXT
GOTO START
 
  PinSelectFail:
PRINT You have selected a pin that does not exist, careful as this may
  cause a divide by 0 and end the universe,  Select between pin 0 and pin 7
GOTO START
 
  START:
PRINT What input do you want to toggle? (pins 0 - 7 are outputs, Pin 8
  is the activation sequence)
INPUT pin
IF pin  0 OR pin  8 THEN
  GOTO PinSelectFail
ELSE IF pin = 8 THEN
  GOTO CommitChanges
ELSE IF pinout[Fix(pin)] = 0 THEN
  pinout[Fix(pin)] = 1
ELSE IF pinout[Fix(pin)] = 1 THEN
  pinout[Fix(pin)] = 0
ENDIF
  GOTO PrintPinout
  END
  -Gambas2
  END
 
  -BASIC
  CODE FOLLOWS--
 
  BASE0=H378
 
  'SWITCH POWER AND OUTPUTS ON
  OUT BASE0, H80
  OUT BASE0 + 2, 11
 
  'DEFINE ALL DIGITAL OUTPUTS [OUT(N)] AS BEING OFF (0)
  FOR N = 0 TO 7
  DOUT(N) = 0
  NEXT N
  DOUT=0
 
  START:
  INPUT WHICH DIGITAL OUTPUT DO YOU WANT TO TOGGLE (0 TO 7); N
  IF N  0 OR N  7 THEN GOTO START
  N = FIX(N)
  DOUT9N0=ABS(NOT (-DOUT(N))) ' THIS LINE TOGGLES THE OUTPUT
 
  'CREATE COMPLETE BYTE FOR IC3 CALLED DOUT
  FOR N = 0 TO 7
  IF DOUT(N) = 0 THEN
  DOUT = DOUT AND NOT (2^N)
  ELSE

Re: [Gambas-user] Parallel Port - Illegal Seek -

2010-04-07 Thread mike
On 04/07/2010 02:47 PM, nando wrote:
 Seek will not change the address.


 -- Original Message ---
 From: Doriano Blenginodoriano.bleng...@fastwebnet.it
 To: nand...@nothingsimple.com, mailing list for gambas users
 gambas-user@lists.sourceforge.net
 Sent: Wed, 07 Apr 2010 11:06:42 +0200
 Subject: Re: [Gambas-user] Parallel Port - Illegal Seek -


 nando ha scritto:
  
 Using SEEK is not correct.
 If you think of the parallel port as a file, you cannot seek.
 It doesn't make sense.
 You can only read and write.
 What are you trying to accomplish ?
 -Fernando


 He is trying to do low level access to the parallel port, which has 3
 hardware addresses.
 In that respect, seek() would make sense to select which IO address to
 read from/write to.
 Whether this works or not, depends on how the kernel driver interprets
 the seeks, but the following listing makes it clear that somewhere
 (other OSes?) this behavior works.
 The error could also arise from other problems: permissions, missing
 modules, wrong major/minor numbers and so on...

 Regards,
 Doriano

  

 -- Original Message ---
 From: Bjorn Macintoshbjorn.macint...@gmail.com
 To: gambas-user@lists.sourceforge.net
 Sent: Fri, 2 Apr 2010 21:09:58 +1300
 Subject: [Gambas-user] Parallel Port - Illegal Seek -



 Hi All,

 I am writing a parallel port interface, however I am struggling with how to
 write to the parallel port.  Below I have included the code that I have
 used.  Following that I have included the BASIC code that I am 
 bastardizing.

 My Gambas version is Gambas2.13
 I am running Linux Mint 8
 I do have a parallel port on my PC. It is '0378' - '037a' and '0778' -
 '077a'
 The error code I am getting is System error. illegal seek

 Thanks in advance for any help anyone can give.
 -GAMBAS2
 CODE FOLLOWS--
 ' Gambas module file
 PUBLIC SUB Main()

 DIM N AS Integer
 DIM pin AS Integer
 DIM pinout AS Integer[] = [0, 0, 0, 0, 0, 0, 0, 0]
 DIM pump AS Integer
 DIM Ptime AS Integer
 DIM Clock AS Integer
 DIM UClock AS Integer
 DIM DClock AS Integer
 DIM commit AS Integer
 DIM poweron AS Integer
 DIM switch AS Integer
 DIM gate AS File
 DIM base0, base1, base2 AS Integer

 base0 = 0
 base1 = 1
 base2 = 2
 poweron = 64
 commit = 144
 switch = 17
 UClock = 130
 DClock = 128
gate = OPEN /dev/parport0 FOR READ WRITE
SEEK #gate, base0
WRITE #gate, poweron
FOR Ptime = 1 TO 2000 STEP 1
NEXT

SEEK #gate, base2
WRITE #gate, switch

GOTO START
 CommitChanges:
FOR N = 0 TO 7 STEP 1
  pump = CInt(100  pinout[Fix(N)])
  Clock = CInt(101  pinout[Fix(N)])
  SEEK #gate, base0
  WRITE #gate, pump
  FOR Ptime = 1 TO 2000 STEP 1
  NEXT
  SEEK #gate, base0
  WRITE #gate, Clock
  FOR Ptime = 1 TO 2000 STEP 1
  NEXT
  SEEK #gate, base0
  WRITE #gate, pump
NEXT
  FOR Ptime = 1 TO 2000 STEP 1
  NEXT

FOR N = 1 TO 16 STEP 1
  SEEK #gate, base0
  WRITE #gate, UClock
  FOR Ptime = 1 TO 2000 STEP 1
  NEXT
  SEEK #gate, base0
  WRITE #gate, DClock
NEXT
  FOR Ptime = 1 TO 2000 STEP 1
  NEXT
SEEK #gate, base0
WRITE #gate, commit
  FOR Ptime = 1 TO 2000 STEP 1
  NEXT
SEEK #gate, base0
WRITE #gate, poweron
GOTO PrintPinout

 PrintPinout:
FOR N = 0 TO 7 STEP 1
  PRINT pinout[Fix(N)]
NEXT
GOTO START

 PinSelectFail:
PRINT You have selected a pin that does not exist, careful as this may
 cause a divide by 0 and end the universe,  Select between pin 0 and pin 7
GOTO START

 START:
PRINT What input do you want to toggle? (pins 0 -  7 are outputs, Pin 
 8
 is the activation sequence)
INPUT pin
IF pin  0 OR pin  8 THEN
  GOTO PinSelectFail
ELSE IF pin = 8 THEN
  GOTO CommitChanges
ELSE IF pinout[Fix(pin)] = 0 THEN
  pinout[Fix(pin)] = 1
ELSE IF pinout[Fix(pin)] = 1 THEN
  pinout[Fix(pin)] = 0
ENDIF
 GOTO PrintPinout
 END
 -Gambas2
 END

 -BASIC
 CODE FOLLOWS--

 BASE0=H378

 'SWITCH POWER AND OUTPUTS ON
 OUT BASE0,H80
 OUT BASE0 + 2, 11

 'DEFINE ALL DIGITAL OUTPUTS [OUT(N)] AS BEING OFF (0)
 FOR N = 0 TO 7
  DOUT(N) = 0
 NEXT N
 DOUT=0

 START:
  INPUT WHICH DIGITAL OUTPUT DO YOU WANT TO TOGGLE (0 TO 7); N
  IF N  0 OR N  7 THEN GOTO START
  N = FIX(N)
  DOUT9N0=ABS(NOT (-DOUT(N))) ' THIS LINE TOGGLES THE OUTPUT

 'CREATE COMPLETE BYTE FOR IC3 CALLED DOUT
  FOR N = 0 TO 7
  IF DOUT(N) = 0 THEN
  DOUT = DOUT AND NOT (2^N)
  ELSE
  DOUT = DOUT OR 2^N

Re: [Gambas-user] Parallel Port - Illegal Seek -

2010-04-06 Thread nando
Using SEEK is not correct.
If you think of the parallel port as a file, you cannot seek.
It doesn't make sense.
You can only read and write.
What are you trying to accomplish ?
-Fernando



-- Original Message ---
From: Bjorn Macintosh bjorn.macint...@gmail.com
To: gambas-user@lists.sourceforge.net
Sent: Fri, 2 Apr 2010 21:09:58 +1300
Subject: [Gambas-user] Parallel Port - Illegal Seek -

 Hi All,
 
 I am writing a parallel port interface, however I am struggling with how to
 write to the parallel port.  Below I have included the code that I have
 used.  Following that I have included the BASIC code that I am bastardizing.
 
 My Gambas version is Gambas2.13
 I am running Linux Mint 8
 I do have a parallel port on my PC. It is '0378' - '037a' and '0778' -
 '077a'
 The error code I am getting is System error. illegal seek
 
 Thanks in advance for any help anyone can give.
 -GAMBAS2
 CODE FOLLOWS--
 ' Gambas module file
 PUBLIC SUB Main()
 
 DIM N AS Integer
 DIM pin AS Integer
 DIM pinout AS Integer[] = [0, 0, 0, 0, 0, 0, 0, 0]
 DIM pump AS Integer
 DIM Ptime AS Integer
 DIM Clock AS Integer
 DIM UClock AS Integer
 DIM DClock AS Integer
 DIM commit AS Integer
 DIM poweron AS Integer
 DIM switch AS Integer
 DIM gate AS File
 DIM base0, base1, base2 AS Integer
 
 base0 = 0
 base1 = 1
 base2 = 2
 poweron = 64
 commit = 144
 switch = 17
 UClock = 130
 DClock = 128
   gate = OPEN /dev/parport0 FOR READ WRITE
   SEEK #gate, base0
   WRITE #gate, poweron
   FOR Ptime = 1 TO 2000 STEP 1
   NEXT
 
   SEEK #gate, base2
   WRITE #gate, switch
 
   GOTO START
 CommitChanges:
   FOR N = 0 TO 7 STEP 1
 pump = CInt(100  pinout[Fix(N)])
 Clock = CInt(101  pinout[Fix(N)])
 SEEK #gate, base0
 WRITE #gate, pump
 FOR Ptime = 1 TO 2000 STEP 1
 NEXT
 SEEK #gate, base0
 WRITE #gate, Clock
 FOR Ptime = 1 TO 2000 STEP 1
 NEXT
 SEEK #gate, base0
 WRITE #gate, pump
   NEXT
 FOR Ptime = 1 TO 2000 STEP 1
 NEXT
 
   FOR N = 1 TO 16 STEP 1
 SEEK #gate, base0
 WRITE #gate, UClock
 FOR Ptime = 1 TO 2000 STEP 1
 NEXT
 SEEK #gate, base0
 WRITE #gate, DClock
   NEXT
 FOR Ptime = 1 TO 2000 STEP 1
 NEXT
   SEEK #gate, base0
   WRITE #gate, commit
 FOR Ptime = 1 TO 2000 STEP 1
 NEXT
   SEEK #gate, base0
   WRITE #gate, poweron
   GOTO PrintPinout
 
 PrintPinout:
   FOR N = 0 TO 7 STEP 1
 PRINT pinout[Fix(N)]
   NEXT
   GOTO START
 
 PinSelectFail:
   PRINT You have selected a pin that does not exist, careful as this may
 cause a divide by 0 and end the universe,  Select between pin 0 and pin 7
   GOTO START
 
 START:
   PRINT What input do you want to toggle? (pins 0 - 7 are outputs, Pin 8
 is the activation sequence)
   INPUT pin
   IF pin  0 OR pin  8 THEN
 GOTO PinSelectFail
   ELSE IF pin = 8 THEN
 GOTO CommitChanges
   ELSE IF pinout[Fix(pin)] = 0 THEN
 pinout[Fix(pin)] = 1
   ELSE IF pinout[Fix(pin)] = 1 THEN
 pinout[Fix(pin)] = 0
   ENDIF
 GOTO PrintPinout
 END
 -Gambas2
 END
 
 -BASIC
 CODE FOLLOWS--
 
 BASE0=H378
 
 'SWITCH POWER AND OUTPUTS ON
 OUT BASE0, H80
 OUT BASE0 + 2, 11
 
 'DEFINE ALL DIGITAL OUTPUTS [OUT(N)] AS BEING OFF (0)
 FOR N = 0 TO 7
 DOUT(N) = 0
 NEXT N
 DOUT=0
 
 START:
 INPUT WHICH DIGITAL OUTPUT DO YOU WANT TO TOGGLE (0 TO 7); N
 IF N  0 OR N  7 THEN GOTO START
 N = FIX(N)
 DOUT9N0=ABS(NOT (-DOUT(N))) ' THIS LINE TOGGLES THE OUTPUT
 
 'CREATE COMPLETE BYTE FOR IC3 CALLED DOUT
 FOR N = 0 TO 7
 IF DOUT(N) = 0 THEN
 DOUT = DOUT AND NOT (2^N)
 ELSE
 DOUT = DOUT OR 2^N
 ENDIF
 NEXT N
 
 'SEND 8 CLOCK PULSES AND DIGITAL OUT DATA (ALL ZERO'S)
 FOR BIT = 1 TO 8
 B = 8 - BIT
 BYTE = ((DOUT AND 2^B) / 2^B) OR H80
 OUT BASE0, BYTE
 OUT BASE0, BYTE OR 2
OUT BASE0 BYTE
 NEXT BIT
 
 'SEND ANOTHER 16 CLOCK PULSES TO SHIFT THE DATA INTO IC3
 FOR BIT = 9 TO 24
 OUT BASE0, H82
 OUT BASE0, H80
 NEXT BIT
 
 'LOAD IC3
 OUT BASE0, H90
 OUT BASE0, h80]
 
 -BASIC
 END
 
 Bjorn Macintosh
 --
 Download Intel#174; Parallel Studio Eval
 Try the new software tools for yourself. Speed compiling, find bugs
 proactively, and fine-tune applications for parallel performance.
 See why Intel Parallel Studio got high marks during beta.
 http://p.sf.net/sfu/intel-sw-dev

Re: [Gambas-user] Parallel Port - Kadaitcha Man

2010-04-04 Thread Doriano Blengino
Bjorn Macintosh ha scritto:
 Hiya,
   
 My Gambas version is Gambas2.13
 I am running Linux Mint 8
 I do have a parallel port on my PC. It is '0378' - '037a' and '0778' -
 '077a'
 The error code I am getting is System error. illegal seek
   

 I had already found and gone through the link you sent,  it is what part of
 my code was based on.  If you have read it and can fully understand it can
 you tell me what
 iPortNumber should be in order for me to access the parallel port.  I was
 thinking it would be 888 as a integer (378 in hex is 888 in dec) however I
 don't appear to have got a result from this.

 I tryed 378 aswell without result.  I would try polling each and every port
 however I understand this would potentially break my pc. not my favourite
 option.
   
On a standard PC the parallel ports should be on 0x378 (first), 0x278 
(second), ox3bc (alternate address). Your address 0x778 sounds strange, 
even if possible (everything is possible...). Every PC parallel port 
takes three consecutive I/O address, namely BASE+0, BASE+1 and BASE+2. 
So the standard first port should be at address 0x378 (to write the 
eight data bit pins); 0x379 (to read the printer status) and 0x37A (to 
write some addition I/O).

Anyway, this should be of little importance to you, because the linux 
kernel abstract these addresses, and maps a device which should hide 
those details.

You can take some more info with the command cat /proc/ioports: if you 
don't see the addresses you expect, then you should insert some module 
in the kernel (modprobe parport, modprobe lp, or similar).

Once verified that your machine has a parallel port, and that the kernel 
sees it, you can start to program. I really don't know if the gambas 
sources you have are correct, at first sight they seem ok, but a seek 
operation on a character devices is impossible... is your /dev/parport0 
a character device?
Another thing, may be that to access a device in similar manner you need 
some privileges - try to run the program as root.

Another way would be to use the I/O kernel space directly: in /dev you 
could find a device (/dev/port?) which gives you access to all the IO space.

A third way is to use the IN and OUT instructions, bypassing the kernel 
completely (but you need to ask permission before, and perhaps gambas 
does not have IN and OUT instructions).

Unfortunately, right now, I am on a machine which lacks a parallel port, 
so I can't experiment. But you can google for these three methods to 
access hardware.

Regards,

-- 
Doriano Blengino

Listen twice before you speak.
This is why we have two ears, but only one mouth.


--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Parallel Port - Kadaitcha Man

2010-04-04 Thread Ron_1st
On Sunday 04 April 2010, Bjorn Macintosh wrote:
 Hiya,
 
 I had already found and gone through the link you sent,  it is what part of
 my code was based on.  If you have read it and can fully understand it can
 you tell me what
 iPortNumber should be in order for me to access the parallel port.  I was
 thinking it would be 888 as a integer (378 in hex is 888 in dec) however I
 don't appear to have got a result from this.
 
 I tryed 378 aswell without result.  I would try polling each and every port
 however I understand this would potentially break my pc. not my favourite
 option.
 
 Thanks
 Bjorn Macintosh

Read exactly which port you must open in the gambas documentation for your used 
code. 

using:
2.2 An alternate method:
It is written in the example below. :)



Best regards,

Ron_1st

-- 

111.11 x 111.11 = 12345.678987654321

-- 
 A: Delete the text you reply on.
 Q: What to do to get my post on top?
---
 A: Because it messes up the order in which people normally read text. 
 Q: Why is top-posting such a bad thing? 
---
 A: Top-posting. 
 Q: What is the most annoying thing in e-mail? 
 

--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


[Gambas-user] Parallel Port

2010-04-03 Thread Bjorn Macintosh
Hi all,

Does anyone have a program that interfaces with the parallel port, one
written in Gambas.  If you do would you be willing to share this program
with me as I am trying to write a parallel port interface and am struggling
to get my head around a few concepts.  mainly how to write to the port and
how to select pin's base 0 base1 and base2.

Any help would be greatly appreciated.  I sent a post two days ago holding
the full details on my program and what I am trying to do if you  need any
clarification.

Thanks
Bjorn Macintosh
--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Parallel Port

2010-04-03 Thread Kadaitcha Man
On 4 April 2010 08:14, Bjorn Macintosh bjorn.macint...@gmail.com wrote:
 Hi all,

 Does anyone have a program that interfaces with the parallel port, one
 written in Gambas.  If you do would you be willing to share this program
 with me as I am trying to write a parallel port interface and am struggling
 to get my head around a few concepts.  mainly how to write to the port and
 how to select pin's base 0 base1 and base2.

 Any help would be greatly appreciated.

http://lmgtfy.com/?q=gambas+%22parallel+port%22

--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


[Gambas-user] Parallel Port - Kadaitcha Man

2010-04-03 Thread Bjorn Macintosh
Hiya,

I had already found and gone through the link you sent,  it is what part of
my code was based on.  If you have read it and can fully understand it can
you tell me what
iPortNumber should be in order for me to access the parallel port.  I was
thinking it would be 888 as a integer (378 in hex is 888 in dec) however I
don't appear to have got a result from this.

I tryed 378 aswell without result.  I would try polling each and every port
however I understand this would potentially break my pc. not my favourite
option.

Thanks
Bjorn Macintosh
--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


[Gambas-user] Parallel Port Programming in Gambas

2009-12-16 Thread Me
Hi all,

I am new to Gambas 2.16 and also Ubuntu  9.04.
I trying to write a Gambas program to control
parallel  port's input/output in Ubuntu.

For example, 
Switch parallel port pin 2 to on or off.

From How To Use Parallel Port

http://gambasdoc.org/help/howto/parport

Solution 1:
opening /dev/port with
OPEN and read/write at a specific location.


Solution 2:
Based on a C library named 'parapin'

For solution 2, how Gambas can access the parapin library?

Thank you in advance.



  New Email names for you! 
Get the Email name you#39;ve always wanted on the new @ymail and @rocketmail. 
Hurry before someone else does!
http://mail.promotions.yahoo.com/newdomains/aa/
--
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user