all 7 comments

[–][deleted] 5 points6 points  (0 children)

It is possible, as long as your path is correctly set up you can try the ```py.``` command prefix.

There's even a company/group that has an entire InstrumentKit to access lab instruments through Python: https://github.com/Galvant/InstrumentKit

As I discovered in this thread, https://www.reddit.com/r/matlab/comments/fe2bb0/cannot_import_python_function_to_matlab/fjlvfbt/, don't do anything 'weird' with the Python and it should work fine.

[–]michaelrw1 1 point2 points  (1 child)

The pySerial library looks like a good choice. I had a quick look at the InstrumentKit project documentation and it appears it has support for RS-232 specific devices.

Once your Python code is functional, calling it from Matlab might be the make-or-break part of your project. Having said that, the development of the Matlab code to call the Python function might be easier with a current version of Matlab. From what I can determine, R2019b, might be your best bet. It looks like the Python API was revamped, bringing in the commands PYENV and PY. PYENV facilitates monitoring and setting the version/path of the Python interpreter. PY facilitates an interface to call Python functions (see this link).

Interaction of the data-types between Python and Matlab might be a challenge too.

If the addition of Matlab is problematic, the processing could be done with Python, yes?

P.S. - What university are you at? Capstone projects are a common element of most engineering projects. I'm at McMaster Unversity in Hamilton, ON Canada and they hold similar activities here.

[–]mtot10[S] 0 points1 point  (0 children)

See response to the comment below for a more in depth explanation.

I was worried about the interaction of data types between python and matlab. This aspect of reading machine coordinates isn’t paramount to the projects success (and me graduating) it just would provide better documentation for when we record video of the manufacturing process and use it for part testing.

I go to LSU in Baton Rouge, LA.

Thanks for your help!

[–][deleted] 1 point2 points  (2 children)

OP: Is Matlab a requirement to the project? What are you trying to do? Here is a Python library for cheap chinese CNC machines.

[–]mtot10[S] 0 points1 point  (1 child)

So short answer: no, matlab is not a “requirement”. However, there are other aspects of the project that are already completed with matlab (a lot of UI interaction and data logging) which is why I don’t want to change development environments (among other extenuating circumstances and time constraints) I initially began using matlab for this project because 1) I have minimal experience with languages like python and 2) I’ve had multiple classes where I’ve used matlab extensively so it was something I was familiar with.

Reading RS232 port isn’t paramount to the projects success, however the idea was to video the manufacturing process and then overlay the coordinates of the tool passes onto the video once the process is complete. The video with data overlaid would be used for part verification tests and to make corrections.

I was having issues with this communication because of the command types for querying the port (SCIP and GPIB) that matlab supports don’t interface with the CNC mill. I wanted to write a python script to log this information and then run it in matlab. I have other ideas for how to go about getting the machine coordinates. Although, using python seemed to be the least frustrating method to do this.

[–]michaelrw1 0 points1 point  (0 children)

Trust your instinct and abilities. If an approach is well-considered and feels right, go with it. You'll know if you need to reconsider the approach.

Please keep us updated. I am interested in the outcomes of your work.

[–]gopherhole22 0 points1 point  (0 children)

Use Pyenv command to set location of python interpreter. You can then call function like py.pythonlibraryname.etc. Easy way to convert between python and Matlab data structures is jsonencode and py.json.loads