# System.serial.write command data type confusion

**URL:** <https://forum.inductiveautomation.com/t/system-serial-write-command-data-type-confusion/55266>\
**Category:** Ignition\
**Created:** [January 21, 2022, 7:35pm UTC](https://forum.inductiveautomation.com/t/system-serial-write-command-data-type-confusion/55266 "2022-01-21T19:35:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dane\_Piper](https://avatars.discourse-cdn.com/v4/letter/d/b487fb/32.png) [@Dane\_Piper](https://forum.inductiveautomation.com/u/Dane_Piper)\
**Post date:** [January 21, 2022, 7:35pm UTC](https://forum.inductiveautomation.com/t/system-serial-write-command-data-type-confusion/55266/1 "2022-01-21T19:35:05Z")

</div>

I am trying to communicate with a device using the system.serial.write and the system.serial.writeBytes commands. I want to send it Modbus RTU commands so that I can retrieve certain registers for testing. I need to send it hexadecimal numbers in a sequence in order for it to respond. I can successfully send a command through the writeBytes function but I’m unable to send a number over 128 because that number is no longer represented by 1 byte. I try to use the system.serial.write command but I can’t get a response from the device. I am sending the same data for the system.serial.write command but I’m representing the hexadecimal command as a string instead of a byte array. I’m just not sure how the system.serial.write command sends data to the device and why I’m not getting a response back.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 21, 2022, 7:43pm UTC](https://forum.inductiveautomation.com/t/system-serial-write-command-data-type-confusion/55266/2 "2022-01-21T19:43:20Z")

</div>

A few things:

- Bytes in java are signed two’s complement. Subtract 256 from byte values over 127 to get the valid byte for a java byte array.

- Is there any particular reason you aren’t using Ignition’s Modbus driver’s RTU support?

- If the reason is a function code not supported by Ignition’s driver, consider using my [Advanced Modbus driver](https://inductiveautomation.com/moduleshowcase/module/automation-professionals-llc-advanced-modbus). In addition to more built-in supported function codes, it also exposes a gateway scripting function for exchanging messages with arbitrary functions and payloads. [/shameless plug]

---

<div class="post-metadata">

**Author:** ![Dane\_Piper](https://avatars.discourse-cdn.com/v4/letter/d/b487fb/32.png) [@Dane\_Piper](https://forum.inductiveautomation.com/u/Dane_Piper)\
**Post date:** [January 21, 2022, 8:07pm UTC](https://forum.inductiveautomation.com/t/system-serial-write-command-data-type-confusion/55266/3 "2022-01-21T20:07:30Z")

</div>

The reason I’m not using the Modbus driver is because I am only connecting to the device locally. I don’t want the device added to the gateway but am instead communicating locally through the vision client.

---

<div class="post-metadata">

**Author:** ![pridesleap](https://avatars.discourse-cdn.com/v4/letter/p/f4b2a3/32.png) [@pridesleap](https://forum.inductiveautomation.com/u/pridesleap)\
**Post date:** [January 21, 2022, 8:17pm UTC](https://forum.inductiveautomation.com/t/system-serial-write-command-data-type-confusion/55266/4 "2022-01-21T20:17:40Z")

</div>

Hmm, this sounds like a project I have down the road.

I will need to connect Ignition to a CNC machine using a serial connection. My interface will be by writing and reading text strings and GCode comands to and from a vision client. I was wondering if this was even possible. Hope you don’t mind but I’m curious to see how this turns out.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 21, 2022, 8:22pm UTC](https://forum.inductiveautomation.com/t/system-serial-write-command-data-type-confusion/55266/5 "2022-01-21T20:22:00Z")

</div>

Oy. Not fun. I’d use an ethernet-to-serial device there to avoid that pain.

---

<div class="post-metadata">

**Author:** ![Dane\_Piper](https://avatars.discourse-cdn.com/v4/letter/d/b487fb/32.png) [@Dane\_Piper](https://forum.inductiveautomation.com/u/Dane_Piper)\
**Post date:** [February 14, 2022, 3:01pm UTC](https://forum.inductiveautomation.com/t/system-serial-write-command-data-type-confusion/55266/6 "2022-02-14T15:01:37Z")

</div>

Just an update. So I used the Ignition serial module and started to use the serial.write command. I needed to send the bytes in python unicode in order for my device to properly read the data. I learned that the serial.write command would send each character as a separate byte but I was using hex so I needed to use unicode. It was pretty complicated but it worked.
