IonicWind Software

IWBasic => General Questions => Topic started by: dabil on September 01, 2017, 05:44:02 AM

Title: Using IWbasic dll with VB.NET
Post by: dabil on September 01, 2017, 05:44:02 AM
I am trying to use a dll originally written in IWbasic with VB.net or c# and don't understand how to properly construct the DLLImport sections for each of the calls.  Is there any documentation that will help?  I am trying to use the AIM_dll_863 for the AIM 4170.
Title: Re: Using IWbasic dll with VB.NET
Post by: Brian on September 01, 2017, 06:18:18 AM
Don't understand. How can a DLL be written in IWBasic WITH VB.net OR c# ?
Brian

I see now. The DLL was wriiten in IWB and you are wanting to use it with vb net or c#
What is the name of the Dll?
Title: Re: Using IWbasic dll with VB.NET
Post by: Andy on September 02, 2017, 05:49:31 AM
You would need to understand the IWB variable types to begin with.

I.E. Strings, Istrings, Char, Int, Uint, Int32, and Uint64 etc, and which type of IWB variable relates to VB or C equivalent.

That must be the starting point for you.



Title: Re: Using IWbasic dll with VB.NET
Post by: Brian on September 02, 2017, 06:16:08 AM
Dabil,

The attached zip file may help you, possibly

Brian
Title: Re: Using IWbasic dll with VB.NET
Post by: fasecero on September 03, 2017, 01:55:09 PM
This may give you something to start with. Please make sure to copy the DLL to the same folder that contains the vb executable, and compile the app for x86.


EXPORT Add
EXPORT Message
EXPORT GetExePath
EXPORT StructDoSomething

' Integer
SUB Add( INT a, INT b), INT
RETURN a+b
ENDSUB

' string
SUB Message(string text)
MESSAGEBOX(0, text, "Message from DLL", @MB_OK)
ENDSUB

' return a string
SUB GetExePath(string buffer)
buffer = GETSTARTPATH()
ENDSUB

' fixed struct
TYPE MYSTRUCT
    INT a
INT b
INT aplusb
    ISTRING ExePath[500]
ENDTYPE

SUB StructDoSomething(MYSTRUCT st)
' do something with st
st.aplusb = st.a + st.b
st.ExePath = GETSTARTPATH()
ENDSUB



Imports System.Runtime.InteropServices

Public Class Form1

    Declare Function Add Lib "mydll.dll" (ByVal a As Integer, ByVal b As Integer) As Integer
    Declare Sub Message Lib "mydll.dll" (ByVal text As String)
    Declare Sub GetExePath Lib "mydll.dll" (<Out()> ByVal buffer As System.Text.StringBuilder)

    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)>
    Public Structure MYSTRUCT
        <MarshalAs(UnmanagedType.U4)> Public a As Integer
        <MarshalAs(UnmanagedType.U4)> Public b As Integer
        <MarshalAs(UnmanagedType.U4)> Public aplusb As Integer
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=500)> Public ExePath As String
    End Structure

    Declare Sub StructDoSomething Lib "mydll.dll" (ByRef st As MYSTRUCT)

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' Integer
        Dim value As Integer = Add(3, 5)
        MessageBox.Show(Me, value.ToString, "Add")

        ' string
        Dim text As String = "hello world"
        Message(text)

        ' get string from DLL
        Dim sb As New System.Text.StringBuilder(500)
        GetExePath(sb)
        MessageBox.Show(Me, sb.ToString, "ExePath")

        ' fixed struct
        Dim st As New MYSTRUCT
        st.a = 3
        st.b = 5
        StructDoSomething(st)
        MessageBox.Show(Me, st.aplusb.ToString, "Struct - Add")
        MessageBox.Show(Me, st.ExePath, "Struct - ExePath")
    End Sub
End Class
Title: Re: Using IWbasic dll with VB.NET
Post by: dabil on September 18, 2017, 12:30:51 PM
 :) Thank all of you for your help.  I will try your suggestions.  I am trying to get the AIM_DLL_863 drivers to work with c#.  I'll let you know how I make out.
Title: Re: Using IWbasic dll with VB.NET
Post by: dabil on October 24, 2017, 10:02:58 AM
Here is the IWBasic DLL interface code that works.  Can some one give me the C# or VB equivalent? 

declare  "AIM_863_DLL",AIM_InitVars(flag:int),int
declare  "AIM_863_DLL",AIM_CommPort(flag:int,port:int, baud:int),int
declare  "AIM_863_DLL",AIM_ScanPoint(flag:int,freq_ : double,  Rss:double byref, Xss:double byref),int         
declare  "AIM_863_DLL",AIM_AvgReadings(avg : int),int
declare  "AIM_863_DLL",AIM_LoadCalFile(_str : string),int
declare  "AIM_863_DLL",AIM_ProgRelay(flag: int),int  : ' flag = 1 => close relay,  0 => open relay
declare  "AIM_863_DLL",AIM_GetVersion(flag:int),string
declare  "AIM_863_DLL",AIM_GetSerialNum(flag:int),int
declare  "AIM_863_DLL",AIM_GetRFVoltage(flag:int),double
declare  "AIM_863_DLL",AIM_Sync(flag:int),int  : ' 1 or 2=enable,  0=disable sync output



Title: Re: Using IWbasic dll with VB.NET
Post by: Brian on October 24, 2017, 11:04:29 AM
Dabil,

Where can you download this DLL? If you can't, could you post it here? You would probably have to zip it

Can't say I have ever heard of it in connection with IBasic over the years I have been a member

Brian
Title: Re: Using IWbasic dll with VB.NET
Post by: Brian on October 25, 2017, 03:25:39 AM
Dabil,

This is my best shot at converting your declares to VB. If they don't work, don't come running, as I am not a VB expert, but it should give you a start:

Declare Function AIM_InitVars Lib "AIM_863_DLL" (By Val flag As Long) As Long
Declare Function AIM_CommPort Lib "AIM_863_DLL" (By Val flag As Long, By Val port As Long, By Val baud As Long) As Long
Declare Function AIM_ScanPoint Lib "AIM_863_DLL" (By Val flag As Long, By Val freq_ As Double, By Val Rss As Double, By Val Xss As Double) As Long
Declare Function AIM_AvgReadings Lib "AIM_863_DLL" (By Val avg As Long) As Long
Declare Function AIM_LoadCalFile Lib "AIM_863_DLL" (By Val _str As String) As Long
Declare Function AIM_ProgRelay Lib "AIM_863_DLL" (By Val flag As Long) As Long 'flag = 1 => close relay, 0 => open relay
Declare Function AIM_GetVersion Lib "AIM_863_DLL" (By Val flag As Long) As String
Declare Function AIM_GetSerialNum Lib "AIM_863_DLL" (By Val flag As Long) As Long
Declare Function AIM_GetRFVoltage Lib "AIM_863_DLL" (By Val flag As Long) As Double
Declare Function AIM_Sync Lib "AIM_863_DLL" (By Val flag As Long) As Long '1 or 2=enable, 0=disable sync output

Note that the DLL has to be in the same folder as your program. If it is in a different place, you need to put the full path in the declare, as in this example: Declare Function AIM_AvgReadings Lib "c:\my folder\AIM_863_DLL" (By Val avg As Long) As Long

You could always look at this page for some more help:
https://msdn.microsoft.com/en-us/library/aa716201(v=vs.60).aspx

Best of luck,

Brian
Title: Re: Using IWbasic dll with VB.NET
Post by: Egil on October 25, 2017, 04:40:23 AM
There have been a lot of questions similar to this on several other forums lately, all about how to use the DLLs that comes with the AIM Antenna Analyzers.
Most questions about these analyzers will probably be answered here: http://aim4150.proboards.com/board/1/antenna-analyzer-forum (http://aim4150.proboards.com/board/1/antenna-analyzer-forum)

You can most probably get help from the supplier: https://www.arraysolutions.com (https://www.arraysolutions.com)
I beleive that the software that comes with these devices are propriatary, but if you have obtained a license this should not cause problems.

Lots of information on these analyzers can be found on W5BIG's website: http://www.w5big.com (http://www.w5big.com)


Good luck!
Egil - LA2PJ
Title: Re: Using IWbasic dll with VB.NET
Post by: Brian on October 25, 2017, 06:25:45 AM
Egil,

I had a quick search of the 'net this morning, and I couldn't find anything given the name of the DLL he mentioned, so I just did the conversions to the best of my ability. He is not very forthcoming with info, and I somehow can't believe it was ever written with an IW product

Let's hope your information will help him somewhat

Brian
Title: Re: Using IWbasic dll with VB.NET
Post by: Egil on October 25, 2017, 06:55:35 AM
QuoteLet's hope your information will help him somewhat

I hope so too Brian.
A friend of mine owns one of these small wonders, and on his specimen the web adress to the manufacturer is printed on a label on the back of the instrument. He is serving in Afganistan at the moment, but this morning he mailed me the link to the forum posted above.
He said he has a CD containing several AIM related programs and DLLs, but he is unable to find it until he is back in Norway some time next year.


Egil
Title: Re: Using IWbasic dll with VB.NET
Post by: dabil on October 25, 2017, 07:12:33 AM
If you go to this page

http://www.w5big.com/prog_update.htm
and download the AIM_910A software the 863 dll will be included in the zip.

You really need to device to tell if the software is working.  I can get the dll to work with IWbasic, but not C# or VB.
Title: Re: Using IWbasic dll with VB.NET
Post by: Brian on October 25, 2017, 07:23:03 AM
Have you tried my conversions at all?

Brian
Title: Re: Using IWbasic dll with VB.NET
Post by: Egil on October 25, 2017, 07:30:24 AM
QuoteI can get the dll to work with IWbasic, but not C# or VB.

That is probably because calls to the DLL functions need to be declared in a different format than that used with IWB.
Usually the helpfile for any coding language describe how to declare such calls. If not, I advise you to try posting your questions on a C# or VB users forum.
Sorry I can't be more specific, but I'm not familiar with any of the two languages.

But if you have coded a working example for interfacing the AIM analyzers, there are numerous radio enthusiasts (including me) on this forum that will love to see what you've done.


Good luck!
Egil
Title: Re: Using IWbasic dll with VB.NET
Post by: Brian on October 25, 2017, 07:46:36 AM
Which begs the question: If it works with IWB, why does he need to have it working with C or VB, with all the bloat that they bring?

Brian
Title: Re: Using IWbasic dll with VB.NET
Post by: Egil on October 25, 2017, 07:52:22 AM
I just downloaded the mentioned software, and to my surprise I found several pieces of EB code, showing how to use the DLL.


Dabil:
Have you seen the AIM_Software_Guide_121212 .pdf?
On page 6 there is a warning for users that use NET runtimes, with a suggestion on how to get rid of errors. Maybe that fix also can be of help for you?


Egil
Title: Re: Using IWbasic dll with VB.NET
Post by: Egil on October 25, 2017, 07:54:41 AM
Quote from: Brian Pugh on October 25, 2017, 07:46:36 AM
Which begs the question: If it works with IWB, why does he need to have it working with C or VB, with all the bloat that they bring?

Brian

Good question, but maybe he feels more comfortable with that languages. In addition some schools only accept coding projects made with one of them.


Egil
Title: Re: Using IWbasic dll with VB.NET
Post by: Brian on October 25, 2017, 08:02:58 AM
I'll download it tonight and have a look when I get home. I think I read somewhere that you can run it in demo mode if you have not got the device/hardware
Brian
Title: Re: Using IWbasic dll with VB.NET
Post by: dabil on October 25, 2017, 08:57:05 AM
I tried your conversion.

It is about what I came up with. 

These calls below function but get an error "Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at WindowsFormsApplication1.Form1.AIM_GetSerialNum(Int32 flag)"

        [DllImport("@AIM_863_DLL.dll", CallingConvention = CallingConvention.StdCall)]
        [return: MarshalAs(UnmanagedType.I4)]
        public static extern int AIM_InitVars([MarshalAs(UnmanagedType.I4)] int flag);

        [DllImport(@"AIM_863_DLL.dll", CallingConvention = CallingConvention.StdCall)]
        [return: MarshalAs(UnmanagedType.I4)]
        public static extern int AIM_CommPort([MarshalAs(UnmanagedType.I4)] int flag, [MarshalAs(UnmanagedType.I4)] int port, [MarshalAs(UnmanagedType.I4)] int baud);

        [DllImport(@"AIM_863_DLL.dll", CallingConvention = CallingConvention.StdCall)]
        public static extern string AIM_GetVersion([MarshalAs(UnmanagedType.I4)] int flag);

        [DllImport(@"AIM_863_DLL.dll", CallingConvention = CallingConvention.StdCall)]
        [return: MarshalAs(UnmanagedType.I4)]
        public static extern int AIM_GetSerialNum([MarshalAs(UnmanagedType.I4)] int flag);


The reason I am trying to integrate with Visual Studio as I have a program written that allows other analyzer to be used.  I am trying to integrate a 4170 as just another selection.
Title: Re: Using IWbasic dll with VB.NET
Post by: Brian on October 25, 2017, 12:46:29 PM
I downloaded the package, and converted the EBA file to IWB format - not a lot to do, really

And I generated a .lib file from the DLL with IWBasic. That's in the zip along with the DLL and .iwb file

As I said before, I am not an expert at all with Visual Studio or C, so that is the end of the trail for me

Brian
Title: Re: Using IWbasic dll with VB.NET
Post by: fasecero on October 25, 2017, 01:35:29 PM
I think we could help you better if you make a small functional sample in IWB and its equivalent not-working .NET and upload it in a zip. Maybe someone can have a better perspective of what may be happening by watching the actual code.

Edit: Sorry, this was actually a bad idea that is probably breaking a forum rule.
Title: Re: Using IWbasic dll with VB.NET
Post by: Brian on October 25, 2017, 02:02:28 PM
Fasecero,

I'm quite willing to help someone if I have the time, and the brains, but this is a forum for IWBasic programming, and Dabil should really be asking for help on the appropriate sites, not here. I've exhausted what I can do now - I don't know anything about Visual Studio or C#

Brian
Title: Re: Using IWbasic dll with VB.NET
Post by: fasecero on October 25, 2017, 03:16:58 PM
Oh. I didn't realize about that, thank you for pointing it out. I have edited my last post.
Title: Re: Using IWbasic dll with VB.NET
Post by: Brian on October 27, 2017, 03:18:20 AM
Dabil,

Keep checking this forum item: http://aim4150.proboards.com/thread/528/aim-dll

I have had a request put on this forum for information about interfacing the DLL with C# for you. It was only put on last night, so be patient!

I noticed that there were a couple of exports in the DLL that you haven't got defined. The export names are correct, but it is a guess to what they actually call:

DECLARE "AIM_863_DLL",AIM_ConstantFreq(flag:int),int
DECLARE "AIM_863_DLL",AIM_GetTemperature(flag:int),int

Brian
Title: Re: Using IWbasic dll with VB.NET
Post by: dabil on November 02, 2017, 07:47:32 AM
I have tried the manufacture first and they were not able to help either.  That is why I tried here.

Thanks for your help.  I'll just assume it is not possible at this point and move on.


Title: Re: Using IWbasic dll with VB.NET
Post by: ckoehn on November 02, 2017, 08:37:29 AM
Add to top of your source file:
Imports System.Runtime.InteropServices

Where ever you need your import:
<DllImport("AIM_863_DLL.dll", SetLastError:=True, CharSet:=CharSet.Auto)>_
public function AIM_InitVars(ByVal flag as integer) as integer
end function

<DllImport("AIM_863_DLL.dll", SetLastError:=True, CharSet:=CharSet.Auto)>_
public function AIM_CommPort(ByVal flag as integer, ByVal port as integer, ByVal baud as int) as integer
end function

<DllImport("AIM_863_DLL.dll", SetLastError:=True, CharSet:=CharSet.Auto)>_
public function AIM_ScanPoint(ByVal flag as integer, ByVal freq_  as double, ByRef  Rss as double, ByRef Xss as double) as integer         
end function

<DllImport("AIM_863_DLL.dll", SetLastError:=True, CharSet:=CharSet.Auto)>_
public function AIM_AvgReadings (ByVal avg as integer) as integer
end function

<DllImport("AIM_863_DLL.dll", SetLastError:=True, CharSet:=CharSet.Auto)>_
public function AIM_LoadCalFile (ByVal _str as string) as integer
end function

<DllImport("AIM_863_DLL.dll", SetLastError:=True, CharSet:=CharSet.Auto)>_
public function AIM_ProgRelay(ByVal flag as integer) as integer ' flag = 1 => close relay,  0 => open relay
end function

<DllImport("AIM_863_DLL.dll", SetLastError:=True, CharSet:=CharSet.Auto)>_
public function AIM_GetVersion(ByVal flag as integer) as string
end function

<DllImport("AIM_863_DLL.dll", SetLastError:=True, CharSet:=CharSet.Auto)>_
public function AIM_GetSerialNum (ByVal flag as integer) as integer
end function

<DllImport("AIM_863_DLL.dll", SetLastError:=True, CharSet:=CharSet.Auto)>_
public function AIM_GetRFVoltage (ByVal flag as integer) as double
end function

<DllImport("AIM_863_DLL.dll", SetLastError:=True, CharSet:=CharSet.Auto)>_
public function AIM_Sync(ByVal flag as integer) as integer  ' 1 or 2=enable,  0=disable sync output
end function

It should be something like that.  Maybe it will give you something to start with.

Later,
Clint