-
Feb 1st, 2023, 05:42 PM
#1
Thread Starter
Addicted Member
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
-
Feb 2nd, 2023, 05:21 AM
#2
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.
-
Feb 2nd, 2023, 05:56 AM
#3
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
-
Feb 8th, 2023, 09:50 AM
#4
Thread Starter
Addicted Member
Re: Exporting Data From My Program, Maybe An API
Originally Posted by Zvoni
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.
-
Feb 8th, 2023, 10:05 AM
#5
Re: Exporting Data From My Program, Maybe An API
Originally Posted by VB-MCU-User
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
-
Feb 8th, 2023, 01:40 PM
#6
Thread Starter
Addicted Member
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.
-
Feb 8th, 2023, 03:11 PM
#7
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
-
Feb 8th, 2023, 03:46 PM
#8
Thread Starter
Addicted Member
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.
-
Feb 8th, 2023, 06:32 PM
#9
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
-
Feb 8th, 2023, 07:21 PM
#10
Re: Exporting Data From My Program, Maybe An API
Originally Posted by Shaggy Hiker
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.
-
Feb 8th, 2023, 10:01 PM
#11
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
-
Feb 8th, 2023, 11:06 PM
#12
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.
-
Feb 9th, 2023, 12:18 PM
#13
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
-
Feb 11th, 2023, 09:23 PM
#14
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|