Results 1 to 14 of 14

Thread: Exporting Data From My Program, Maybe An API

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2010
    Posts
    177

    Exporting Data From My Program, Maybe An API

    Hi all,

    I have a Vb.net program that receives data from an external device through a USB connection. I need to have some kind of short program interface that would allow other programmers to receive data from my device and import it into their own programs. I believe that this kind of program is called an API. Correct me if I'm wrong. I have read that APIs can do things like this, but I'm not sure if that's what I need.

    What would be the easiest way for me to achieve this? Can you provide some kind of tutorial where I can read about it?

    Thanks,

    Robert

  2. #2
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Exporting Data From My Program, Maybe An API

    APIs apply to more than just communicating with devices. An API is basically a contract between a programmer and a system that specifies how that system expects the programmer to talk to it. For example, when you want Windows to save a file, you use the WriteFile function of the Win32 API. The definition of the function in the Windows documentation contains all the information about that contract like what parameters it expects and what you can and cannot do with each parameter.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  3. #3
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    Re: Exporting Data From My Program, Maybe An API

    It's also dependant on what you mean with "Import".

    Is your program writing an output to some file? Do those other users want to import that file? File-Format resp. how is the Data structured in that File?
    Or are you writing your Data into a Database (local database or Server-Database)? You could provide access to the Database.

    Or do those other users want to see your data in kinda "realtime"? Then DDE might be an approach.

    Or you could use COM (i'm coming from vb6, so for .NET it might be called something else).
    Basically, you provide a public Interface in your program (can be Events or Procedures/Methods), where "subscribers" can "tap" into that interface to grab your data
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jun 2010
    Posts
    177

    Re: Exporting Data From My Program, Maybe An API

    Quote Originally Posted by Zvoni View Post
    Or do those other users want to see your data in kinda "realtime"? Then DDE might be an approach.
    This sounds more of what I want. I need to research how to use this DDE.

  5. #5
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    Re: Exporting Data From My Program, Maybe An API

    Quote Originally Posted by VB-MCU-User View Post
    This sounds more of what I want. I need to research how to use this DDE.
    DDE = Dynamic Data Exchange
    https://en.wikipedia.org/wiki/Dynamic_Data_Exchange
    and is currently maintained in Windows systems only for the sake of backward compatibility.
    "modern" Alternative to DDE: Observer Pattern

    https://en.wikipedia.org/wiki/Observer_pattern
    Last edited by Zvoni; Feb 8th, 2023 at 10:08 AM.
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jun 2010
    Posts
    177

    Re: Exporting Data From My Program, Maybe An API

    Hmm, it looks like DDE is not supported by VB.Net. It was supported by VB6. I found these comments on Google,

    The LinkX properties were included in VB 6 for backward compatibility with Dynamic Data Exchange (DDE), a technology that hasn't been used since the days of Windows 3.1. If your project really requires DDE support then unfortunately you will not be able to move it forward to VB .NET.

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Exporting Data From My Program, Maybe An API

    I'm unclear on the setup. Where are the different things located? Your device and computer are in one location, where are the other developers? If they are going to be accessing things across the web, then WebAPI would do what you want. That could work even within a LAN or VPN, though it would likely be overkill, since WebAPI would require a web server. For internal only connections, then you have a variety of options.
    My usual boring signature: Nothing

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jun 2010
    Posts
    177

    Re: Exporting Data From My Program, Maybe An API

    Shaggy, the device and computer are connected through a USB connection. My program receives the data and does some data processing. Is it possible to pass this data realtime to another program developed by someone else. Everything happens in the same PC without the internet connection. I'm thinking about writing data to a text file. But this doesn't look too professional.

  9. #9
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Exporting Data From My Program, Maybe An API

    If it happens in the same PC, perhaps all you need to do is write up a class library that contains the functionality. Then any other program could reference the class library.

    That might not be ideal, though. If your program should be running regardless of whether or not anybody is using it, then the class library approach wouldn't be the best.

    Writing data to a text file isn't the best, either. Others might have different suggestions, but one is TCP or UDP. UDP would allow you to ping out data as it comes in, regardless of whether or not anybody is listening, but it works best with relatively small data packets. Small means a few thousand bytes in a message, so it's not all THAT small.

    TCP would mean establishing a connection, which means that your program would be listening for connections. The other program would connect to it, then you'd pass along the data. Of course, that means that the other program would HAVE to be running, as it would be the other side of the connection.
    My usual boring signature: Nothing

  10. #10
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Exporting Data From My Program, Maybe An API

    Quote Originally Posted by Shaggy Hiker View Post
    UDP would allow you to ping out data as it comes in, regardless of whether or not anybody is listening, but it works best with relatively small data packets. Small means a few thousand bytes in a message, so it's not all THAT small.
    Actually this is a misconception born out of fear of UDP's unreliability. UDP is perfectly capable of handling large volumes of data. The difference is that the developer has the responsibility of ensuring the integrity of the data where as this is guaranteed by the TCP protocol. UDP is preferred in scenarios where latency matters and is used in a lot of software and systems to transfer large amounts of data. For example, it's often preferred in streaming protocols for video or multiplayer video game data.

    It works best with small amounts of data only when you have no intention of ensuring integrity. This distinction is important.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  11. #11
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Exporting Data From My Program, Maybe An API

    That's true. However, the question of integrity becomes considerably more complex if the amount of data exceeds the packet size, which is based on the network. Of course, internally, that isn't really an issue. UDP packets can be dropped or duplicated. Sequencing takes care of that, but not sequencing is easier. Therefore, UDP becomes particularly simple for those cases where losing a packet doesn't really matter...and all of that doesn't matter within a single computer, as packet collision in that environment, though never frequent, is going to be mighty unlikely.
    My usual boring signature: Nothing

  12. #12
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Exporting Data From My Program, Maybe An API

    You are right of course. I just think we should be very careful that we don't discourage usage of UDP. It gets such a bad reputation when in fact it's a very good protocol when used correctly for what it was intended.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  13. #13
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Exporting Data From My Program, Maybe An API

    That's true. I, personally, really like UDP and wouldn't want to do anything to discourage use of it. There are caveats that people should be aware of, but UDP is the best solution in a whole lot of cases. It's particularly ideal for broadcasting within a LAN, which is why it was the basis for a lot of LAN games over the years.
    My usual boring signature: Nothing

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Jun 2010
    Posts
    177

    Re: Exporting Data From My Program, Maybe An API

    Thanks for your suggestions. Another idea can be just to tell the third party developer how to read the USB device data in order to be able to use it in his program. This might be the easiest and cleanest way.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width