Pira.cz Technical Forum

Radio Data System (RDS) => MRDS1322 => Topic started by: SteveyD on July 02, 2011, 10:11:46 am

Title: Development of interface software for the miniRDS in C#
Post by: SteveyD on July 02, 2011, 10:11:46 am
Greetings

Anyone else out here working on a C# version of the mrdsio.dll example?

Code: [Select]
procedure ConnectionSetup(ConMode, PortNum: integer; Bidirectional, Slow: boolean); using the Delphi pascal works fine for the LPT ports.

converting it to C#

Code: [Select]
[DllImport("mrdsio.dll")]
        public static extern void ConnectionSetup(int ConMode, int PortNum, bool Bidirectional, bool Slow);

PortNum = 0x378
PortNum = 378
PortNum = 888

None of the different PortNum defines will access the LPT1 in C#

Anyone know the reason?
Title: Re: Development of interface software for the miniRDS in C#
Post by: SteveyD on July 02, 2011, 10:47:18 am
Sorted it out..  I was missing the Inpout32.dll  in the directory.

On to the next step.

Title: Re: Development of interface software for the miniRDS in C#
Post by: SteveyD on July 05, 2011, 09:07:25 pm
Jan

mrdsio.dll

Does the dll return a C-style array or SafeArray?

I've got everything working in C# except the Receive function

 
Title: Re: Development of interface software for the miniRDS in C#
Post by: Jan on July 06, 2011, 09:04:50 am
It's probably no one from the two options.

If you can pass the array in the Send function, it should be possible to get it also using the Receive function as the array format is still the same.

The Delphi array declaration

Code: [Select]
TData = array [0..255] of byte;
is probably equal to

Code: [Select]
BYTE TData[255];
However if you know better format for the array to pass, the mrdsio.dll can be updated as it is still possible at this stage.
Title: Re: Development of interface software for the miniRDS in C#
Post by: SteveyD on July 06, 2011, 12:22:18 pm
Thanks Jan

The current Array function in Delphi is the best method at this point.

I've encountered some difficulty calling the Array from the mrdsio.dll in C#

Its most likely something I'm not doing correctly in the Receive routine as the Send routine works fine.
Title: Re: Development of interface software for the miniRDS in C#
Post by: SteveyD on July 28, 2011, 02:35:09 am
Jan

can you take a look at the Receive function of your example1.pas 

Procedure  TForm.Button5Click(Sender:TObject);

"if not(CheckBox1.Checked) then
begin StatusBar1.SimpleText:='Bidirectional operation not allowed';exit;end; "


IF the CheckBox1 is checked, then Bidirectional operation is allowed.
IF the CheckBox1 is not checked, then Bidirectional operation is not allowed.


Your Procedure checks the CheckBox1 and if it is checked, will continue on to receive the data.
(Bidirectional operation IS allowed, and required to complete the procedure as the code is written)

If the CheckBox1 is not checked, then you get the trap of "Bidirectional operation not allowed" with an exit. which is the exact opposite logic of what you want.


Is the trap even needed?  if so, you should change;

"if not (CheckBox1.Checked) then"


Steve








Title: Re: Development of interface software for the miniRDS in C#
Post by: Jan on July 28, 2011, 10:15:32 am
It is surely right as it is, you cannot read any data in uni-directional mode, so -> exit.
Title: Re: Development of interface software for the miniRDS in C#
Post by: SteveyD on July 30, 2011, 02:46:51 pm
I see, Bi-directional operation is REQUIRED.

therefore the trap is correct, and the CheckBox1 must be checked.

The error is the message;

StatusBar1.SimpleText:="Bidirectional operation not allowed"

should be

StatusBar1.SimpleText:= "Bidirectional operation required"



On another note,  Which is returned in the Receive function,  TData as a byte array  or Result: Output as a string?

Title: Re: Development of interface software for the miniRDS in C#
Post by: Jan on July 30, 2011, 03:26:49 pm
You may take the example sources and modify them as required.
Title: Re: Development of interface software for the miniRDS in C#
Post by: SteveyD on September 14, 2011, 05:39:24 pm
Has anyone come up with a working example for using the Receive function in VB or C#?
I've converted and tested all the functions except Receive. Its still giving me problems.

function Receive (Adr, Len : Integer); TData; stdcall;

Title: Re: Development of interface software for the miniRDS in C#
Post by: SteveyD on September 19, 2011, 01:19:06 am
Solved!

I had a Bool declaration backwards
Title: Re: Development of interface software for the miniRDS in C#
Post by: SteveyD on October 17, 2011, 09:15:20 am
Jan

I've been encountering application crashes when I use the "Disconnect" button on your example.exe

This occurs in WinXP Sp3, as well as Win7 Sp1.

The error always occurs in the same memory location on the mrdsio.dll

I'm trying to get a screen shot to post.

Has anyone else reported this problem?

Steve
Title: Re: Development of interface software for the miniRDS in C#
Post by: Jan on October 17, 2011, 09:29:38 am
Make sure you have the latest version http://pira.cz/rds/mrdsio.zip
This works stable for me using any combination of OS or settings.
Title: Re: Development of interface software for the miniRDS in C#
Post by: SteveyD on October 17, 2011, 10:38:37 am
Yes, I'm using Dll version 0.98

Application Error

Exception EAccessViolation in module mrdsio.dll at 000038C4,
Access violation at addres 075938C4 in module 'mrdsio.dll'.
Read of address 00000000.
Title: Re: Development of interface software for the miniRDS in C#
Post by: Jan on October 17, 2011, 11:59:50 am
Is your example file actual too?
Title: Re: Development of interface software for the miniRDS in C#
Post by: SteveyD on October 17, 2011, 02:33:28 pm
Yes,  even the most recent zip package from 4 posts above.

It occurs on your example.exe in Delphi as well as my C# conversion.
Title: Re: Development of interface software for the miniRDS in C#
Post by: Jan on October 17, 2011, 03:49:19 pm
The Disconnect procedure is pretty simple:
Code: [Select]
procedure TDM1.Disconnect;
begin
Connected:=false;
try
  VaComm1.Close;
  sleep(200);
  except
  end;
end;

Could you confirm that the error occurs also if you connect to some COM port previously?
Title: Re: Development of interface software for the miniRDS in C#
Post by: SteveyD on October 18, 2011, 02:11:45 am
Jan

I've tested my Serial (with 2K resistor replacement) version and it consistently returns the error.

My LPT version is functioning fine in both Delphi and C#.

I will rebuilding my Serial interface cable and will test again.

Steve
Title: Re: Development of interface software for the miniRDS in C#
Post by: Jan on October 18, 2011, 09:06:35 am
This kind of error may occur if you use USB to RS232 converter and if you remove the converter from the USB before the connection is closed in the application. (But for example FTDI drivers are well written and do not raise this error.)

The cable wiring has no effect on it. It may be a driver issue. There's something more you can test:
http://pira.cz/rds/TinyRDS_Setup.exe (http://pira.cz/rds/TinyRDS_Setup.exe) - This is the minirds control software based on mrdsio.dll
http://pira.cz/rds/minirds.zip (http://pira.cz/rds/minirds.zip) - This is an older minirds control software that accesses the port directly (but using the same VaComm component).
Title: Re: Development of interface software for the miniRDS in C#
Post by: SteveyD on October 23, 2011, 06:33:54 pm
Error was found

my Serial adapter cable was at fault.

Title: Re: Development of interface software for the miniRDS in C#
Post by: Jan on October 23, 2011, 09:37:56 pm
Is it a USB to RS232?
Title: Re: Development of interface software for the miniRDS in C#
Post by: SteveyD on October 23, 2011, 10:08:25 pm
No, just a simple bi-directional Serial port interface.

I built a new interface and the errors are gone.