# Writing bytes through TCP socket problems above 7F

**URL:** <https://forum.inductiveautomation.com/t/writing-bytes-through-tcp-socket-problems-above-7f/11864>\
**Category:** Ignition\
**Created:** [June 27, 2016, 12:22pm UTC](https://forum.inductiveautomation.com/t/writing-bytes-through-tcp-socket-problems-above-7f/11864 "2016-06-27T12:22:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Taylor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/chris_taylor/32/3315_2.png) [@Chris\_Taylor](https://forum.inductiveautomation.com/u/Chris_Taylor)\
**Post date:** [June 27, 2016, 12:22pm UTC](https://forum.inductiveautomation.com/t/writing-bytes-through-tcp-socket-problems-above-7f/11864/1 "2016-06-27T12:22:57Z")

</div>

Morning

I have the following code running in the script console as a rough test, it is a Modbus broadcast using function 16 and it works OK except any values above INT127 or HEX 7F causes a failure, I really need to be-able to write up to 255 or FF.  
its easiest to change the “data” bytes and it needs an open port on the slave

```auto
import socket
import struct
#write Modbus Function 16
# Slave IP address
IP = "192.168.2.106"
#Slave Port No
PORT = 502
#Set UP Modbus headers (Four Byte)
Modbus = (0,1,0,0,)
# Length Total bytes after this (Two Bytes)
Length = (0,11,)
#Modbus Unit ID (one Byte)
unit = (0,)
#Modbus Function (one Byte)
Function = (16,)
# Modbus register start (Two Bytes)
Ref = (0,2,)
#total Word count (two Bytes)
WCount = (0,2,)
#Total byte Count (one Byte)
BCount = (4,)
#Data to write (See Byte Count)
data = (0,123,0,127)

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

MESSAGE = (Modbus+Length+unit+Function+Ref+WCount+BCount+data)

print MESSAGE
sock.connect((IP, PORT))

sock.send(MESSAGE)
sock.close()
```

What have I done wrong? its driving me silly.

---

<div class="post-metadata">

**Author:** ![Chris\_Taylor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/chris_taylor/32/3315_2.png) [@Chris\_Taylor](https://forum.inductiveautomation.com/u/Chris_Taylor)\
**Post date:** [June 27, 2016, 12:42pm UTC](https://forum.inductiveautomation.com/t/writing-bytes-through-tcp-socket-problems-above-7f/11864/2 "2016-06-27T12:42:34Z")

</div>

Signed byte?? What?  
Oh flip.  
how do I get around that?

```auto
if xx >127:
   xx = xx - 256
```

Looks good for now
