SerialPort.ReadHex
------------------

Reads bytes from serial port and returns them hex encoded.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [SerialPort](component_SerialPort.md) | [3.0](newinversion30.md) | ✅ Yes | ✅ Yes | ❌ No | ✅ Yes, on macOS and Windows | ❌ No |

MBS( "SerialPort.ReadHex"; PortReference; Length ) 

**MBS**( **"SerialPort.ReadHex";** /\* Reads bytes from serial port and returns them hex encoded. \*/  
**$PortReference**; /\* The reference number of the port. You get this number from [SerialPort.Open](SerialPortOpen.md) when you open the port.e.g. $port \*/   
**$Length**) /\* Maximum number of bytes to read.e.g. 10 \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| PortReference | The reference number of the port. You get this number from [SerialPort.Open](SerialPortOpen.md) when you open the port. | $port |
| Length | Maximum number of bytes to read. | 10 |

### Result

Returns text encoded as hex or error message.

### Description

Reads bytes from serial port and returns them hex encoded.  
The text returned may be shorter than length bytes.  
See also [SerialPort.AvailableBytes](SerialPortAvailableBytes.md) function.  
  
The script trigger pauses after it triggered a script and waits for you to call a function to read. This function clears the flag and allows the script trigger to fire again.  
### Examples

Read up to 8 bytes and return them as:

 $value = MBS ( "SerialPort.ReadHex"; $port ; 8 )  
### See also

- [SerialPort.AvailableBytes](SerialPortAvailableBytes.md)
- [SerialPort.Open](SerialPortOpen.md)
- [SerialPort.Read](SerialPortRead.md)
- [SerialPort.ReadByte](SerialPortReadByte.md)
- [SerialPort.ReadLine](SerialPortReadLine.md)
- [SerialPort.Resume](SerialPortResume.md)
- [SerialPort.WriteHex](SerialPortWriteHex.md)

### Blog Entries

- [MBS Filemaker Plugin, version 4.5pr1](https://www.mbsplugins.de/archive/2014-11-24/MBS_Filemaker_Plugin_version_4/monkeybreadsoftware_blog_filemaker)
- [Serial Port functions for MBS Filemaker Plugin](https://www.mbsplugins.de/archive/2012-12-01/Serial_Port_functions_for_MBS_/monkeybreadsoftware_blog_filemaker)

This function is free to use.

Created 18th August 2014 , last changed 30th January 2025

  
[SerialPort.ReadByte](SerialPortReadByte.md) - [SerialPort.ReadLine](SerialPortReadLine.md)

[HTML Version](SerialPortReadHex.shtml)