Author |
Topic: opening more than 4 COM ports at the same time (Read 353 times) |
|
janga
New Member
member is offline
Posts: 3
|
|
opening more than 4 COM ports at the same time
« Thread started on: Jan 5th, 2017, 07:15am » |
|
hello, It is my first post in this forum , so please excuse my mistakes. Is there a limit in the number of COM ports opened in the same time? I need to work with 5 COM ports reading data from external devices. I can open only 4 com ports , when I try to open the 5th I got the message "Too many open files at line 0". the code may look like this:
open "Com1:9600,n,8,1" for random as #com1 open "Com2:9600,n,8,1" for random as #com2 open "Com6:9600,n,8,1" for random as #com6 open "Com9:9600,n,8,1" for random as #com9 open "Com20:9600,n,8,1" for random as #com20 close #com1 close #com2 close #com6 close #com9 close #com20
the ports are present on the PC, each of them work separately , but 5 of them together are not willing to cooperate ...
Is there an easy solution to this problem or is it a set limit ? Best regards
Janusz
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: opening more than 4 COM ports at the same time
« Reply #1 on: Jan 5th, 2017, 08:25am » |
|
on Jan 5th, 2017, 07:15am, janga wrote:Is there an easy solution to this problem or is it a set limit ? |
|
It is a set limit in LBB (which it inherits from BBC BASIC) so there's not an easy solution, sorry. To open more than four serial ports simultaneously would require either using Windows API calls or some 'cheat' embedded BBC BASIC code.
I could try to write some code for you, if you are sufficiently keen to want me to do that. No promises though.
Richard.
|
|
Logged
|
|
|
|
janga
New Member
member is offline
Posts: 3
|
|
Re: opening more than 4 COM ports at the same time
« Reply #2 on: Jan 5th, 2017, 09:26am » |
|
Richard, Thank you so much for a fast answer. It would be nice not to have the limitation , but if it needs a lot of work I could try to find some other solution. Maybe running two separate programs and sending the data between them?
Thank you for your help,
Janusz
|
|
Logged
|
|
|
|
RobM
Junior Member
member is offline
Posts: 91
|
|
Re: opening more than 4 COM ports at the same time
« Reply #3 on: Jan 8th, 2017, 05:24am » |
|
I know nothing about working with com ports but if you are doing something like reading a temperature, could you open, read, and then close them one at a time?
|
|
Logged
|
|
|
|
janga
New Member
member is offline
Posts: 3
|
|
Re: opening more than 4 COM ports at the same time
« Reply #4 on: Jan 9th, 2017, 12:14pm » |
|
Thank you for the suggestion. It is of course possible to close and open the ports one by one , but some of the devices transmit the data asynchronously and there is a risk of loosing the data. Not all of them can respond to messages. It was a question rather to clarify if I was doing some mistake or if the problem was in some limits that I was not aware of. The answer was very fast so Thanks again.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: opening more than 4 COM ports at the same time
« Reply #5 on: Jan 10th, 2017, 12:46pm » |
|
on Jan 9th, 2017, 12:14pm, janga wrote:It was a question rather to clarify if I was doing some mistake or if the problem was in some limits that I was not aware of. |
|
I am confident that it should be possible to overcome the limit quite easily. Basically the trick will be to re-use the same 'handle' for more than one serial port, so for example if each handle is shared between two ports, it would raise the limit to 8 simultaneously-open ports.
One approach, which seems to work, is to provide a 'swap port' function that switches the given handle to an alternative port. A slight complication is that it's not straightforward to pass a handle as a parameter in Liberty BASIC (handles are always global) so I've been experimenting with either passing the handle as a string, or passing the native Windows handle (which you can get with the HWND function in LBB).
Unfortunately I am busy with other projects at the moment so I haven't been able to give this as much attention as it deserves.
Richard.
|
|
Logged
|
|
|
|
|