0

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
ADyson
  • 57,178
  • 14
  • 51
  • 63
  • I think this library is not what you need. I think you are confused between two different meanings of "COM". You are talking about a "COM port", more commonly known as a "serial port" which is a physical connector on your computer. Whereas this DotNet library is designed to be an interface to interact with the Windows .NET framework via the "COM" interface which is a software programming interface, its full name is "Component Object Model". These are two totally different things which just happen to share the same acronym. – ADyson Sep 03 '20 at 17:30
  • I think you will get better results if you search for [PHP connect to serial port](https://www.google.com/search?q=php+connect+to+serial+port), there is plenty of more relevant information for you to use – ADyson Sep 03 '20 at 17:32

1 Answers1

0

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.

kunif
  • 4,060
  • 2
  • 10
  • 30
  • Do you have a tutorial which explains how to do ? – Prince Mychkine Sep 03 '20 at 15:26
  • I don't see really what you mean on create and register this COM visible wrapper. I don't know the framework .NET. I have just found this method to communicate with a port on Internet. Other ways were exclusive to Linux. – Prince Mychkine Sep 03 '20 at 15:28
  • Please check this page [Walkthrough: Creating COM Objects with Visual Basic](https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/com-interop/walkthrough-creating-com-objects) from Microsoft or these articles from stackoverflow. [Turn a simple C# DLL into a COM interop component](https://stackoverflow.com/q/7092553/9014308),[How to register a DLL with RegAsm in Build EventS VS2013](https://stackoverflow.com/q/37854287/9014308),[How to register a .NET assembly as COM?](https://stackoverflow.com/q/11322353/9014308) Even if you didn't know it until now, you should look into it. – kunif Sep 03 '20 at 15:41
  • I have need to use Visual Basic and C# ? It can't be done only with PHP ? – Prince Mychkine Sep 03 '20 at 16:14
  • Yes, it is necessary. Alternatively, even if it is made in C++, it can work as COM(Component Object Model). If you already have a PHP library with such functionality, you may consider using it. It might be good to look for it. – kunif Sep 03 '20 at 16:22
  • Thank your very much for your responses. It's a bit too much for me for the moment. I will watch that later, but I think I will try a simpler way at first. Thank you still despite that. – Prince Mychkine Sep 04 '20 at 08:46