Posts: 2 Threads: 1 Joined: Jan 2021 Jan-14-2021, 05:15 PM (This post was last modified: Jan-14-2021, 05:58 PM by buran.) 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. Posts: 12,117 Threads: 494 Joined: Sep 2016 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) Posts: 2,171 Threads: 12 Joined: May 2017 Jan-15-2021, 03:29 PM (This post was last modified: Jan-15-2021, 03:29 PM by DeaD_EyE.) 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 Posts: 2 Threads: 1 Joined: Jan 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...characters Unfortunatly no |