Serial Comm Port

Share your advanced PureBasic knowledge/code with the community.
drahneir
Enthusiast
Enthusiast
Posts: 105
Joined: Tue Jul 18, 2006 4:18 pm
Location: JO42RM

Serial Comm Port

Post by drahneir »

I have an external application and my own one, both must have access to the same comm port.
This is not possible under Windows. Only the application which has opened the port has access to it.
The access by the external program is minimal: just setting the state of the RTS line to switch a device on and off.
Fortunately, the program releases the comm port when it has switched off the device.
This makes solution 1 very simple: I can do everything with the port during the switch off period. When my comm tasks are finished, I in turn release the port,
so that the other program has access again. OK, I can't access the port during the switch on period.
Solution 2 uses a virtual serial cable (created by VSPManager). Each end of the virtual serial cable is assigned to a virtual comm port. I have named the ports COM7 and COM17.
COM7 is used by the external application, COM17 by my program. The real existing port which is connected to the switched device is COM3.
When the foreign program sets RTS of COM7, this change is reflected at CTS of COM17. What my program has to do, is to transfer the state of CTS of COM17 to RTS of COM3.
This can be done in a single line command:

SetSerialPortStatus(3, #PB_SerialPort_RTS, GetSerialPortStatus(17, #PB_SerialPort_CTS))

Before I came to VSPManager I used VSPE. With VSPE one can assign a random number of virtual comm ports to a real existing port, which makes the multi access to a comm port very easy.
Why I don't use it anymore is the fact, that is was difficult to exit VSPE without any remainders. In my case a restart of the PC was always necessary.
infratec
Always Here
Always Here
Posts: 7582
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Serial Comm Port

Post by infratec »

In such cases I use com0com

http://com0com.sourceforge.net/

There is also a signed installer in the web.

You are looking for hub4com which is included.

Bernd

P.S.: Is your posting really a trick or a tip :?:
drahneir
Enthusiast
Enthusiast
Posts: 105
Joined: Tue Jul 18, 2006 4:18 pm
Location: JO42RM

Re: Serial Comm Port

Post by drahneir »

Bernd,

my post doesn't show a trick, it's just a tip for those who are not so familiar with the serial interface.
I have tried com0com as well, but IMHO VSPManager is the easiest way to create and delete virtual comm ports.

Alles Gute noch im Neuen Jahr.

Reinhard
Post Reply