Skip to content

Commit

Permalink
release v1.0 (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
drunsinn authored Jan 15, 2023
1 parent eb37a53 commit 8eb6078
Show file tree
Hide file tree
Showing 37 changed files with 3,848 additions and 2,105 deletions.
5 changes: 5 additions & 0 deletions .codespellrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[codespell]
skip = *.po,*.ts,./docs/_build,./docs/_static,./.git
count =
quiet-level = 3
ignore-words-list = spindel
78 changes: 4 additions & 74 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -60,85 +60,14 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use "--disable=all --enable=classes
# --disable=W".
disable=print-statement,
parameter-unpacking,
unpacking-in-except,
old-raise-syntax,
backtick,
long-suffix,
old-ne-operator,
old-octal-literal,
import-star-module-level,
non-ascii-bytes-literal,
raw-checker-failed,
disable=raw-checker-failed,
bad-inline-option,
locally-disabled,
file-ignored,
suppressed-message,
useless-suppression,
deprecated-pragma,
use-symbolic-message-instead,
apply-builtin,
basestring-builtin,
buffer-builtin,
cmp-builtin,
coerce-builtin,
execfile-builtin,
file-builtin,
long-builtin,
raw_input-builtin,
reduce-builtin,
standarderror-builtin,
unicode-builtin,
xrange-builtin,
coerce-method,
delslice-method,
getslice-method,
setslice-method,
no-absolute-import,
old-division,
dict-iter-method,
dict-view-method,
next-method-called,
metaclass-assignment,
indexing-exception,
raising-string,
reload-builtin,
oct-method,
hex-method,
nonzero-method,
cmp-method,
input-builtin,
round-builtin,
intern-builtin,
unichr-builtin,
map-builtin-not-iterating,
zip-builtin-not-iterating,
range-builtin-not-iterating,
filter-builtin-not-iterating,
using-cmp-argument,
eq-without-hash,
div-method,
idiv-method,
rdiv-method,
exception-message-attribute,
invalid-str-codec,
sys-max-int,
bad-python3-import,
deprecated-string-function,
deprecated-str-translate-call,
deprecated-itertools-function,
deprecated-types-field,
next-method-defined,
dict-items-not-iterating,
dict-keys-not-iterating,
dict-values-not-iterating,
deprecated-operator-function,
deprecated-urllib-function,
xreadlines-attribute,
deprecated-sys-function,
exception-escape,
comprehension-escape,
consider-using-f-string

# Enable the message, report, category or checker with the given id(s). You can
Expand Down Expand Up @@ -251,7 +180,8 @@ good-names=i,
k,
ex,
Run,
_
_,
pyLSV2

# Good variable names regexes, separated by a comma. If names match any regex,
# they will always be accepted
Expand Down Expand Up @@ -318,7 +248,7 @@ indent-after-paren=4
indent-string=' '

# Maximum number of characters on a single line.
max-line-length=100
max-line-length=120

# Maximum number of lines in a module.
max-module-lines=1000
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 - 2022 drunsinn
Copyright (c) 2020 - 2023 drunsinn

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
203 changes: 112 additions & 91 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
as collect information about said files. Over time more and more functions where added which
support gathering information from the control.

Most of this library is based on the work of tfischer73 and his Eclipse plugin found at [his GitHub page](https://github.com/tfischer73/Eclipse-Plugin-Heidenhain). Since there is no free documentation beside the plugin, some parts are based purely on reverse engineering and might therefore be not correct.
Most of this library is based on the work of tfischer73 and his Eclipse plugin found at [his GitHub page](https://github.com/tfischer73/Eclipse-Plugin-Heidenhain). Since there is no free documentation beside the plugin, some parts are based purely on reverse engineering and might therefore be not correct.

As long as no encrypted communication is necessary, no additional librarys are necessary.
As long as no encrypted communication is necessary and you are using Python 3.5 or newer, no additional librarys are necessary.

Please consider the dangers of using this library on a production machine! This library is by no means complete and could damage the control or cause injuries! Everything beyond simple file manipulation is blocked by a lockout parameter. Use at your own risk!

Expand Down Expand Up @@ -40,105 +40,70 @@
SOFTWARE.

## News and Releases
check [the github release page](https://github.com/drunsinn/pyLSV2/releases) for information on the latest updates
check [the github release page](https://github.com/drunsinn/pyLSV2/releases) for information on the latest updates

## Contributors
In chronological order:
- tfischer73
- drunsinn
- WouterElfrink
- kekec14
- Michal Navrátil
- PandaRoux8
- sazima
- manusolve
- NeeXoo
- Baptou88

## Compatibility
Since there are a lot of different software versions and machine configurations out there
it is hard to say if this library is compatible with all of them. Most testing has been done
on programming stations but also with real hardware. Here is a list of versions that have
been tested:

### Programming Stations
| Control | Software |
|-------------|----------------|
| TNC640 | 340595 08 SP1 |
| TNC640 | 340595 10 SP2 |
| TNC640 | 340595 11 SP1 |
| TNC640 | 340595 11 SP4 |
| iTNC530 | 606425 04 SP20 |
| iTNC530 | 340494 08 SP2 |
| CNCpilot640 | 1230521 03 SP1 |

### Machines
| Control | Software |
|-------------|----------------|
| TNC620 | 817605 04 SP1 |
| TNC640 | 340595 08 SP1 |
| iTNC530 | 340480 14 SP4 |
| iTNC530 | 606420 02 SP14 |
| iTNC530 | 606420 02 SP3 |

If you have tested it on one of your machines with a different software version, please let us know!

Take a look at [protocol.rst](https://github.com/drunsinn/pyLSV2/blob/master/docs/package.rst) for a more in depth explanation on the detials of LSV2.
In chronological order:
- tfischer73
- drunsinn
- WouterElfrink
- kekec14
- Michal Navrátil
- PandaRoux8
- sazima
- manusolve
- NeeXoo
- Baptou88

## Usage
See [lsv2_demo.py](https://github.com/drunsinn/pyLSV2/blob/master/scripts/lsv2_demo.py) for a demonstration of some of the functions.

Notice that the definitionns of constant values will be moved from pyLSV2.LSV2 to pyLSV2 directly!

### Basic example
See [lsv2_demo.py](https://github.com/drunsinn/pyLSV2/blob/master/scripts/lsv2_demo.py) for a demonstration of some of the functions.

Since the whole protocol isn't documented there can always be problems with certain corner cases. Especially during file transfer a lot of stuff can go wrong.
In case the control doesn't accept a command it returns an error. Some of these errors are checked internally but not everything is covered as of now. It is therefore
best to check the last error with `con.last_error()`. Every error consists of type and a status code. The enum `LSV2StatusCode` contains all known status codes.

### Notes for upgrade to v1.xx
Notice: The change from 0.xx to 1.xx brought some major incompatible changes in regards to the API:
- raise the minimal required python version to 3.4 (for [IronPython 3.4](https://ironpython.net/)), future releases (1.1.x) will target 3.7 or higher!
- change of function names and parameters to better reflect their use
- change of return types from dict to data classes to reduce the dependency on magic strings
These changes where made intentionally to make further development easier. See the demo script for an overview of the new API.

#### exemplary overview of the changes from v0.x to v1.x
| Functionality | Version 0.x | Version 1.x |
|------------------------------|-------------------------------------------------------|---------------------------------------------------------|
| read nc software version | `con.get_versions()["NC_Version"]` | `con.versions.nc_sw` |
| check if control is a iTNC | `con.is_itnc()` | `con.version.is_itnc()` |
| get execution status via | `con.get_execution_status()` returns `int` value | `con.execution_status()` returns enum `ExecState` |
| read override values via | `con.get_override_info()` returns `dict` or `False` | `con.override_info()` returns `OverrideState` or `None` |
| read axes position via | `con.get_axes_location()` returns `dict` or `False` | `con.axes_location()` returns `dict` or `None` |
| move a file on the control | `con.move_local_file()` | `con.move_file()` |

### Basic example without context manager
```
import pyLSV2
con = pyLSV2.LSV2('192.168.56.101')
con = pyLSV2.LSV2("192.168.56.101")
con.connect()
print(con.get_versions())
print(con.versions.control)
con.disconnect()
```

### Reading Information from the control
### Basic example with context manager
```
import logging
import pyLSV2
logging.basicConfig(level=logging.DEBUG)
con = pyLSV2.LSV2('192.168.56.101', safe_mode=False)
con.connect()
print(con.get_program_status_text(con.get_program_status()))
print(con.get_execution_status_text(con.get_execution_status()))
print(con.get_axes_location())
con.disconnect()
```

### File transfer
```
import logging
import pyLSV2
logging.basicConfig(level=logging.DEBUG)
con = pyLSV2.LSV2('192.168.56.101', safe_mode=True)
con.connect()
con.send_file(local_path='./test.H', remote_path='TNC:/',
override_file=True, binary_mode=True)
con.recive_file(local_path='./', remote_path='TNC:/nc_prog/$mdi.h',
override_file=True, binary_mode=True)
con.disconnect()
with pyLSV2.LSV2("192.168.56.101") as con:
... con.connect()
... print(con.versions.control)
```

### Accessing PLC data
To read values from the PLC memory you need to know the memory area/type and the memory address. There are two ways to read these values.

#### Reading via memory address
The following command reads 15 marker (bits) starting at address
The following command reads 15 marker (bits) starting at address 32. This returns a list with 15 boolean values.

```
con.read_plc_memory(address=32, mem_type=pyLSV2.PLC_MEM_TYPE_MARKER, count=15)
con.read_plc_memory(32, pyLSV2.MemoryType.MARKER, 15)
```
See [lsv2_demo.py](https://github.com/drunsinn/pyLSV2/blob/master/scripts/lsv2_demo.py) for more examples.

Expand Down Expand Up @@ -169,23 +134,79 @@ Notice that the definitionns of constant values will be moved from pyLSV2.LSV2 t
See [lsv2_demo.py](https://github.com/drunsinn/pyLSV2/blob/master/scripts/lsv2_demo.py) for more examples.

### SSH Tunnel
Newer controls allow the use of ssh to encrypt the communication via LSV2. See scripts/ssh_tunnel_demo.py for an example on how to use the python library [sshtunnel](https://github.com/pahaz/sshtunnel) to achieve a secure connection.
Newer controls allow the use of ssh to encrypt the communication via LSV2.
See [ssh_tunnel_demo.py](https://github.com/drunsinn/pyLSV2/blob/master/scripts/ssh_tunnel_demo.py) for an example on
how to use the python library [sshtunnel](https://github.com/pahaz/sshtunnel) to achieve a secure connection.

## Compatibility
Since there are a lot of different software versions and machine configurations out there
it is hard to say if this library is compatible with all of them. Most testing has been done
on programming stations but also with real hardware. Here is a list of versions that have
been tested:

### Programming Stations
| Control | Software |
|-------------|----------------|
| TNC640 | 340595 08 SP1 |
| TNC640 | 340595 10 SP2 |
| TNC640 | 340595 11 SP1 |
| TNC640 | 340595 11 SP4 |
| iTNC530 | 606425 04 SP20 |
| iTNC530 | 340494 08 SP2 |
| CNCpilot640 | 1230521 03 SP1 |

### Machines
| Control | Software |
|-------------|----------------|
| TNC620 | 817605 04 SP1 |
| TNC640 | 340595 08 SP1 |
| iTNC530 | 340480 14 SP4 |
| iTNC530 | 606420 02 SP14 |
| iTNC530 | 606420 02 SP3 |

If you have tested it on one of your machines with a different software version, please let us know!

# Tables
Included in this library is also fuctionality to work with Tables used by different NC Controls. This includes for example TNC controls as well as Anilam 6000i CNC. As these controls and there software versions use different table formats, it is also possible to dreive the format form an existing table and export the format to a json file.
Included in this library is also functionality to work with Tables used by different NC Controls. This includes for example TNC controls as well as Anilam 6000i CNC. As these controls and there software versions use different table formats, it is also possible to dreive the format form an existing table and export the format to a json file.

See [table_reader_demo.py](https://github.com/drunsinn/pyLSV2/blob/master/scripts/table_reader_demo.py) for a demonstration on how to read a table and convert it to a different format.
See [tab2csv.py](https://github.com/drunsinn/pyLSV2/blob/master/scripts/tab2csv.py) for a demonstration on how to read a table and convert it to a csv file.

This script can also be used as a command line tool
```
usage: tab2csv.py [-h] [--decimal_char DECIMAL_CHAR] [-d | -v] source
command line script parsing table files
positional arguments:
source table file to parse
options:
-h, --help show this help message and exit
--decimal_char DECIMAL_CHAR
override local decimal char
-d, --debug enable log level DEBUG
-v, --verbose enable log level INFO
```

# Testing
To run the test you either need a machine or a programming station. The controls has to be on and the
PLC program has to be running. You can add the IP-Address and timeout as a parameter
To run the test you either need a machine or a programming station. The control has to be on and the
PLC program has to be running. The IP address and timeout are set via command line parameters.
```
pytest --address=192.168.56.103 --timeout=5
```

# Resources
https://www.inventcom.net/support/heidenhain/read-tnc-plc-data

https://www.inventcom.net/s1/_pdf/Heidenhain_TNC_Machine_Data.pdf
# Minimum required Python version
The minimum required python version was checked with [vermin](https://github.com/netromdk/vermin).
```
vermin --no-parse-comments .
```
The results indicate that pyLSV2 should work with python 3.5 and even with 3.4 if you install
the packported modules argparse, enum and typing. While argpares is only used in the demo script
the other two are necessary. Therefore it should be possible to use pyLSV2 with the curretn version
of [IronPython](https://ironpython.net/) if you install these two modules.

https://de.industryarena.com/heidenhain/forum
# Resources
- [protocol.rst](https://github.com/drunsinn/pyLSV2/blob/master/docs/package.rst)
- https://www.inventcom.net/support/heidenhain/read-tnc-plc-data
- https://www.inventcom.net/s1/_pdf/Heidenhain_TNC_Machine_Data.pdf
- https://www.yumpu.com/en/document/read/18882603/-f-heidenhain
Loading

0 comments on commit 8eb6078

Please sign in to comment.