Python Forum
Python for Omron-Fins - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Python for Omron-Fins (/thread-32008.html)



Python for Omron-Fins - carlomatto - Jan-14-2021

Sorry for my bad english. I'm trying to read data from an omron-fins plc with a python scripts. I read something but that data are incomprehensible. I use this script

import fins.udp
import time


fins_instance = fins.udp.UDPFinsConnection()
fins_instance.connect('192.168.1.211')
#i don't know what i had to write in this fields
fins_instance.dest_node_add=211
#i don't know what i had to write in this fields
fins_instance.srce_node_add=30

mem_area = fins_instance.memory_area_read(fins.FinsPLCMemoryAreas().CIO_WORD,b'\x00\x51\x06')
print(mem_area)
that code give me this result :
Output:
b'\xc0\x00\x02\x00\x1e\x00\x00\xd3\x00`\x01\x01\x00\x00\x00\x00'
Someone know how can i read understandable integer values?


RE: Python for Omron-Fins - Larz60+ - Jan-14-2021

The output contains control characters, which control various uart functionality, the control characters don't readily convert to text.

But ...

the control character portion can be dropped once identified see: https://en.wikipedia.org/wiki/Control_character
for a list of control characters (not vouching for site, but it seems to contain most common control character list)


RE: Python for Omron-Fins - DeaD_EyE - Jan-15-2021

The package you use, is overcomplicated.

In PLC-World a Word is 16 bit long. The values you get back is binary data, which is 16 bytes long.
I don't know why you get more data back, as requested.


You can try to parse the data with the struct module.
The controller should use Big-Endian as byte order.

import struct


mem_area = b'\xc0\x00\x02\x00\x1e\x00\x00\xd3\x00`\x01\x01\x00\x00\x00\x00'

print(struct.unpack("!8h", mem_area)) # 8 x signed short   (2 bytes, 16 bit)
print(struct.unpack("!8H", mem_area)) # 8 x unsigned short (2 bytes, 16 bit)

print(struct.unpack("!4i", mem_area)) # 4 x signed short   (4 bytes, 32 bit)
print(struct.unpack("!4I", mem_area)) # 4 x unsigned short (4 bytes, 32 bit)

print(struct.unpack("!8e", mem_area)) # float (2 bytes, 16 bit)
print(struct.unpack("!4f", mem_area)) # float (4 bytes, 32 bit)
print(struct.unpack("!2d", mem_area)) # float (8 bytes, 64 bit)
The output:
Output:
(-16384, 512, 7680, 211, 96, 257, 0, 0) (49152, 512, 7680, 211, 96, 257, 0, 0) (-1073741312, 503316691, 6291713, 0) (3221225984, 503316691, 6291713, 0) (-2.0, 3.0517578125e-05, 0.005859375, 1.2576580047607422e-05, 5.7220458984375e-06, 1.531839370727539e-05, 0.0, 0.0) (-2.0001220703125, 6.776434022477028e-21, 8.816567764872488e-39, 0.0) (-2.0009767860175116, 7.121981476561534e-307)
Do some of these values make sense?


The format specification: https://docs.python.org/3/library/struct.html#format-characters


RE: Python for Omron-Fins - carlomatto - Jan-18-2021

(Jan-15-2021, 03:29 PM)DeaD_EyE Wrote: The package you use, is overcomplicated.

In PLC-World a Word is 16 bit long. The values you get back is binary data, which is 16 bytes long.
I don't know why you get more data back, as requested.


You can try to parse the data with the struct module.
The controller should use Big-Endian as byte order.

import struct


mem_area = b'\xc0\x00\x02\x00\x1e\x00\x00\xd3\x00`\x01\x01\x00\x00\x00\x00'

print(struct.unpack("!8h", mem_area)) # 8 x signed short   (2 bytes, 16 bit)
print(struct.unpack("!8H", mem_area)) # 8 x unsigned short (2 bytes, 16 bit)

print(struct.unpack("!4i", mem_area)) # 4 x signed short   (4 bytes, 32 bit)
print(struct.unpack("!4I", mem_area)) # 4 x unsigned short (4 bytes, 32 bit)

print(struct.unpack("!8e", mem_area)) # float (2 bytes, 16 bit)
print(struct.unpack("!4f", mem_area)) # float (4 bytes, 32 bit)
print(struct.unpack("!2d", mem_area)) # float (8 bytes, 64 bit)
The output:
Output:
(-16384, 512, 7680, 211, 96, 257, 0, 0) (49152, 512, 7680, 211, 96, 257, 0, 0) (-1073741312, 503316691, 6291713, 0) (3221225984, 503316691, 6291713, 0) (-2.0, 3.0517578125e-05, 0.005859375, 1.2576580047607422e-05, 5.7220458984375e-06, 1.531839370727539e-05, 0.0, 0.0) (-2.0001220703125, 6.776434022477028e-21, 8.816567764872488e-39, 0.0) (-2.0009767860175116, 7.121981476561534e-307)
Do some of these values make sense?


The format specification: https://docs.python.org/3/library/struct.html#format-characters

Unfortunatly no