- Posts: 59
- Thank you received: 0
Access Modbus pins directly with Python - doable?
ArcEye wrote:
How would I go about connecting the pins using Python? That would solve at least some of the problem.
Did you read the links I posted in your other thread?
From src/hal/halmodule.cc
Code:PyObject *connect(PyObject *self, PyObject *args) { char *signame,*pinname; if(!PyArg_ParseTuple(args, "ss", &pinname,&signame)) return NULL; if(!SHMPTR(0)) { PyErr_Format(PyExc_RuntimeError, "Cannot call before creating component"); return NULL; } //printf("INFO HALMODULE -- link sig %s to pin %s\n",signame,pinname); return PyBool_FromLong(hal_link(pinname, signame) != 0); }
and many other functions which echo the C access functions, which are what halcmd and the other parts of HAL call.
Unless you let people see what you are doing, ie attach your files, this is a rather pointless exercise.
We are just trying to guess what you are doing.
I appreciate that you are willing to spend your time trying to help and I understand it is frustrating when a person is unable to precisely describe a problem using the proper terminology. Usually the shoe is on the other foot, but for now, I am the newbee. We all have our turn in the barrel.
Certainly I saw your posting of source code, but it never occurred to me that this was considered documentation. I don't think it would be a stretch to say Linux/LinuxCNC is pretty geeky stuff, but source code as a manual is a bit over the top. :laugh:
Not a problem, I'll get used to it. Thanks for the education and I will view source code as a 'manual' of sorts fro here on.
Sorry to frustrate you and thanks for taking time to be frustrated over my problem.
Please Log in to join the conversation.
Simpson36 wrote: For example, can the pin access that BASH has be added to the Python 'linuxcnc' library? What would be needed to make that happen? If that is doable, then count me in. I'll contribute in whatever way I can.
Meanwhile, if anyone has a suggestion on how to get h.ready() to work in the Python component library, please share. THANKS!
So the linuxcnc module in python is for access to linuxcnc (the motion controller)
The hal module in python is for building components in python it allows access to halcmd (which is what you are using in BASH)
We do not want to intermix them.
The hal module is a subset of halcmd (plus a few other things added in)
It was discussed/attempted a long time ago to add the rest of halcmd to the python module.
I forget the exact reason why it failed, but it might be because all of halcmd had to be basically duplicated - a lot of work.
having a python binding to halcmd all on its own would be interesting - it should allow writing HAL scripts in python allowing
all of pythons programing syntactics. I believe machinekit has done this. We have something similar written in TCL
Chris M
Please Log in to join the conversation.
The solution to LinuxCNC hanging on startup is on line 8 and also below in red. Specifying the component name seems to have made it recognizable to the script, otherwise it was continuously waiting for it to go 'ready' even though it already was.
The offsets and scales are workarounds to deal with s32 and float data types on 16 bit Modbus registers. Joystick values are +50 to -50 so I had to add 50 at the device, xfer over Modbus and subtract (offset) 50 at LinuxCNC to get the negative number back.
Scale is used as a 'down and dirty' way to get an actual float across Modbus. If more than 3 decimal places of accuracy are required, you have to use a more complicated method and use (at least) a pair of 16 bit Modbus registers, but that's a whole other topic..
Hopefully useful to someone.
loadusr -Wninturncel -i /home/sfs/linuxcnc/nc_files/inturncel.py
Please Log in to join the conversation.
cmorley wrote:
Simpson36 wrote: For example, can the pin access that BASH has be added to the Python 'linuxcnc' library? What would be needed to make that happen? If that is doable, then count me in. I'll contribute in whatever way I can.
Meanwhile, if anyone has a suggestion on how to get h.ready() to work in the Python component library, please share. THANKS!
So the linuxcnc module in python is for access to linuxcnc (the motion controller)
The hal module in python is for building components in python it allows access to halcmd (which is what you are using in BASH)
We do not want to intermix them.
The hal module is a subset of halcmd (plus a few other things added in)
It was discussed/attempted a long time ago to add the rest of halcmd to the python module.
I forget the exact reason why it failed, but it might be because all of halcmd had to be basically duplicated - a lot of work.
having a python binding to halcmd all on its own would be interesting - it should allow writing HAL scripts in python allowing
all of pythons programing syntactics. I believe machinekit has done this. We have something similar written in TCL
Chris M
Chris,
I have to wonder whether there is some 'frog in the water' syndrome in the 'old guard'. Now, I'm old myself (62), BUT I have a fresh perspective on LinuxCNC with no pre-conceived notions (other than it is geeky). Maybe the contorted way of doing things has just been around so long it seems 'normal' to people who have been doing it for years.
To me, it just seems like . . REALLY? . . anyway, no disrespect intended to anyone, it just was unexpected. I'm old enough to remember programming when you spent a LOT of time compacting code and data because memory was small and uber expensive. I don't see any justification with modern computers to have a bunch of separate modules. How big would the whole thing be if it was combined, or major parts of it combined.
I just got a bunch of new info to dig thru, including 'source code manuals' and as implied elsewhere, it may be that a lot of this stuff has been accomplished, but just not documented yet. In any case, these are just my 'first impressions', FWIW, which together with 5 bucks will get you coffee at Starbucks. :blush:
One question, please; who or what is machinekit?
Please Log in to join the conversation.
- Todd Zuercher
- Offline
- Platinum Member
-
- Posts: 4739
- Thank you received: 2
Simpson36 wrote: One question, please; who or what is machinekit?
Short answer, it is a fork of Linuxcnc.
Please Log in to join the conversation.
