将程序从并行端口转换为USB [英] Converting a program from Parallel port to USB

查看:132
本文介绍了将程序从并行端口转换为USB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



由于更多更新的PC不再具有并行端口和串行端口,因此我需要重写10年的MS Visual-C ++程序才能进行USB访问.

第一个问题:Visual C ++ 6.0不支持大于5的串行端口.
在所有笔记本电脑上,我们不能使用3到10(已经被占用)的串行端口.
如何至少访问端口3,4或5? 第二个问题:在台式机上,我可以使用COM3:或COM4 :,具体取决于PC和操作系统(WIN XP或WIN7),但是使用CreateFile和WriteFile时,程序会冻结. 50秒并行端口操作仍在起作用.

如果需要,我可以发送代码段.

问候René

编辑-从OP更新================
我已经尝试过使用那些8美元的USB到并行端口适配器,但是它们仅适用于真正的打印机.
由于我的控制盒是只写设备,因此它无法模拟打印机并创建相应的反馈信号.
因此,我从H-Tronic购买了70美元的设备USB8-I/O HB628,但是在台式机上使用串行端口3或4(仅适用于串行端口,较高的端口显示已被占用")时,appr后计时器冻结. 50秒在笔记本电脑上,只有COM1和COM2是免费的,不能用于虚拟端口.

现在到计时器冻结.相关的代码段是:

Hi,

Since more newer PC´s have no Parallel Port and Serial Port anymore, i need to rewrite a 10 year old MS Visual-C++ program for USB access.

First problem: Visual C++ 6.0 doesn´t support serial ports greater than 5.
On all laptops we cannot use serial ports 3 to 10 ( already occupied ).
How can I gain access to at least ports 3 , 4 or 5 ?
Second problem: On my desktops I can use either COM3: or COM4: depending on PC and Operating System (WIN XP or WIN7), however using CreateFile and WriteFile the Program freezes after approx. 50 seconds. Parallel port operation is still functioning.

I can send Code snippets, if necessary.

regards, René

EDIT - Update From OP ================
I have tried using those 8 $ USB to parallel port adapters, but they only work with real printers.
Since my control box is a write only device it cannot simulate a printer and create the respective feedback signals.
So i bought a 70 $ device USB8-I/O HB628 from H-Tronic, but when using serialport 3 or 4 (only ones available, higher ones show "already occupied" ) on my desktops my timer freezes after appr. 50 seconds. On Laptops only COM1 and COM2 are free, which cannot be used for virtual ports.

Now to the timer freeze. relevant code pieces are:

rcsp = CreateFile(portname,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,OPEN_EXISTING,NULL,NULL);
. . . . . .
if (interf == 0) 
{ 
    // Parallel Port , this code works since 10 years
    if (abcd) 
    { 
        pdat |= 16; 
    } 
    else 
    {
        pdat &= 0xFFEF; 
    }
    if (redjustset==1) 
    { 
        // this will reset the clock
        pdat |= 64; 
        Out32(0x378,pdat);
        // wait for signal to perform clock function
        Sleep(100); 
        pdat &= 0xFF9F; 
        Out32(0x378, pdat); 
    }
    if (red) 
    {
        pdat |= 8; 
        redjustset = 0; 
    } 
    else 
    {
        pdat &= 0xFFF7;
    }
    ………….
} 
else 
{ 
    // Code for USB Port ,if interf > 0 ( 0 means Parallel Port ) 
    // ( > 0 means Serial Port ). Following code stops timer after 
    // approximately 50 to 60 seconds and program freezes.
    ………….
    if (red) 
    {
        bWriteRC = WriteFile (rcsp,"c141",4,&iBytesWritten, NULL);
        // sets ampel to red on
        redjustset = 0; 
    }
    else 
    {
        bWriteRC = WriteFile (rcsp,"c140",4,&iBytesWritten, NULL);
    } // sets ampel to red off



该程序用于射箭比赛中,并控制交通信号灯和时钟,以告知射手他们何时以及可以射击多长时间.



this program is used in archery contests and controls traffic lights and clocks to inform archers about when and how long they can shoot.

推荐答案

USB到并行端口适配器,但它们仅适用于真正的打印机.
由于我的控制盒是只写设备,因此它无法模拟打印机并创建相应的反馈信号.
因此,我从H-Tronic购买了70个
USB to parallel port adapters, but they only work with real printers.
Since my control box is a write only device it cannot simulate a printer and create the respective feedback signals.
So i bought a 70


设备USB8-I/O HB628,但是在使用串行端口3或4(仅可用的端口,较高的端口显示已经占用")时,台式机我的计时器冻结后冻结. 50秒在笔记本电脑上,只有COM1和COM2是免费的,不能用于虚拟端口.

现在到计时器冻结.相关的代码段是:

device USB8-I/O HB628 from H-Tronic, but when using serialport 3 or 4 (only ones available, higher ones show "already occupied" ) on my desktops my timer freezes after appr. 50 seconds. On Laptops only COM1 and COM2 are free, which cannot be used for virtual ports.

Now to the timer freeze. relevant code pieces are:

rcsp = CreateFile(portname,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,OPEN_EXISTING,NULL,NULL);
. . . . . .
if (interf == 0) 
{ 
    // Parallel Port , this code works since 10 years
    if (abcd) 
    { 
        pdat |= 16; 
    } 
    else 
    {
        pdat &= 0xFFEF; 
    }
    if (redjustset==1) 
    { 
        // this will reset the clock
        pdat |= 64; 
        Out32(0x378,pdat);
        // wait for signal to perform clock function
        Sleep(100); 
        pdat &= 0xFF9F; 
        Out32(0x378, pdat); 
    }
    if (red) 
    {
        pdat |= 8; 
        redjustset = 0; 
    } 
    else 
    {
        pdat &= 0xFFF7;
    }
    ………….
} 
else 
{ 
    // Code for USB Port ,if interf > 0 ( 0 means Parallel Port ) 
    // ( > 0 means Serial Port ). Following code stops timer after 
    // approximately 50 to 60 seconds and program freezes.
    ………….
    if (red) 
    {
        bWriteRC = WriteFile (rcsp,"c141",4,&iBytesWritten, NULL);
        // sets ampel to red on
        redjustset = 0; 
    }
    else 
    {
        bWriteRC = WriteFile (rcsp,"c140",4,&iBytesWritten, NULL);
    } // sets ampel to red off



该程序用于射箭比赛中,并控制交通信号灯和时钟,以告知射手他们何时以及可以射击多长时间.



this program is used in archery contests and controls traffic lights and clocks to inform archers about when and how long they can shoot.


您可以获得USB并行和串行端口适配器(硬件).它们通常小于
You can get USB parallel and serial port adapters (hardware). They''re typically less than


这篇关于将程序从并行端口转换为USB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆