I hope it is ok to post here, since I don't know a better forum to ask my question.
I use right now one of theese cheap USB to RS232 adapters to let my PC sent serial commands via Python to my Cambridge Azure AVR.
Normally it is just one line that wil be send, but sometimes the script needs to read the answer of the AVR (also just one line) for if-decisions.
I now want to have a second PC to do the same (it is very unlikely that I push a buttons on both PCs at the same time), bit the AVR has just one RS232 interface.
Is there a cheap way to connect both PCs the same time?
Can I use one of these 10$ Y-Adapters from Amazon for this?
I found a protocol specification for Azur 851E. Is that the document you are using? If not, can you provide a link to the document you are using.
Do you have some information on which RS232 signals, other than Gnd, Data TX, Data RX, that need to be used? I.E. does the Azur unit require the use of any of the RS232 handshake signals.
If it only needs Gnd, TX, and RX then a DPDT switch that you move manually to select PC1 or PC2 would work. IDK if having a manually operated switch would suit your requirements.
It would be okay to wire both PCs RX pins to the Azur TX pin.
It would not be okay to wire both PCs TX pins together. If that's what the Y adapator you refer to would do, then no, it's not suitable
A switch that requires a trigger (by hand or maybe a software triggered relay) is better than nothing, but not a real satisfying way.
Maybe I'm not deep enough into the serial stuff, but I think that it is important to mention that I close the serial connection after every script.
So there ist none of the PCs, just the Cambridge, listening the whole time.
As an example, here is the "most complicated" script I use:
import serial
import time
try:
ser = serial.Serial( port="COM3",
baudrate=9600,
bytesize=serial.EIGHTBITS,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
timeout=2 )
print ("Serial port is open")
except Exception as e:
print ("error open serial port: " + str(e))
exit()
try:
s = "Test"
print (s)
ser.write(b'\r')
ser.write(b'#1,03\r')
s = ser.read(18)
s = s.decode("utf-8")
if s.rstrip().endswith('#6,11,00'):
print ("Was already muted.")
ser.write(b'#1,02\r')
else:
ser.write(b'#1,02\r')
print ("Send to mute.")
time.sleep(0.1)
ser.write(b'#1,11,01\r')
s = ser.read(8)
print (s)
ser.close()
print ("Closed Port.")
except Exception as e:
print ("error communicating...: " + str(e))
So about:
How will your AVR know which PC to send the answer to?
That might be a problem. If PC #1 sends a message to the AVR which requires a response, and that response is received by both PC, then PC#2 might receive and keep that response in its buffer. Then later PC #2 sends a message that requires a response and then reads the response, it will read the response from the buffer, which was the response of the earlier request from PC#1.
This could be fixed by having each PC clear it's buffer before sending a request, which would remove any previously received responses. I don't know if closing the port has the side-effect of clearing the buffer.
I think closing the interface workes fine enough on this buffer.
The Cambridge sends a status-response after nearly all commands.
Even if you move the volume poti by hand, the Cambridge will send the new volume vis serial.
So even right now with my commands I simply ignore nearly everything the Cambridge "says".
Muting is the only command where I work with the answer, since there is no mute-toggle command (so the script needs to check if it needs to mute, or unmute).
As mentioned, you can probably connect the AVR's TX pin to the RX pins of the RS232 adapters of both PCs.
It's combining the two TX pins of the PCs to the single RX pin of the AVR that is more difficult.
You cannot simply connect them. According to the RS232 specification, if I have understood it correctly, connecting them together should not damage anything, but the signals may be garbled, even if only one PC is sending at any time, so the AVR may not be able to read them.
RS232 signals can vary between -15V and +15V, so they are not compatible with most logic chips, including Arduinos, and adapters must be used to convert between the -15~+15V levels used by RS232 and 0~5V levels used by logic chips.
With such level converters, and a few diodes and resistors to make a simple OR-gate, it might be possible. The MAX232 chip provides 2 pairs of level converters, so you could do it with 2 of these chips, I think, plus a 5V supply and various capacitors, resistors and diodes.
A more sophisticated version including an Arduino could be made, but as mentioned, an Arduino with 3 hardware serial ports would be needed. Maybe one with 2 hardware and one software serial port could be possible. But I don't think the advantages of using an Arduino would be worth the extra cost and complexity.
First I'll give it a try with a simple 3€ y-adapter, a friend of my used in a similar situation.
I ha dto order parts anyway and I have two times the identical Usb to serial converter here.
If that is not working and even it looks over-engineered, I think such a module could be the smart way: