How to open a file with string through USB?

This is a discussion on How to open a file with string through USB? within the C Programming forums, part of the General Programming Boards category; I am trying to open a file ( like a picture) by sending a null terminated string from a micro-controller ...

  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    11

    How to open a file with string through USB?

    I am trying to open a file ( like a picture) by sending a null terminated string from a micro-controller through a USB to my computer. The only command that I have available to send to the PC is: "_SendString232" or

    uchar _SendString232 (long ptr)

    Is there a program that can get the info from the USB and then open the desired file? Can I write a program ( e.x. in Microsoft Visual Studio or other environment) that gets info from the USB then have that program open a file? Is it possible to send a ShellExecute() command through the USB making windows open a file?

    I EMPHATICALLY THANK YOU FOR YOUR HELP!!!

    My computer specs:
    64-bit Dell with Windows 7 OS.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    All you can do with a USB is communicate. If you have a program listening on the PC side, then it can do things based on the input it receives.

  3. #3
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,047
    Quote Originally Posted by K.Flynn View Post
    I am trying to open a file ( like a picture) by sending a null terminated string from a micro-controller through a USB to my computer.
    What kind of microcontroller do you have and is it connected to the PC using USB ports at both ends?
    Quote Originally Posted by K.Flynn View Post
    The only command that I have available to send to the PC is: "_SendString232" or

    uchar _SendString232 (long ptr)

    Is there a program that can get the info from the USB and then open the desired file? Can I write a program ( e.x. in Microsoft Visual Studio or other environment) that gets info from the USB then have that program open a file? Is it possible to send a ShellExecute() command through the USB making windows open a file?
    You need to get a compiler for the microcontroller that has a builtin USB lib (most have 'em).
    It'd help if you provided some more details about how the whole thing is connected.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,656
    It seems unlikely that an API would be called SendString232 to send data along the USB.

    It seems more likely to be an old-style serial line - which is easier to code for at both ends.

    Check the connector shapes, are they 'D' type
    RS232 Tutorial on Data Interface and cables

    Or are they really USB
    Universal Serial Bus - Wikipedia, the free encyclopedia
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Some micro-controllers have a chip that allows communication with USB (ie the FT232 that the arduino ships with) so it might make sense for them to also offer a basic function to send a string to the USB host. Even if that is what your board has, you will likely need a driver on your computer to read what is sent - especially if you are using Windows.

    Best bet, look at the docs for your board. You'll probably get the answer there

  6. #6
    Registered User
    Join Date
    Aug 2003
    Posts
    1,208
    Some microcontrollers even have USB host/slave builtin (for example PIC32), however I very very very much doubt that a single function would be provided to make up all the communication betwean a USB host and a USB slave, even for a "trivial" task of sending bytes along an emulated rs232 connection. The USB protocol is built in a way that you can't just push bytes, you need to provide stuff like Vendor, device class, subclass, endpoint descriptors and so on and so forth (read the official USB documentation for more info). USB is several times more complex than serial port communication and I think that is what that function provides you with.

  7. #7
    Registered User
    Join Date
    Jun 2011
    Posts
    11
    Quote Originally Posted by itCbitC View Post
    What kind of microcontroller do you have and is it connected to the PC using USB ports at both ends?

    You need to get a compiler for the microcontroller that has a builtin USB lib (most have 'em).
    It'd help if you provided some more details about how the whole thing is connected.
    Microcontroller:
    Company: VeeaR
    Model: VoiceGP DK-T2SI

    USB at both ends. yes
    USB lib? USB library? I've checked the dev. guide for the IDE that comes with the microcontroller and that is the only command that I could find. Others just set the baud rate and other stuff like idle, init and wait.

    There is a "terminal" in the IDE which connects to the microcontroller and receives the "_SendString232 " correctly and prints the string. I don't know if I might be able to use this to my advantage because it is running within the IDE.

    Thank you for your help.
    Last edited by K.Flynn; 06-29-2011 at 06:59 AM.

  8. #8
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Check the com: ports in your PC... if the microcontroller is emulating RS232 over USB you may find that when it's connected you have an extra com: port on your PC. If that's the case you can communicate with the uC through that port, by opening it as a file in C.

    Note: you may have to install a driver for the uC on your PC and the manufacturer should provide that.

  9. #9
    Registered User
    Join Date
    Jun 2011
    Posts
    11
    Quote Originally Posted by Salem View Post
    It seems unlikely that an API would be called SendString232 to send data along the USB.

    It seems more likely to be an old-style serial line - which is easier to code for at both ends.

    Check the connector shapes, are they 'D' type
    RS232 Tutorial on Data Interface and cables

    Or are they really USB
    Universal Serial Bus - Wikipedia, the free encyclopedia
    I thought USB was serial? Or is a different kind?

    The USB is D(connected to micro-controller) to A type which is connected to the computer.

    Thank you for your help.

  10. #10
    Registered User
    Join Date
    Jun 2011
    Posts
    11
    Quote Originally Posted by Fordy View Post
    Some micro-controllers have a chip that allows communication with USB (ie the FT232 that the arduino ships with) so it might make sense for them to also offer a basic function to send a string to the USB host. Even if that is what your board has, you will likely need a driver on your computer to read what is sent - especially if you are using Windows.

    Best bet, look at the docs for your board. You'll probably get the answer there
    I will continue to look at the docs. Thank you for your help.

  11. #11
    Registered User
    Join Date
    Jun 2011
    Posts
    11
    Quote Originally Posted by CommonTater View Post
    Check the com: ports in your PC... if the microcontroller is emulating RS232 over USB you may find that when it's connected you have an extra com: port on your PC. If that's the case you can communicate with the uC through that port, by opening it as a file in C.

    Note: you may have to install a driver for the uC on your PC and the manufacturer should provide that.
    do you mean that when its connected a virtual COM port is created? I don't think that is the case.
    PLEASE tell me what you mean by "If that's the case you can communicate with the uC through that port, by opening it as a file in C." What does uC stand for? How do I do this?!?! THANK YOU FOR YOUR HELP!

  12. #12
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by K.Flynn View Post
    do you mean that when its connected a virtual COM port is created? I don't think that is the case.
    PLEASE tell me what you mean by "If that's the case you can communicate with the uC through that port, by opening it as a file in C." What does uC stand for? How do I do this?!?! THANK YOU FOR YOUR HELP!
    u = micro
    C = controller
    uC is a short form for "microcontroller"...

    It looks from the command sets you've described that the uC is emulating RS232 over USB... this should result in a virtual com port being created on your PC for the uC... As I said there might be a driver you need to install on the PC to get this working... but from what you've said --especially the _SendString232() function-- I would not be at all surprised if that's the case.

    What you need to do first before you go begging people for "scoop and poop" code is...

    A) read the manufacturer's documentation for the chip you are using; it should explain how to communicate with the device and if PC side drivers are needed it should tell you where to get them. (Read all of it... you might be surprised at what you will learn.)

    B) Learn about C and C's file handling. In C all devices are "streams" and can be opened with fopen(), access with fread() and fwrite() then closed with fclose()... just like disk files. There are gobs of tutorials out there for this kind of thing; do a little reading, you'll be glad you did.

    You are playing in a highly technical area, don't even think about dumbassing your way through it... do the research, learn the language... it's the only path to success.

    To check for virtual comports.... (Assuming windows, here)
    Go into your control panel...
    Click through Administrative Tools -> Computer Management -> Device Manager
    There you will find a tree item for your serial ports... expand that.

    When the device is plugged in you will see an extra comport (Probably COM3: ) pop up.
    If that's the case, all you need to do is use C's file handling commands to access it.
    Last edited by CommonTater; 06-29-2011 at 07:36 AM. Reason: typos

  13. #13
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by K.Flynn View Post
    I thought USB was serial? Or is a different kind?

    The USB is D(connected to micro-controller) to A type which is connected to the computer.

    Thank you for your help.
    USB can be anything...
    For example:
    When you insert a pen drive into a USB port, it appears as a disk drive.
    When you connect a DAC, it appears as a new sound card in device manager.

    It's all virtual devices and it's all about the drivers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 03-08-2010, 01:43 PM
  2. Open File/Save File crashes on cancel?
    By Blackroot in forum Windows Programming
    Replies: 0
    Last Post: 08-02-2008, 02:16 AM
  3. trouble using string to open file
    By dougwilliams in forum C Programming
    Replies: 3
    Last Post: 11-25-2007, 05:05 PM
  4. Using a string to open a file..
    By neoragexxx in forum C++ Programming
    Replies: 7
    Last Post: 04-27-2006, 09:41 AM
  5. Replies: 12
    Last Post: 03-10-2005, 06:48 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21