Outputting through parallel port or USB

Discussion in 'C' started by Player, Apr 23, 2009.

  1. Player

    Player New Member

    Joined:
    Aug 3, 2007
    Messages:
    37
    Likes Received:
    0
    Trophy Points:
    0
    Hi Guys.

    Not sure if this forum deals with the electronic side of programming? I basically want to make a money counting machine thats connected to a PC. I will be using a universal hopper to count any size coin.

    My problem is, i don't know how to output to the printer port or USB. I have wrote the following simple code to try and show what i mean.

    Any help is much appreciated as always. If i'm asking the wrong kind of question please let me know :)
    Code:
    #include<stdio.h>
    
    int main()
    {
        int coins;
        char answer='y';
        
        while(answer=='y')
            {
            printf("Please input how many coins you want counting out.\n");
            scanf("%d",&coins);
            fflush(stdin);
        
            while(coins>0)
                {
                printf("Output %d coins.\n",coins);/*This is where i need to output to the printer port*/
                coins--;
                }
                printf("Do you want to count more coins?\n");
                answer=getchar();
                if(answer=='n')
                
                break;
            }
        return(0);
    }
     
    Last edited by a moderator: Apr 23, 2009
  2. aVague

    aVague New Member

    Joined:
    May 2, 2007
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    forex
    ah,so you want to count 5,10,or whatever the value coins
    i don't get you want to count real coins by scanning with some machine ? i guess so ..
    if you want to print anything you need save that text you want to print in txt file by commands fopen (opens a txt file, wich is in your case empty),fwrite (writes in that file text), then fclose (closes file,saves what you've written there),
    so the remaining thing to do is to print that txt file. i don't remember wich commands are used for that
     
  3. Player

    Player New Member

    Joined:
    Aug 3, 2007
    Messages:
    37
    Likes Received:
    0
    Trophy Points:
    0
    The hopper will count the coins. It looks for a 0v or +5v pulse to count out the coins. I want my programs output to pulse either 0v or +5v via the parallel port. Whatever signal comes from the parallel port i can alter to suit my hopper input. I just need to see how the code would work in the "output" bit i have marked in my code.

    I didn't want to print anything, i just used printf as an example for the output in the compiled program :)
     
  4. aVague

    aVague New Member

    Joined:
    May 2, 2007
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    forex
    so: you 're inputing quantity of coins in computer , then what?
    I don't get , what is the purpuse of counting. Suggestion you have REAL coins 10, 20 for example
    for 10 is 0v, for 20 is +5v , you put coins in the hopper , hopper gives signas 0v, +5v to computer, and computer counts how many signals there are , so you're having resut how many 10 coins and how many 20 coins

    if so then what you need to output from PC? indeed you need to read signals from hopper

    in the case you want to create signals from PC to hopper (i don't understand why), then i guess you need to know other language than C , cuz C is "high-objective" language , and you need "low-objective" language. ( Assembler for example. or Pascal i don't know for sure)
    maybe in C there is such possibility, try to find this command in MSDN http://social.msdn.microsoft.com/Search/ru-RU/?query=voltage signal&ac
     
  5. Player

    Player New Member

    Joined:
    Aug 3, 2007
    Messages:
    37
    Likes Received:
    0
    Trophy Points:
    0
    I don't think you quite get it.

    Hopper connects to PC.

    A number of coins are loaded into the hopper, 10p's for example.

    Program is running on pc.

    You input how many coins you want counting out and the output in the program sends the signal that ammount of times to the hopper.

    The hopper doesn't send anything back. It just counts out how many times the signal is pulsed and churns out that many coins.

    Am i making more sense now? :)
     
  6. aVague

    aVague New Member

    Joined:
    May 2, 2007
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    forex
    yes, now i get it)
    i guess http://www.usbee.com/dxtb.html this will be it

    Digital Signal Generator

    The USBee DX has the ability to generate (output) samples from 8 or 16 digital signals at up to 24Msps or 12Msps in Signal Generator mode.

    In this mode, there is a single buffer that stores the samples to generate. Each sample is a long value made up of 4 bytes. The low order 2 bytes represent the 16 digital channels. Digital Signal 0 is bit 0 of each long value. The high two bytes are not used. These samples can then be generated on command.

    The maximum sample rate that is possible Signal Generator mode is 24Msps. This value can depend on your PC system and available processing speed and how many byte lanes are generating data. The basic rule of thumb is that the maximum bandwidth through USB 2.0 is near 24Mbytes/second. Therefore to generate 2 bytelanes (16 digital channels for example) would equate to a maximum sample rate of 12Msps.

    The method for generating a single output pattern using the Signal Generator routines is as follows:

    · Allocate the sample buffer (MakeBuffer())

    · Fill the sample buffer with the pattern data you want to generate.

    · Start the generation running (StartGenerate (…))

    · Monitor the generation in progress to determine if it is triggered, filling, or completed. (GenerateStatus()).

    · Terminate the generation. (StopGenerate())

    The USBee DX can not generate analog output voltages using this mode. Variable analog outputs are possible using the PWM Controller and an external RC circuit.

    i don't know is these C-commands or not thought
     
  7. Player

    Player New Member

    Joined:
    Aug 3, 2007
    Messages:
    37
    Likes Received:
    0
    Trophy Points:
    0
    This looks very interesting. The inputs and outputs look good. I want to make a pc driven fruit machine eventually but want to code it in C as it's the only language I half understand at the minute.

    Getting back to the original question :). I have been told that going through the serial port would be easier. I know someone who's going to alter my code. I'll report back when he has done it.
     
  8. aVague

    aVague New Member

    Joined:
    May 2, 2007
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    forex
    yes, please)
    it will be interesting
     
  9. Player

    Player New Member

    Joined:
    Aug 3, 2007
    Messages:
    37
    Likes Received:
    0
    Trophy Points:
    0
    He's changed his mind now and say's parallel would be better. I'll put the code up once he's altered it :)
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice