Hello all, I'm trying to communicate with a machine that uses serial (RS232), in a LabVIEW program. Here are some important points:
- I'm using a Serial/USB converter, since I don't have any RS232 ports on this PC (they often don't have them on laptops anymore!), and Windows (10) successfully found and installed the driver for the converter. It now shows up in Device Manager under Ports, as COM3.
- I am positive the hardware of the converter works. I have a python script (shown below) from a colleague which was used to communicate with the machine, fetching a value. If I run this script in Python, on this machine, with the converter and such, it fetches the correct value. So we know that that part is working.
- NI MAX sees the device as well, calling it ASRL3::INSTR "COM3".
Here it is in device manager:
![com3_devman.PNG com3_devman.PNG]()
Here it is in NI MAX:
![NIMAX_com3.PNG NIMAX_com3.PNG]()
Here's the python script:
import os
import sys
import glob
import operator
import serial
import time
from string import *
from time import strftime
# Initialize serial
sii=serial.Serial('COM3',1200,timeout=0.5)
print( "BEGIN")
sii.write(b"T\r")
time.sleep(1)
temp=sii.read(100).decode("utf-8")
sii.close()
print(temp)
print ("done")
I only include that to show an example of something that does work.
Here's the LabVIEW VI I'm trying to use (.vi attached):
![serialread_vi.PNG serialread_vi.PNG]()
(edit: I forgot to say, for the VISA resource name, I'm using ASRL3::INSTR.)
and it always gives me this error:
![NI_serialerror.PNG NI_serialerror.PNG]()
So here's the problem. I'll run the Python script, it will work, and then I'll go to LabVIEW, try my VI (attached, same as image above), it doesn't work, gives that error, and then if I go back to try the Python script again, it gives this error:
serial.serialutil.SerialException: could not open port 'COM3': PermissionError(13, 'Access is denied.', None, 5)
So clearly the Port COM3 is getting used, but not given up, by LabVIEW or something. I really don't know much about Ports at all though.
Similarly, I can sometimes access it in the NI MAX VISA test panel, but usually at this point, if I try, I get this error:
![visa_test_error.PNG visa_test_error.PNG]()
What can I try? Is there some way to "reset" a COM port? I've tried doing something I read, right clicking on the port in Device Manager, and disabling/enabling it, but it doesn't work (for example, after doing that, I get the same Python error). If I reboot, it works, but that's not a solution I can use.
Further, any idea why my LabVIEW VI wouldn't be working, when it appears I'm doing the same thing as the Python script? It appears to be sending "T\r" (T with a carriage return), which I'm doing in the VI. My one suspicion is that the script has that 'b' in front of it, making it a byte stream... I'm not really sure how to do this in LabVIEW. I know about the string to byte array VI, but that produces a byte array, and VISA write needs a string...
What can I do? This is driving me nuts. Thank you for any advice, it is much appreciated.