sockets - IndexError when applying setblocking(0) for a Blender3D Python script -


I am currently running a script with Blender 3D which I have placed in Python 3+ from Python 2+ ,. The script creates communication between the Omron PLC (programmable logic computer) and Blender / Python 3+. The script uses TCP communication to write and read memory of PLC. After the port the script runs properly in Blender, it is only a big problem and forces Blender to run at 6 fps.

Python sockets are blocked by default. This means that when you call socket.read () , the function will not return until your data is being read or there is an error on the socket. I.e. socket "block" execution until the operation is completed. Because your code is blocked in the code recv () , your game gets freezed. This link states that if you add setblocking (0) or setblocking (false) or Settimesout (0) (all the same), you will cancel the delay due to TCP communication.

To work on it, except to avoid a socket error, Tried to wrap your recv () call: BlockingIOR: [WinError 10035] A non-blocking socket operation can not be completed immediately .

I've done it like this:

  def _recieve (self): try: public relations = self.sock.recv (8) length = binstrat (pr [4: 8] ) R = PR + L. SOC RCV (Length) # Print ('RECV:' + RepR (R)) Returns except the socket .error as error: # Any error, but to "block" the socket to close The reason for this should be: err.errno! = Errno.EWOULDBLOCK: self.sock.close () self.sock = no return   

although it did not solve my problem, it Make more trouble These scripts will work fine but when I block on 6 fps (1) But when I turn it on, I have an index head:

File "D: \. .. ", line 126, in assembly [BICF] = Binstrit (self. Strap-frame [16]) Index error: '

outside the index range is where the error occurs, if I comment on the line then it just says that the next Self.rawTcpFrame [17] For example:

  DEF DISCOMMODAL (SW): ASM = {B "Header": BINSTROINT (Self Stuff Frame [0: 4]) , B 'length': BinContount (self strfframe [4: 8]), b 'command': binstrat (self strfframe [8:12]), Bork : (Asm [b'command '] == 2): asm [b'ICF'] = binstr2int (self stripframe [16]) asm [b] RSV '] = binstr2int (self.rawTcpFrame [17]) asm [B'GCT'] = Binstrat (self strfframe [18]) asm [b'DNA] = binstr2int (self strfframe [19]) asm [b] 'DA1'] = binstr2int (self strfframe [20]) asm [b'DA2 '] = binstr2int (self.rawTcpFrame [21]) asm [b'SNA'] = binstr2int (self.rawTcpFrame [22]) asm [ B'SA1 '] = b Instr2int (self.rawTcpFrame [23]) asm [b'SA2'] = binstr2int (self.rawTcpFrame [24]) asm [b'SID '] = binstr2int (self.rawTcpFrame [25]) ASM [BMCR '] = Binstr2int (self.rawTcpFrame [26]) asm [b'SRC'] = binstr2int (self.rawTcpFrame [27]) if self.fromRaw: Reply #decode asm [b'MRES '] = binstr2int (self.rawTcpFrame [28]) ASM [BERSES] = Binestrate (self. Strapframe [29]) ASM [B'prochen] = self. Strawfreck [30:] Second: ASM [B'CMD '] = Self. Stroffframe [28   

Your message is not long (less than sequence 17 is). You should test the length of the frame, or use the zip and take a piece to ensure that, you do not try to call the index that does not exist:

  tags = (b 'ICF', 'BRSV', 'BGCT', 'DNA' ',' B1 '', 'B' 2 ',' B 'SNA, BSA1' ' BESA 2 ', B'SID', B 'MRC', B'SRC), for the tag, data in the zip (tag, self-stripframe [16:]): ASM [tag] = Binstrate T (Data)   

Or you can wrap everything in the : ... except index references: and handle very small frames.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -