Using C to access computer I/O

Discussion in 'Programmer's Corner' started by Shagas, Jul 21, 2014.

  1. Shagas

    Thread Starter Active Member

    May 13, 2013
    802
    74
    Hello

    I was wondering , how would one use a language like "C" to make programs
    that use OS resources or PC hardware etc?

    Example: How would I write a program that could read my soundcard input
    , do some processing and then route the signal to the output ? Or something similar.

    Thanks in advance.

    PS. I tried searching for this on google but honestly ... I don't really know what to write in the search bar.
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,440
    3,360
    The easiest way to read digital data from the sound card, perform digital data processing and play back the results on the sound card is to use MATLAB.
     
  3. Shagas

    Thread Starter Active Member

    May 13, 2013
    802
    74
    Thanks for the information MrChips but I'm afraid you did not understand what I was asking.

    My question wasn't how to do that specific task , my question is how to do that task using programming in 'C'.

    I know how to write programs in an IDE and compile & run them , but how can I use those programs to access computer I/O and other things?
    Is there some specific library/framework for each OS ?
     
  4. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,388
    497
  5. NorthGuy

    Active Member

    Jun 28, 2014
    603
    121
    You cannot access much of a computer IO without drivers. You need to write your own drivers or use hardware which already has drivers, such as COM ports or USB HID.

    What kind of computer you have in mind? What kind of hardware you want to access?
     
  6. Shagas

    Thread Starter Active Member

    May 13, 2013
    802
    74
    Thanks shteii01 but i'm using WIN7

    NorthGuy:

    Ok so how do I go about writing drivers in C for example for WIN7?
    What are the things I have to know besides the C language?
    For example I would Like to write a program in C that drives a camera connected to a USB port , reads the camera input and displays it in my program.
    Or let's say that the camera has already installed drivers and works with skype or whatever , but I want to use that driver in my C program to input the video data and process it or something and then display it in a window.

    I know this is probably advanced stuff , but I'd appreciate an overview of how this is done at least.
     
  7. MrChips

    Moderator

    Oct 2, 2009
    12,440
    3,360
    I believe you don't understand or appreciate how software runs on a PC.
    Sure, one can create their own program written in C to interface with the PC hardware. But how does one integrate it with the OS and all the necessary overhead to be able to write to the screen, as an example.
    Personally, I wouldn't know how to do it. That is why I would rely on a package that does it for me already. With MATLAB, I can get sound from the sound card and play it back. Total effort and programming time: 5 minutes.
     
    Chalma likes this.
  8. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,388
    497
    A. It might work in 7.
    B. I found it for Xp, surely you can at least try to find something similar for 7.
     
  9. Shagas

    Thread Starter Active Member

    May 13, 2013
    802
    74

    You are right .I have a vague Idea but that's about it , so that's why i'm asking.
    I've used MATLAB to do exactly that , but I'm interested in exploring the programming side of things. Specifically in expanding the my scope of reach
    with programming which at the moment is limited to the IDE.
     
  10. Shagas

    Thread Starter Active Member

    May 13, 2013
    802
    74
    Yes , I already did now that I at least know what to search for . Thanks.
     
  11. MrChips

    Moderator

    Oct 2, 2009
    12,440
    3,360
    The bottom line is you end up having to use an IDE, whether or not it is Visual Studio, Labview, MATLAB, etc. unless you are a masochist.

    Yes, I have programmed and compiled code by hand and entered 0s and 1s into the front panel via toggle switches. Eventually you will resort to a text editor and a compiler.

    Suppose you have an MCU from Microchip, Atmel or any other manufacturer and you want to demonstrate the programming procedure by making an LED flash, a classic first test program. You will need a text editor, a compiler and a programmer. It is not likely you will create these tools from scratch so you will rely on a ready made IDE.

    Now suppose you want to make an LED flash from a PC. Not so easy, is it? If you had a parallel printer port it wouldn't be so difficult. Even with a serial COM port it would be possible. Now all you have is a USB port and that's not easy to work with.

    Suppose you want to blank the whole display and turn on one pixel. How would you do that from a C program? Not easy, is it?

    The bottom line is you have to use an IDE and a programming language that provides you with access to the PC internal OS hooks and drivers.
     
  12. Shagas

    Thread Starter Active Member

    May 13, 2013
    802
    74
    I never said that I don't want to use an IDE. What I meant was that I can't use any resources outside the variables etc that i've created inside the IDE . What I am looking for is the
    "and a programming language that provides you with access to the PC internal OS hooks and drivers." bit.


    I'd love to do that :D
     
  13. MrChips

    Moderator

    Oct 2, 2009
    12,440
    3,360
    I could show you a blank screen with one pixel lit but it would be difficult to see.

    This is the best I can do for now:

    [​IMG]
     
  14. NorthGuy

    Active Member

    Jun 28, 2014
    603
    121
    A camera will already have all the drivers. Microsoft provides various APIs for doing different tasks. There must be an API for camera too. They will have sets of DLL functions, or more likely a hierarchy of COM objects, which you can access from your C program.

    I've never worked with camera so I don't know the corresponding API, but usually Microsoft has pretty good documentation of their APIs which is easy to follow.
     
  15. Shagas

    Thread Starter Active Member

    May 13, 2013
    802
    74
    Ok thanks I'll look into that.

    You trying to make me jealous Mr Chips?

    Here is a pic of a prototype scope I made using an AVR and interfacing it to java through UART at 500kBaud .It won me the "Best semestral work" in programming 2 class.

    scopePic.png

    I was thinking of putting it up on the completed projects forum but it doesn't have proper input analog circuitry and a trigger system yet.
     
Loading...