打印

windows xp下我用pietty访问linux下的并口,一些问题请教

[复制链接]
1600|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
xiaoyu9632|  楼主 | 2007-6-25 13:55 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include <stdio.h>
#include <stdlib.h>
#include <sys/io.h>
#include <signal.h>
#include <unistd.h>

#define Pbase 0x378
#define CTLVFD 0X37a

void ctlled(unsigned char ctlbyte);

int main()
{
    ioperm(Pbase,2,1);
    ioperm(CTLVFD,1,1);
    ctlled(0x8C);
}

void ctlled(unsigned char ctlbyte)
{
    outb(ctlbyte,pbase);
    return;
}

我测试过,刚启动的系统并口状态(数据位)是低电平,当我运行我的程序的时候,输出电压变为3v多,这是为什么呢?按照道理应该是波形输出才对,现在的现象是outb(ctlbyte,pbase);这句话我就是写成outb(0xf0,pbase);也不会在有低电平输出了。郁闷中,各位朋友帮忙。

相关帖子

沙发
high| | 2007-6-25 15:28 | 只看该作者

h

#ifndef __PPT_H__
#define __PPT_H__

//#include <asm/io.h>
#include <sys/io.h> /* 2007-04-19 chen yongqiang */

#define _inp(a) inb(a)
#define _outp(a,d) outb(d,a)

int GetValidPpt(void);
int InstallGiveIo(void);
void SetPptCompMode(void);

extern int validPpt;

#define LPT1 0x378    // the search order is LPT1 then 2 then 3
#define LPT2 0x278    // first valid address found is used (re-order if needed for multiple ports)
#define LPT3 0x3bc    // hardware base address for parallel port

#define OutputPpt(value)    _outp((unsigned short)validPpt,value)
#define InputPpt()        _inp((unsigned short)(validPpt+0x1))

#endif //__PPT_H__

使用特权

评论回复
板凳
high| | 2007-6-25 15:29 | 只看该作者

c

#include <stdio.h>
#include "ppt.h"

int validPpt; 
#ifdef __linux__
int io_access_on( unsigned long port )
{
    if (ioperm (port, 3, 1)) {
        perror ("ioperm()");
        return 0;
    }
    if (ioperm (0x80, 1, 1)) {
        perror ("ioperm()");
        return 0;
    }
    return 1;
}

void io_access_off( unsigned long port )
{
    ioperm (port, 3, 0);
    ioperm (0x80, 1, 0);
}
#else
#define io_access_on(x) (1)
#define io_access_off(x)
#endif
int GetValidPpt(void)
{
    // search for valid parallel port
    if( io_access_on(LPT1) ){
        _outp(LPT1, 0x55);
        if((int)_inp(LPT1) == 0x55) return LPT1;
        io_access_off(LPT1);
    }

    if( io_access_on(LPT2) ){    
        _outp(LPT2, 0x55);
        if((int)_inp(LPT2) == 0x55) return LPT2;
        io_access_off(LPT2);
    }

    if( io_access_on(LPT3) ){
        _outp(LPT3, 0x55);
        if((int)_inp(LPT3) == 0x55) return LPT3;
        io_access_off(LPT3);
    }
    
    return 0;    
}

#define ECP_ECR            (0x402)
#define ECR_STANDARD        (0x0)
#define ECR_DISnERRORINT    (0x10)
#define ECR_DISDMA        (0x0)
#define ECR_DISSVCINT        (0x4)

void SetPptCompMode(void)
{
    //configure the parallel port at the compatibility mode.
    //_outp(validPpt+ECP_ECR,ECR_STANDARD | ECR_DISnERRORINT | ECR_DISDMA | ECR_DISSVCINT);
}
#ifndef __linux__
int InstallGiveIo(void)
{
    HANDLE h;
    OSVERSIONINFO osvi;
    
    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    GetVersionEx(&osvi);
    
    if(osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
    {
    //OS=NT/2000
    h = CreateFile("\.giveio", GENERIC_READ, 0, NULL,
            OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    CloseHandle(h);
    if(h == INVALID_HANDLE_VALUE)
            return 0;
    else
        return 0x2000;
    }
    else
    {    //OS=WIN98
    return 0x0098;
    }
}
#endif

使用特权

评论回复
地板
xiaoyu9632|  楼主 | 2007-6-25 16:21 | 只看该作者

楼上的朋友

能不能详细解释下我的那种做法错误在哪里,你的程序好像是针对windows所写呀,可是我是linux下的。

使用特权

评论回复
5
high| | 2007-6-25 16:39 | 只看该作者

我给你的是linux下的而且是可以用。拜托您仔细点。

已经给您demo了还...

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

23

主题

159

帖子

0

粉丝