Using parallel port as synchronous IO device

Hi everybody

I'm trying to write an app that will send data to the parallel port, but I want to send the data on regular intervals. Because I'm working with Win XP ,the data is sent to the port with a dll ( that starts a device driver) found at http://www.logix4u.net. My problem now is that the Timer provided by windows is too slow and inaccurate to allow for synchronous communication. Is there another way to implement a timer? Or another way to solve this problem?

Comments

  • : Hi everybody
    :
    : I'm trying to write an app that will send data to the parallel port, but I want to send the data on regular intervals. Because I'm working with Win XP ,the data is sent to the port with a dll ( that starts a device driver) found at http://www.logix4u.net. My problem now is that the Timer provided by windows is too slow and inaccurate to allow for synchronous communication. Is there another way to implement a timer? Or another way to solve this problem?
    :

    Are you using the performance timer? Or just standard timer?
  • [green]Take a look at "Multimedia Timers" in MSDN:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_about_multimedia_timers.asp
    [/green]
    [hr];-) [b][size=4][red]~Bikram[/red][/size][/b]

  • Thanks Biki. Although those timers provide greater accuracy they are still relatively slow. The minimum value that I can set the timer to, is 1ms so I can effectively send 1000 B/s. Correct? I'll consider this option.I've also considered building a piece of hardware that accepts the data asynchronously and then sending the data synchronously from there. But the more I think about it the more it seems like a bad idea. I think I'll sleep on it. Thanks for the idea.
  • If your code is in a loop, you can use the performance timers as mentioned above. groups.google.com for "QueryPerformanceFrequency" and "QueryPerformanceCounter".

    This is processor dependant, but on my P4 1.8GHz I managed to get accuracy as low as 6 microseconds.
  • : If your code is in a loop, you can use the performance timers as mentioned above. groups.google.com for "QueryPerformanceFrequency" and "QueryPerformanceCounter".
    :
    : This is processor dependant, but on my P4 1.8GHz I managed to get accuracy as low as 6 microseconds.
    :

    Thanks for the suggestion PingPong. I tried this method, here is the code :
    [code]
    __int64 freq;
    if(QueryPerformanceFrequency((LARGE_INTEGER *)&freq))
    {
    __int64 con= 9600;
    __int64 fDif= freq/con;
    __int64 start=0,stop=0,diff=0,count=0;
    while(Form1->Timer1->Enabled==true)
    {
    //get the start freq
    QueryPerformanceCounter((LARGE_INTEGER *)&start);
    QueryPerformanceCounter((LARGE_INTEGER *)&stop);
    diff=stop-start;
    while(diff<=fDif)
    {
    QueryPerformanceCounter((LARGE_INTEGER *)&stop);
    diff=stop-start;
    }
    count++;
    }
    ShowMessage("The value of count is "+(AnsiString)count);
    }
    [/code]

    By using the "count" shown I can test the performance of the timer, I let the function run for 20 seconds to see how many counts I receive. I should receive 192000 counts (9600 baud * 20 sec), but I only get 179690. This performance is not nearly good enough for synchronous comms. I am now communication via the serial port as discussed before, so I have basically solved my problem. But I am still interested in how this could work. Have I done something wrong in the code?
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories