

You can still call out to Python if you have existing code there that builds the message to be sent or interprets the response, just keep the actual comms in LV.

This is what I'd probably do, and the easiest way is probably a ' functional global' style VI using an uninitialised shift register to maintain internal state and an enum input to select the operation to be performed e.g. rewrite all the serial port code in LabVIEW, so all the persistent data stays in LabVIEW.Maybe this can be done by digging into to the lower levels of VISA.įrom your description it sounds as though the overall control of your process or experiment is going to be in LabVIEW? In that case I think your options are: I also don't know any meaningful way in which you can pass a LabVIEW serial 'object' to Python and use it in Python. But I'm pretty sure that won't persist the state of a serial port object on the Python side. To pass an arbitrary Python object to LabVIEW and back I guess you should be able to use pickle.dumps to turn the object into a bytes stream which you can pass across and pickle.loads to go back the other way. Ultimately, my question is how do I pass serial objects between the two languages while maintaining the object's integrity without reinitializing a connection every time? Thanks in advance! I hope this all makes sense, I'm not great at explaining. Note, the above functions are just examples, I have more convoluted scripts I need to perform and it would be easier just to call them from LabVIEW rather than rewrite them so Python is not called at all.

I know there is a serial connection example VI in LabVIEW and maybe I can use this sample VI to create the object and pass it into Python, but I'm not sure how to do the passing. Xonxoff=False, rtscts=False, dsrdtr=False)Īnd here is an example of a function I would like to call later in LabVIEW, but requires the object to be initialized: def set_LED_RGB_currents(ser, currents=): Stopbits=serial.STOPBITS_ONE, timeout=10, Here is the snippet of code I am using to initialize the object: ser = serial.Serial(port=port, baudrate=115200, Clearly, it does not work because the python object is being casted to array. Here is the sort of block diagram I'm testing with. move stages around, control a camera, etc.). I do not want to keep the python session open in LabVIEW either as I need to run other scripts unassociated with this python object (i.e. The issue is I would like to use LabVIEW instead to call this Python initialization script, create the serial object, and store it (in the LabVIEW session) so it can be used later in LabVIEW without having to reinitialize the object. I currently have a script in Python (v3.6) that initializes a connection to a serial port and creates a serial object that can be called whenever I need to reset the buffer, read a register address, etc.
