Using DOTNET class to communicate with a COM Port

222 views Asked by At

I search someone who would have already used the class DOTNET to communicate with a COM port. In a e-Health PHP Project, I search to obtain datas from a smart card. After to be fallen on several methods reserved to Linux, I found this DOTNET class allowed to access to a port to communicate with an external device.

$serial = new DOTNET('system', 'System.IO.Ports.SerialPort');
$serial->PortName = 'COM8';
$serial->Open();

I modified the file php.ini as indicated on another forum to uncomment these three lines, but it seems it's not enough :

extension=php_com_dotnet.dll   
extension_dir = "ext"   
enable_dl = On

When trying to open connection, Wamp send me the following error message :

Fatal error: in C:\wamp64\www\node-project\patients.php on line 204

com_exception: in C:\wamp64\www\node-project\patients.php on line 204
1

There are 1 answers

6
kunif On

Please refer to the comments on this page.
PHP: dotnet - Manual

The dotnet class allows you to instantiate a class from a .Net assembly and call its methods and access its properties, if the class and the methods and properties are ยป visible to COM.

Neither instantiating static classes nor calling static methods is supported.

Some .Net classes do not implement IDispatch, so while they can be instantiated, calling methods or accessing properties on these classes is not supported.

Note:
.Net framework 4.0 and later are not supported by the dotnet class. If assemblies have been registered with regasm.exe, the classes can be instantiated as com objects, though.

juan156_elias at gmail dot com

Using COM and DOTNET directly is quite a nightmare. DOTNET only allows you to target .Net 3.5 and below, and all the binaries need to be COM Visible. This basically means that you will need to write your own .Net binaries for everything, at least wrappers.

You can't use the .NET API directly as you mentioned in the question article, you have to create and register a COM visible wrapper using .NET 3.5 or lower framework and call it.