Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Outputting through parallel port or USB (http://www.go4expert.com/forums/outputting-parallel-port-usb-t17074/)

Player 23Apr2009 19:12

Outputting through parallel port or USB
 
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);
}


aVague 23Apr2009 19:26

Re: Outputting through parallel port or USB
 
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

Player 23Apr2009 20:25

Re: Outputting through parallel port or USB
 
Quote:

Originally Posted by aVague (Post 46237)
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

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 :)

aVague 23Apr2009 21:16

Re: Outputting through parallel port or USB
 
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/Sea...ge%20signal&ac

Player 23Apr2009 23:43

Re: Outputting through parallel port or USB
 
Quote:

Originally Posted by aVague (Post 46246)
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/Sea...ge%20signal&ac

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? :)

aVague 24Apr2009 13:32

Re: Outputting through parallel port or USB
 
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

Player 24Apr2009 14:26

Re: Outputting through parallel port or USB
 
Quote:

Originally Posted by aVague (Post 46284)
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

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.

aVague 26Apr2009 22:23

Re: Outputting through parallel port or USB
 
yes, please)
it will be interesting

Player 26Apr2009 22:44

Re: Outputting through parallel port or USB
 
Quote:

Originally Posted by aVague (Post 46486)
yes, please)
it will be interesting

He's changed his mind now and say's parallel would be better. I'll put the code up once he's altered it :)


All times are GMT +5.5. The time now is 19:37.