ni.com is currently experiencing unexpected issues.
Some services may be unavailable at this time.
04-17-2008 04:20 AM - edited 04-17-2008 04:21 AM
04-17-2008 04:38 AM
04-17-2008 06:52 AM
By "parallel communication" I mean (my goal) "independent communication".
I try to explain better what I'm trying to do.
If you have a routine R that does a task using 1 serial COM port and a set of parameters P_1, and you must invoke the same routine for other 2 different set of parameters P_2 and P_3, what can you do?
Solution 1 (serialization approach):
You call R passing P_1, then R passing P_2, then R passing P_3.
You call R three times in sequence (slow .... )
Solution 2 ( correct? )
Consider that each routine R is independent (it doesn't use global variables, so I don't have the problems of dealing with semaphores, because I don't risk to write/read a variable from two different points), and consider that R is described (implemented) by the state machine in FIG2.
So each instance of R runs on it's own state-machine.
Inside each R, there could be some calls to the serial write/read VISA... but there is a timeout waiting the response, example:
modbus_read(register_1) = init serial port + send_modbus_packet_request_to_outSerialBuffer + read the response (retry&timeout protocol)
Is it possible that meantime, another process (the same R also!?), get access to the serial port and queues another modbus request???
Only function 3 and 6 of modbus protocol are available:
3 = read one single register
6 = write one single register
So in your opinion this is impossible? I think it's possible, otherways the whole ModBus chain over RS485 would be impossible to do ( = multiple devices sharing the same COM port, access to this common medium is ruled by Modbus protocol state machine,all device receive the packet_request, but only the one which match the address responds). This is the scheme:
PC + COM1 < --- Modbus over serial line RS485---->> DEV 1 (addr=1) + DEV 2 (addr.34) + DEV 3 (addr.22) + .... etc...
04-17-2008 07:14 AM
04-17-2008 09:26 AM - edited 04-17-2008 09:27 AM
I initialize and close the VISA resource every time I call the read_register / write_register routine to achieve this behaviour:
it is possibile to have 2 distinct exe files that use the same port at the same time, without conflict.
If you have a program that at the beginning initializes one COM (to use it only sometimes in the program, not continuosly), and then you build it, you have an application that will reserve that COM for itself.
But if you need an extra instance of this program (so two exe running in parallel) and you want to use it on the same COM, they will conflict.
The approach is to initialize/opeon/close practically on demand...
I don't know if there are better ways to do this, but what I said is proven and working (even if I don't fully understand how )
But this brings to me another question about the topic:
In this last case (2 exe running, the same program opened two times, just copy paste his folder elsewhere) opening/closing on demand the same COM port, how are they handled in case of simultaneous access to the COM?
Is the OS (multithreaded) that seemless time-shares the resources, letting resolve one or the other application access to the COM???
04-17-2008 09:46 AM