Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python for Omron-Fins
#1
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?
buran write Jan-14-2021, 05:56 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply
#2
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)
Reply
#3
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...characters
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#4
(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...characters

Unfortunatly no
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020