LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

send two signals at the same time to serial

Hi
 
I have a problem in that I want to control some relay boards by serial. The boards have an address byte (to determine which of the three relay boards) and a relay combination (four relays on each board). The .vi I will need to make will be sending data to the serial as a result of feedback from sensors (they are currently simply controlled by timers to simulate) so there is a good chance that there will be two relay addresses sent at the same time and consequently much confusion. The timed simulation demonstrates this possibility by switching all relays on at the start.
Is there a way of avoiding this? Any help would be much appreciated.
 
Many thanks
 
Alastair
0 Kudos
Message 1 of 9
(3,669 Views)
Why not use one COM port for each serial device, in that case you can send a command at the same time to all boards.
Regards,
André (CLA, CLED)
0 Kudos
Message 2 of 9
(3,664 Views)

Thanks Andre,

You have touched on a sore point there. I am trying to get this control system set up with the help of a computing student doing a years work experience, and as it took us so long to find the best way of getting the boards to respond to their correct address he is rather keen to do it from a single port. I am in favour of the easy way as you suggest! We even have a serial multiplexer.

Many thanks,

Alastair

0 Kudos
Message 3 of 9
(3,662 Views)
Alastair,

When you say send to multiple boards "at the same time" exactly what to you mean? On a serial port only one byte at a time can be sent. You do not specify how many bytes are sent to each board to handle the addressing, the data, and any EOT (End of Transmission) characters.

I can think of two possibilities.

1. Relays are slow. If the transmission rate is fast enough, you could send messages to all relays sequentially over the serial port but still have the appearance of simultaneous activation of the relays. If the relays switch in 10 ms and each command contains 6 bytes, sending the data at 115 kilobaud would take about 1.5 ms for three boards. This would likely be close enough to simultaneous for relays.

2. Add a command similar to the GPIB GET (Group Execute Trigger). All devices on the bus respond to this command by executing a previously stored command. No addressing is used for this command. This does require that the relay boards be modified to respond to their address and to the common or group address and to store a command for later execution.

Lynn
0 Kudos
Message 4 of 9
(3,644 Views)

Hi Lynn

Thanks for the advice. The address byte is 8 bits as is the following relay on/off byte. It has a stop bit but I am not sure about EOT characters as I am sending decimals rather than the ASCII string equired by VISA.

The problem is not in the relay speed, but in the serial interface itself. I will have no control of 'pump off' times in the final .vi as they will be calculated as part of an optimisation algorithm, so they could stop at exactly the same time as the mix cycle for example. We need something to do the following: 'if there are two simultaneous addresses, then send them with a slight time delay' according to my colleague who has experience of text based programming. He suggested that some sort of queue is required, but using the 'PtbyPt queue' method is still randomly flicking between the two addresses, but in a way it does store the commands, I think?

Best regards

Alastair

0 Kudos
Message 5 of 9
(3,630 Views)
If you write a driver for your relay board and set the VI not to be re-entrant, then you will not be able to send two commands at once.  It sounds as if you are using the raw VISA write in your control loops.  Write a subVI that is basically a wrapper around the VISA VIs, and another loop will not be able to communicate with the relay board until the first loop has finished.  This will allow you to send a command and wait for a repsonse.  If you can't hold up your control loop, then you will need to dump them into a queue.


Message Edited by Matthew Kelton on 12-03-2007 09:51 AM
0 Kudos
Message 6 of 9
(3,624 Views)
That sounds like an oppertunity to use an Action Engine.
 
Just make sure your transmit/recieve are in the same "action" and other calls will be blocked until the operation completes.
 
I talk about how this is acheived in the Action Engine Nugget.
 
Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 7 of 9
(3,623 Views)
The easiest way to avoid a conflict is to use a semaphore. Each piece of code that writes to the relay will need to acquire the semaphore, write to the serial port, then release the semphore. If another function tries to write at the same time, it will wait until the semaphore becomes available. Semaphore VIs are located in the synchronization palette. Look at the examples if you've never used them before.

Edit: or Ben's suggestion, the action engine. This would work great, but if you already have all the code written and don't want to change a lot, adding code for a  semaphore isn't too difficult.


Message Edited by Marc A on 12-03-2007 10:55 AM
0 Kudos
Message 8 of 9
(3,619 Views)

Thank you to everyone for your help, I will need some time to take in all this information as it is all new to me.

Many thanks

Alastair

0 Kudos
Message 9 of 9
(3,586 Views)