diff --git a/larpix/larpix.py b/larpix/larpix.py
index d4ae36b..a0efae8 100644
--- a/larpix/larpix.py
+++ b/larpix/larpix.py
@@ -1332,7 +1332,7 @@ class PacketCollection(object):
         d['message'] = str(self.message)
         d['read_id'] = 'None' if self.read_id is None else self.read_id
         d['bytestream'] = ('None' if self.bytestream is None else
-                self.bytestream.decode('utf-8'))
+                self.bytestream.decode('raw_unicode_escape'))
         return d
 
     def from_dict(self, d):
@@ -1342,7 +1342,7 @@ class PacketCollection(object):
         '''
         self.message = d['message']
         self.read_id = d['read_id']
-        self.bytestream = d['bytestream'].encode('utf-8')
+        self.bytestream = d['bytestream'].encode('raw_unicode_escape')
         self.parent = None
         self.packets = []
         for p in d['packets']:

Some bytestreams don't parse well to JSON in Python 2 (PacketCollection.to_dict)
``UnicodeDecodeError: 'utf8' codec can't decode byte 0xd8 in position 1: invalid continuation byte``. Indeed byte ``b"\xd8"`` is in position 1. I think I'll need to insert some Python version logic into the to_dict and from_dict methods.
diff --git a/test/test_larpix.py b/test/test_larpix.py
index af9e035..8c5165b 100644
--- a/test/test_larpix.py
+++ b/test/test_larpix.py
@@ -189,7 +189,7 @@ def test_controller_save_output(tmpdir):
                     'parent': 'None',
                     'message': 'hi',
                     'read_id': 0,
-                    'bytestream': p.bytes().decode('utf-8')
+                    'bytestream': p.bytes().decode('raw_unicode_escape')
                     }
                 ]
             }
@@ -1699,6 +1699,7 @@ def test_packetcollection_origin():
 
 def test_packetcollection_to_dict():
     packet = Packet()
+    packet.chipid = 246
     packet.packet_type = Packet.TEST_PACKET
     collection = PacketCollection([packet], bytestream=packet.bytes(),
             message='hello')
@@ -1708,11 +1709,11 @@ def test_packetcollection_to_dict():
             'parent': 'None',
             'message': 'hello',
             'read_id': 'None',
-            'bytestream': packet.bytes().decode('utf-8'),
+            'bytestream': packet.bytes().decode('raw_unicode_escape'),
             'packets': [{
                 'bits': packet.bits.bin,
                 'type': 'test',
-                'chipid': 0,
+                'chipid': packet.chipid,
                 'parity': 0,
                 'valid_parity': True,
                 'counter': 0

pip install -e .
parse_log_pytest
pyserial bitstring pytest
pytest
apt-get update apt-get install -y gcc
3.9
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
bitarray @ file:///home/conda/feedstock_root/build_artifacts/bitarray_1741686834964/work
bitstring @ file:///home/conda/feedstock_root/build_artifacts/bitstring_1742657504808/work
exceptiongroup @ file:///croot/exceptiongroup_1706031385326/work
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
-e git+https://github.com/samkohn/larpix-control.git@345deb77ced183828f951008ad804a06819ccd52#egg=larpix_control
packaging @ file:///croot/packaging_1734472117206/work
pluggy @ file:///croot/pluggy_1733169602837/work
pyserial @ file:///croot/pyserial_1736540546229/work
pytest @ file:///croot/pytest_1738938843180/work
tomli @ file:///opt/conda/conda-bld/tomli_1657175507142/work

name: larpix-control
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - bitarray=3.1.1=py39h8cd3c5a_0
  - bitstring=4.3.1=pyhd8ed1ab_0
  - ca-certificates=2025.2.25=h06a4308_0
  - exceptiongroup=1.2.0=py39h06a4308_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc=14.2.0=h767d61c_2
  - libgcc-ng=14.2.0=h69a702a_2
  - libgomp=14.2.0=h767d61c_2
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - packaging=24.2=py39h06a4308_0
  - pip=25.0=py39h06a4308_0
  - pluggy=1.5.0=py39h06a4308_0
  - pyserial=3.5=py39h06a4308_2
  - pytest=8.3.4=py39h06a4308_0
  - python=3.9.21=he870216_1
  - python_abi=3.9=2_cp39
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tomli=2.0.1=py39h06a4308_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
prefix: /opt/conda/envs/larpix-control

test/test_larpix.py::test_packetcollection_to_dict
test/test_larpix.py::test_configuration_set_pixel_trim_thresholds_errors test/test_larpix.py::test_configuration_set_global_threshold_errors test/test_larpix.py::test_configuration_set_csa_gain_errors test/test_larpix.py::test_configuration_set_csa_bypass_errors test/test_larpix.py::test_configuration_set_internal_bypass_errors test/test_larpix.py::test_configuration_set_csa_bypass_select_errors test/test_larpix.py::test_configuration_set_csa_monitor_select_errors test/test_larpix.py::test_configuration_set_csa_testpulse_enable_errors test/test_larpix.py::test_configuration_set_csa_testpulse_dac_amplitude_errors test/test_larpix.py::test_configuration_set_test_mode_errors test/test_larpix.py::test_configuration_set_cross_trigger_mode_errors test/test_larpix.py::test_configuration_set_periodic_reset_errors test/test_larpix.py::test_configuration_set_fifo_diagnostic_errors test/test_larpix.py::test_configuration_set_test_burst_length_errors test/test_larpix.py::test_configuration_set_adc_burst_length_errors test/test_larpix.py::test_configuration_set_channel_mask_errors test/test_larpix.py::test_configuration_set_external_trigger_mask_errors test/test_larpix.py::test_configuration_set_reset_cycles_errors test/test_larpix.py::test_configuration_write_errors test/test_larpix.py::test_controller_get_chip_error test/test_larpix.py::test_controller_format_UART test/test_larpix.py::test_controller_format_bytestream test/test_larpix.py::test_controller_write_configuration test/test_larpix.py::test_controller_write_configuration_one_reg test/test_larpix.py::test_controller_write_configuration_write_read test/test_larpix.py::test_controller_get_configuration_bytestreams test/test_larpix.py::test_controller_parse_input test/test_larpix.py::test_controller_parse_input_dropped_data_byte test/test_larpix.py::test_controller_parse_input_dropped_start_byte test/test_larpix.py::test_controller_parse_input_dropped_stop_byte test/test_larpix.py::test_controller_parse_input_dropped_stopstart_bytes
test/test_larpix.py::test_FakeSerialPort_write test/test_larpix.py::test_FakeSerialPort_read test/test_larpix.py::test_FakeSerialPort_read_multi test/test_larpix.py::test_chip_str test/test_larpix.py::test_chip_get_configuration_packets test/test_larpix.py::test_chip_sync_configuration test/test_larpix.py::test_chip_export_reads test/test_larpix.py::test_chip_export_reads_no_new_reads test/test_larpix.py::test_chip_export_reads_all test/test_larpix.py::test_controller_save_output test/test_larpix.py::test_controller_load test/test_larpix.py::test_packet_bits_bytes test/test_larpix.py::test_packet_init_default test/test_larpix.py::test_packet_init_bytestream test/test_larpix.py::test_packet_bytes_zeros test/test_larpix.py::test_packet_bytes_custom test/test_larpix.py::test_packet_bytes_properties test/test_larpix.py::test_packet_export_test test/test_larpix.py::test_packet_export_data test/test_larpix.py::test_packet_export_config_read test/test_larpix.py::test_packet_export_config_write test/test_larpix.py::test_packet_set_packet_type test/test_larpix.py::test_packet_get_packet_type test/test_larpix.py::test_packet_set_chipid test/test_larpix.py::test_packet_get_chipid test/test_larpix.py::test_packet_set_parity_bit_value test/test_larpix.py::test_packet_get_parity_bit_value test/test_larpix.py::test_packet_compute_parity test/test_larpix.py::test_packet_assign_parity test/test_larpix.py::test_packet_has_valid_parity test/test_larpix.py::test_packet_set_channel_id test/test_larpix.py::test_packet_get_channel_id test/test_larpix.py::test_packet_set_timestamp test/test_larpix.py::test_packet_get_timestamp test/test_larpix.py::test_packet_set_dataword test/test_larpix.py::test_packet_get_dataword test/test_larpix.py::test_packet_get_dataword_ADC_bug test/test_larpix.py::test_packet_set_fifo_half_flag test/test_larpix.py::test_packet_get_fifo_half_flag test/test_larpix.py::test_packet_set_fifo_full_flag test/test_larpix.py::test_packet_get_fifo_full_flag test/test_larpix.py::test_packet_set_register_address test/test_larpix.py::test_packet_get_register_address test/test_larpix.py::test_packet_set_register_data test/test_larpix.py::test_packet_get_register_data test/test_larpix.py::test_packet_set_test_counter test/test_larpix.py::test_packet_get_test_counter test/test_larpix.py::test_configuration_get_nondefault_registers test/test_larpix.py::test_configuration_get_nondefault_registers_array test/test_larpix.py::test_configuration_get_nondefault_registers_many_changes test/test_larpix.py::test_configuration_set_pixel_trim_thresholds test/test_larpix.py::test_configuration_get_pixel_trim_thresholds test/test_larpix.py::test_configuration_set_global_threshold test/test_larpix.py::test_configuration_get_global_threshold test/test_larpix.py::test_configuration_set_csa_gain test/test_larpix.py::test_configuration_get_csa_gain test/test_larpix.py::test_configuration_set_csa_bypass test/test_larpix.py::test_configuration_get_csa_bypass test/test_larpix.py::test_configuration_set_internal_bypass test/test_larpix.py::test_configuration_get_internal_bypass test/test_larpix.py::test_configuration_set_csa_bypass_select test/test_larpix.py::test_configuration_get_csa_bypass_select test/test_larpix.py::test_configuration_set_csa_monitor_select test/test_larpix.py::test_configuration_get_csa_monitor_select test/test_larpix.py::test_configuration_set_csa_testpulse_enable test/test_larpix.py::test_configuration_get_csa_testpulse_enable test/test_larpix.py::test_configuration_set_csa_testpulse_dac_amplitude test/test_larpix.py::test_configuration_get_csa_testpulse_dac_amplitude test/test_larpix.py::test_configuration_set_test_mode test/test_larpix.py::test_configuration_get_test_mode test/test_larpix.py::test_configuration_set_cross_trigger_mode test/test_larpix.py::test_configuration_get_cross_trigger_mode test/test_larpix.py::test_configuration_set_periodic_reset test/test_larpix.py::test_configuration_get_periodic_reset test/test_larpix.py::test_configuration_set_fifo_diagnostic test/test_larpix.py::test_configuration_get_fifo_diagnostic test/test_larpix.py::test_configuration_set_test_burst_length test/test_larpix.py::test_configuration_get_test_burst_length test/test_larpix.py::test_configuration_set_adc_burst_length test/test_larpix.py::test_configuration_get_adc_burst_length test/test_larpix.py::test_configuration_set_channel_mask test/test_larpix.py::test_configuration_get_channel_mask test/test_larpix.py::test_configuration_set_external_trigger_mask test/test_larpix.py::test_configuration_get_external_trigger_mask test/test_larpix.py::test_configuration_set_reset_cycles test/test_larpix.py::test_configuration_get_reset_cycles test/test_larpix.py::test_configuration_disable_channels test/test_larpix.py::test_configuration_disable_channels_default test/test_larpix.py::test_configuration_enable_channels test/test_larpix.py::test_configuration_enable_channels_default test/test_larpix.py::test_configuration_enable_external_trigger test/test_larpix.py::test_configuration_enable_external_trigger_default test/test_larpix.py::test_configuration_disable_external_trigger test/test_larpix.py::test_configuration_enable_testpulse test/test_larpix.py::test_configuration_enable_testpulse_default test/test_larpix.py::test_configuration_disable_testpulse test/test_larpix.py::test_configuration_disable_testpulse_default test/test_larpix.py::test_configuration_enable_analog_monitor test/test_larpix.py::test_configuration_disable_analog_monitor test/test_larpix.py::test_configuration_trim_threshold_data test/test_larpix.py::test_configuration_global_threshold_data test/test_larpix.py::test_configuration_csa_gain_and_bypasses_data test/test_larpix.py::test_configuration_csa_bypass_select_data test/test_larpix.py::test_configuration_csa_monitor_select_data test/test_larpix.py::test_configuration_csa_testpulse_enable_data test/test_larpix.py::test_configuration_csa_testpulse_dac_amplitude_data test/test_larpix.py::test_configuration_test_mode_xtrig_reset_diag_data test/test_larpix.py::test_configuration_sample_cycles_data test/test_larpix.py::test_configuration_test_burst_length_data test/test_larpix.py::test_configuration_adc_burst_length_data test/test_larpix.py::test_configuration_channel_mask_data test/test_larpix.py::test_configuration_external_trigger_mask_data test/test_larpix.py::test_configuration_reset_cycles_data test/test_larpix.py::test_configuration_to_dict test/test_larpix.py::test_configuration_from_dict test/test_larpix.py::test_configuration_write test/test_larpix.py::test_configuration_write_force test/test_larpix.py::test_configuration_read_absolute test/test_larpix.py::test_configuration_read_default test/test_larpix.py::test_configuration_read_local test/test_larpix.py::test_configuration_from_dict_reg_pixel_trim test/test_larpix.py::test_configuration_from_dict_reg_global_threshold test/test_larpix.py::test_configuration_from_dict_reg_csa_gain test/test_larpix.py::test_configuration_from_dict_reg_csa_bypass test/test_larpix.py::test_configuration_from_dict_reg_internal_bypass test/test_larpix.py::test_configuration_from_dict_reg_csa_bypass_select test/test_larpix.py::test_configuration_from_dict_reg_csa_monitor_select test/test_larpix.py::test_configuration_from_dict_reg_csa_testpulse_enable test/test_larpix.py::test_configuration_from_dict_reg_csa_testpulse_dac_amplitude test/test_larpix.py::test_configuration_from_dict_reg_test_mode test/test_larpix.py::test_configuration_from_dict_reg_cross_trigger_mode test/test_larpix.py::test_configuration_from_dict_reg_periodic_reset test/test_larpix.py::test_configuration_from_dict_reg_fifo_diagnostic test/test_larpix.py::test_configuration_from_dict_reg_sample_cycles test/test_larpix.py::test_configuration_from_dict_reg_test_burst_length test/test_larpix.py::test_configuration_from_dict_reg_adc_burst_length test/test_larpix.py::test_configuration_from_dict_reg_channel_mask test/test_larpix.py::test_configuration_from_dict_reg_external_trigger_mask test/test_larpix.py::test_configuration_from_dict_reg_reset_cycles test/test_larpix.py::test_controller_init_chips test/test_larpix.py::test_controller_get_chip test/test_larpix.py::test_controller_get_chip_all_chips test/test_larpix.py::test_controller_serial_read_mock test/test_larpix.py::test_controller_serial_write_mock test/test_larpix.py::test_controller_serial_write_read_mock test/test_larpix.py::test_packetcollection_getitem_int test/test_larpix.py::test_packetcollection_getitem_int_bits test/test_larpix.py::test_packetcollection_getitem_slice test/test_larpix.py::test_packetcollection_getitem_slice_bits test/test_larpix.py::test_packetcollection_origin test/test_larpix.py::test_packetcollection_from_dict
larpix/larpix.py
larpix/larpix.py