LED through IO ports

Discuss Programming
shuiend
scripter
scripter
Posts: 91
Joined: Mon Apr 28, 2003 8:05 pm

Post by shuiend » Wed Oct 01, 2003 3:29 pm

No i am not using M$. I will be making it on a SlackWare 9 box. She has given me other code for an I/O driver and it has like an open function and a read + write function and such. I will post more later when i get a chance b/c right now i am cooking some dinner.

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Wed Oct 01, 2003 6:09 pm

Yeah, she probably wants you to open /dev/lp0 or something similar. You could always take a look at lpd for some ideas...

shuiend
scripter
scripter
Posts: 91
Joined: Mon Apr 28, 2003 8:05 pm

Post by shuiend » Thu Oct 23, 2003 9:56 am

ok now i have finished my design document i am ready to start coding the project. I would like to know how i search all files on the system for outb() so that i could see that code to make that work. Also i am having trouble finding any tutorials or things on I/O drivers.

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Fri Oct 24, 2003 5:55 pm

There are are several ways to find text in all files. You can use the KDE search ("kfind" if you aren't in KDE otherwise it should be on your KDE menus). Another way is:

http://voidmain.is-a-geek.net/files/scripts/findtext

shuiend
scripter
scripter
Posts: 91
Joined: Mon Apr 28, 2003 8:05 pm

Post by shuiend » Thu Dec 11, 2003 5:48 am

OK i finally got my program semi wokring. My LED Box of lights works and the command line program works fine. But the GUI does not work. outb just dosent seem to work from it. It dosent matter where i put it in my code it just willnot turn off the ligghts. I have the ioperm function before it so i know i have permission to write to the port. The GUI is made in QT so and I didnt thnk that would mess up the use of outb or anything but it seems to. I also had to switch from #inlcude <asm/io.h> to #include <sys/io.h> so that ioperm works. It would not work from the other one. My code is as follows.


//main.cpp
#include <qapplication.h>
#include "guiqt.cpp"
#include <unistd.h>

int main(int argc,char **argv)
{

QApplication a(argc,argv);
MyMainWindow w;
a.setMainWidget(&w);
w.show();
a.exec();
}

//guiqt.cpp
#include <qapplication.h>
#include <qwidget.h>
#include <qbuttongroup.h>
#include <qcheckbox.h>
#include <qpushbutton.h>
#include <sys/io.h>
#include "apstring.h"
#include "apvector.h"
#include "guiqt.moc"
#include <qstring.h>
//#include <unistd.h>
//#include <stdio.h>
//#include <stdlib.h>

#define base 0x387





MyMainWindow::MyMainWindow()
{
setGeometry( 100,100, 250,250);

group = new QButtonGroup( "Lights" , this);
group->setGeometry(10,10,150,150);

cb1= new QCheckBox( "1", group);
cb1->move(20,20);
cb2= new QCheckBox( "2", group);
cb2->move(20,50);
cb3= new QCheckBox( "3", group);
cb3->move(20,80);
cb4= new QCheckBox( "4", group);
cb4->move(20,110);
cb5= new QCheckBox( "5", group);
cb5->move(60,20);
cb6= new QCheckBox( "6", group);
cb6->move(60,50);
cb7= new QCheckBox( "7", group);
cb7->move(60,80);
cb8= new QCheckBox( "8", group);
cb8->move(60,110);

group->insert(cb1);
group->insert(cb2);
group->insert(cb3);
group->insert(cb4);
group->insert(cb5);
group->insert(cb6);
group->insert(cb7);
group->insert(cb8);

lon = new QPushButton( "Lights On", this);
lon->setGeometry(20, 180,70,20);

loff = new QPushButton( "Lights Off", this);
loff->setGeometry(100,180,70,20);

quitb = new QPushButton( "Quit", this);
quitb->setGeometry(180,180,70,20);

connect(quitb, SIGNAL( clicked()), qApp, SLOT( quit() ));
connect(lon, SIGNAL( clicked() ), this, SLOT( lighton() ));
connect(loff, SIGNAL( clicked() ), this, SLOT( lightoff() ));
}

void MyMainWindow::lighton()
{
int open=ioperm(base,1,1);
outb((unsigned char)255, base);
apvector<int> bit(8,0);
QString bits;
bool ok;

if (cb1->isChecked())
bit[0]=1;
if (cb2->isChecked())
bit[1]=1;
if (cb3->isChecked())
bit[2]=1;
if (cb4->isChecked())
bit[3]=1;
if (cb5->isChecked())
bit[4]=1;
if (cb6->isChecked())
bit[5]=1;
if (cb7->isChecked())
bit[6]=1;
if (cb8->isChecked())
bit[7]=1;
int i,k=7, dec;
for(i=0;i<bit.length();i++)
{
bits += bit[k];
k--;
}
dec=bits.toInt( &ok, 10 );
int ok=ioperm(base,1,1);
outb(dec,base);
}


void MyMainWindow::lightoff()
{
int value=0;
int open=ioperm(base,1,1);
outb((unsigned char)value, base);

}

//guiqt.h
#include <qvariant.h>
#include <qdialog.h>


class MyMainWindow : public QWidget
{

Q_OBJECT
public:
MyMainWindow();
public slots:
void lighton();
void lightoff();
private:
QButtonGroup *group;
QCheckBox *cb1;
QCheckBox *cb2;
QCheckBox *cb3;
QCheckBox *cb4;
QCheckBox *cb5;
QCheckBox *cb6;
QCheckBox *cb7;
QCheckBox *cb8;
QPushButton *quitb;
QPushButton *lon;
QPushButton *loff;
};

To make this program i am using the make file form the QT tutuorial files. In slack it is located in
/usr/lib/qt-3.2.1/tutorial/t2 I copied all my files into their and then just did make. It compiles fine and runs but when i click the light on button or the light off button nothing happens. I have movied the ioperm and outb lines to the start of the main.cpp and then compiled and ran it and nothing would happen. I get no errors when i run the program or press the button form the command line so i dont know where it is messing up. Also for apvector just search google for the .h and .cpp files. Any help on this would be nice.

TheQuirk
programmer
programmer
Posts: 114
Joined: Wed Jan 22, 2003 4:11 pm

Post by TheQuirk » Fri Jan 30, 2004 6:35 pm

This is a pretty old thread, but still an interesting topic. The said thread on the MES is located here.

shuiend
scripter
scripter
Posts: 91
Joined: Mon Apr 28, 2003 8:05 pm

Post by shuiend » Mon May 03, 2004 7:04 am

Well I have finally come back to this program and I am trying to get my actual driver to work so that i can call it from any type of program. I am gettin an error though and I am not sure how to fix it. The code for my driver is the following.


#include <linux/config.h>
#include <asm/io.h>
#include <linux/module.h>
#include <linux/version.h>
#include <linux/types.h>
#include <linux/fs.h>
//#include <linux/mm.h>
#include <linux/errno.h>
#include <asm/segment.h>
static int base = 0x378;



static int write_Lights(node, file, buf, count)
struct inode *node;
struct file *file;
char *buf;
int count;
{
char i = get_user_byte(buf);
outb(i,base);
return 1;
}
static int read_Lights(file, buf, count, offset)
struct file *file;
char *buf;
int count;
char *offset;
{
return 1;
}

static int open_Lights(node, file)
struct inode *node;
struct file *file;
{
return 1;
}


static struct file_operations Lights_ops={
NULL,
NULL,
read_Lights,
write_Lights,
NULL,
NULL,
NULL,
NULL,
open_Lights,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
};



i use the following makefile to compile it.


#/bin/bash
CFLAGS = -O -DMODULE -D__KERNEL__
CC=gcc

ALL: driver.o

driver.o: driver.c
$(CC) $(CFLAGS) -c driver.c


I get the following output from the compile.

root@localhost IOINFO]# make
gcc -O -DMODULE -D__KERNEL__ -c driver.c
In file included from driver.c:2:
/usr/include/asm/io.h:4:2: warning: #warning <asm/io.h> is deprecated, use <sys/io.h> instead
driver.c:41: error: variable `Lights_ops' has initializer but incomplete type
driver.c:42: warning: excess elements in struct initializer
driver.c:42: warning: (near initialization for `Lights_ops')
driver.c:43: warning: excess elements in struct initializer
driver.c:43: warning: (near initialization for `Lights_ops')
driver.c:44: warning: excess elements in struct initializer
driver.c:44: warning: (near initialization for `Lights_ops')
driver.c:45: warning: excess elements in struct initializer
driver.c:45: warning: (near initialization for `Lights_ops')
driver.c:46: warning: excess elements in struct initializer
driver.c:46: warning: (near initialization for `Lights_ops')
driver.c:47: warning: excess elements in struct initializer
driver.c:47: warning: (near initialization for `Lights_ops')
driver.c:48: warning: excess elements in struct initializer
driver.c:48: warning: (near initialization for `Lights_ops')
driver.c:49: warning: excess elements in struct initializer
driver.c:49: warning: (near initialization for `Lights_ops')
driver.c:50: warning: excess elements in struct initializer
driver.c:50: warning: (near initialization for `Lights_ops')
driver.c:51: warning: excess elements in struct initializer
driver.c:51: warning: (near initialization for `Lights_ops')
driver.c:52: warning: excess elements in struct initializer
driver.c:52: warning: (near initialization for `Lights_ops')
driver.c:53: warning: excess elements in struct initializer
driver.c:53: warning: (near initialization for `Lights_ops')
driver.c:54: warning: excess elements in struct initializer
driver.c:54: warning: (near initialization for `Lights_ops')
driver.c:55: warning: excess elements in struct initializer
driver.c:55: warning: (near initialization for `Lights_ops')
driver.c:56: warning: excess elements in struct initializer
driver.c:56: warning: (near initialization for `Lights_ops')
driver.c:57: warning: excess elements in struct initializer
driver.c:57: warning: (near initialization for `Lights_ops')
driver.c:58: warning: excess elements in struct initializer
driver.c:58: warning: (near initialization for `Lights_ops')
driver.c:59: warning: excess elements in struct initializer
driver.c:59: warning: (near initialization for `Lights_ops')
driver.c:41: error: storage size of `Lights_ops' isn't known
make: *** [driver.o] Error 1


I need to know what it means to not have the storage size of the struct file_operations. I have googled and so far have not found anything usefull about it. Also I am trying to get this working on a stock Fedora Core 1 Machine with Linux version 2.4.22-1.2115.nptl (bhcompile@daffy.perf.redhat.com) (gcc version 3.2.3 20030422 (Red Hat Linux 3.2.3-6))

Post Reply