I asked this question on the Engineering StackExchange and someone said it might be more appropriate here.
I want to interface an old Shimadzu spectrophotometer (Model UV-1601, manual here) through its RS-232C port, which is described in the manual in Fig. 12.2:
I want to use a USB Type C connection on my laptop, so I bought this adapter from StarTech, with the following pinout diagram:
Next, I used PySerial to try and communicate with the instrument. That's when things started to become difficult for me. The manual of the spectrophotometer gives the details of the serial transmission parameters:
The manual also describes an example protocol (although the code is in BASIC) to change the instrument wavelength:
In this protocol:
- ENQ is 05 in hexadecimal
- ACK is 06 in hexadecimal
- EOT is 04 in hexadecimal
- NUL is 00 in hexadecimal
- w, 6, and 0 are interpreted as ascii caracters (for example 'w' is 77 in hexadecimal
In Python, I have a short program that opens the serial communications:
import serial
device = serial.Serial(port='COM4', baudrate=9600, bytesize=serial.SEVENBITS, parity=serial.PARITY_ODD, stopbits=serial.STOPBITS_ONE, timeout=.1)
Then, I use this line to send the ENQ signal:
device.write(b'\x05')
Now here comes the trouble. If I try to read the ACK byte with:
device.read()
It returns an empty byte:
b''
If I try to send the rest of the command it won't work. If I send the ENQ, and straight after send the command:
device.write(b'\x77\x36\x30\x30\x30\x00')
I hear the device moving the slit to the new position, but the screen of the instrument isn't updated until I send an ACK signal. Also, I cannot send another command until I send that same ACK signal.
My main problem is that I can't output the instrument data.
I want to focus on this small example to make sure everything is right first.
The BASIC program described in the manual is as follows:
100 'UV-1601 PC Control Program
110 DIMBUF$(32)
120 ENQ $ =CHR $ (&H5) : EOT $ =CHR $ (&H4) : ESC $ =CHR $ (&H1B)
130 NUL $ =CHR $ (&H0) : ACK $ =CHR $ (&H6) : NAK $ =CHR $ (&H15)
140 '
150 ' GO TO A
160 OPEN "COM1: 071NN" AS#1
170 FOR 1=0 TO 99: NEXT
180 PRINT #1,ENQ $;
190 IF INPUT $ (1,#1)< >ACK $ THEN 170
200 FOR 1=0 TO 99: NEXT
210 PRINT #l,"w6000" +NUL$;
220 IF INPUT $ (1, #1)< >ACK $ THEN BEEP : PRINT #1, ESC $;: GOTO 250
230 IF INPUTS (1, #1)< >EOT$ THEN BEEP: PRINT#1, ESC $;: GOTO 250
240 PRINT #1, ACK $; -o
250 CLOSE #1 O
260 END
Does anyone know why I can't seem to read the bytes from the instrument? Is it because of my RS-232C to USB C adapter, or is it related to PySerial?
EDIT: this is the cable I ended up making (this is the same wiring as suggested by @jonathanjo but with a female connector on the left-hand side to the USB adaptor and male connector on the right-hand side to the instrument)
With this cable, I could read the data from the spectro, but oddly enough, changing the wavelength still doesn't work as expected, but I guess I will live with that problem.
For those interested, this is a repository where I store my Python code for this instrument.
Thank you all :)