Pira.cz Technical Forum
Radio Data System (RDS) => MRDS1322 => Topic started 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?
procedure ConnectionSetup(ConMode, PortNum: integer; Bidirectional, Slow: boolean);
using the Delphi pascal works fine for the LPT ports.
converting it to C#
[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?
-
Sorted it out.. I was missing the Inpout32.dll in the directory.
On to the next step.
-
Jan
mrdsio.dll
Does the dll return a C-style array or SafeArray?
I've got everything working in C# except the Receive function
-
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
TData = array [0..255] of byte;
is probably equal to
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.
-
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.
-
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
-
It is surely right as it is, you cannot read any data in uni-directional mode, so -> exit.
-
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?
-
You may take the example sources and modify them as required.
-
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;
-
Solved!
I had a Bool declaration backwards
-
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
-
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.
-
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.
-
Is your example file actual too?
-
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.
-
The Disconnect procedure is pretty simple:
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?
-
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
-
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).
-
Error was found
my Serial adapter cable was at fault.
-
Is it a USB to RS232?
-
No, just a simple bi-directional Serial port interface.
I built a new interface and the errors are gone.