Write data into serial port line

@param string $data

@return int length of byte written

@throws WriteNotAllowed|DeviceNotOpened
775244
public function write($data)
    {
        $this->ensureDeviceOpen();

        if (false !== ($dataWritten = fwrite($this->fd, $data))) {
            return $dataWritten;
        }

        throw new WriteNotAllowed();
    }
603756
public function writeBytes($data, $num=null)
    {
        // We do not need to check if file position points to the end of "file".
        // Only append operation is supported now

        if ($num !== null) {
            $this->_data .= substr($data, 0, $num);
        } else {
            $this->_data .= $data;
        }

        $this->_position = strlen($this->_data);
    }
517983
public function serialize(/*mixed*/ $data) 
    {
        if (null === $data) {
            return $this->serializeInt(null);
        }
        elseif (is_array($data)) {
            return $this->serializeUInt8($data);
        }
        elseif (is_integer($data)) {
            return $this->serializeLong($data);
        }
        elseif (is_string($data)) {
            return $this->serializeString($data);
        }
        elseif ($data instanceof Serializable) {
            return $data->serialize();
        }

        throw new RuntimeException("Invalid parameter provided to \\NEM\\Core\\Serialize::serialize().");
    }
1089440
public function writeLine(string $data): void
	{
		try
		{
			$this->write($data."\r\n");
		}
		catch (\Exception $e)
		{
			throw $e;
		}
	}
945985
public function write($data)
    {
        $dataLen            = strlen($data);
        $this->content      = substr($this->content, 0, $this->bytes_read) . $data . substr($this->content, $this->bytes_read + $dataLen);
        $this->bytes_read  += $dataLen;
        $this->lastModified = time();
        return $dataLen;
    }
183892
protected function encode($data)
    {
        if ($this->getEncoding() === self::ENCODING_BASE64) {
            return base64_encode(serialize($data));
        } else {
            return serialize($data);
        }
    }
1342303
public function stream_write($data)
    {
        if ($this->getOnWriteDataMode()) {

            $length = strlen($data);
            $this->appendDataBuffer($data);
            $this->appendPosition($length);
            return $length;
        } else {
            throw new \Exception('dirty mode.');
        }
    }
14561
public function write($data)
    {
        if ($this->isOpen() === false) {
            $msg = "Cannot write in a closed MemoryStream.";
            throw new MemoryStreamException($msg, $this, MemoryStreamException::NOT_OPEN);
        }
        
        if ($this->length - 1 === $this->position) {
            // simply append.
            $this->binary .= $data;
        } elseif ($this->position === 0) {
            // simply prepend.
            $this->binary = ($data . $this->binary);
        } else {
            // we are in the middle of the string.
            $part1 = substr($this->binary, 0, $this->position);
            $part2 = substr($this->binary, $this->position);
            $this->binary = ($part1 . $data . $part2);
        }

        $dataLen = strlen($data);
        $this->incrementPosition($dataLen);
        $this->incrementLength($dataLen);

        return $dataLen;
    }
1100029
private function writeData($data) {
        $count = fwrite($this->connection, $data.EOL_WINDOWS, strlen($data)+2);

        if ($count != strlen($data)+2)
            throw new RuntimeException('Error writing to socket, length of data: '.(strlen($data)+2).', bytes written: '.$count.NL.'data: '.$data.NL.NL.'SMTP transfer log:'.NL.'------------------'.NL.$this->logBuffer);

        $this->logSentData($data);
    }
928884
public function fwrite(string $data): int
    {
        $len = dechex(strlen($data));
        $written = fwrite($this->peer, "${len}\r\n${data}\r\n");
        if (!$written) {
            $msg = 'Cannot write to socket';
            throw new Exception\RuntimeException($msg);
        }

        return $written;
    }
483487
public function write(string $data): int
    {
        $length = strlen($data);

        if (0 === $length) {
            return 0;
        }

        $written = @fwrite($this->handle, $data, $length);

        if (false === $written || $written !== $length) {
            $message = 'Could not write to the file.';
            if ($error = error_get_last()) {
                $message .= sprintf(' Errno: %d; %s', $error['type'], $error['message']);
            }
            throw new FileException($message);
        }

        return $written;
    }
558098
public function write($data, $offset)
    {
        $segno = floor($offset / $this->segsize);
        if (!isset($this->segments[$segno])) {
            if (!$this->open($segno, true)) {
                return false;
            }
        }
        $sOffset = $offset % $this->segsize;
        $d = $this->segsize - ($sOffset + mb_orig_strlen($data));
        if ($d < 0) {
            $this->write(mb_orig_substr($data, $d), ($segno + 1) * $this->segsize);
            $data = mb_orig_substr($data, 0, $d);
        }
        //Daemon::log('writing to #'.$offset.' (segno '.$segno.')');
        shmop_write($this->segments[$segno], $data, $sOffset);
        return true;
    }
1280314
public function write($data)
    {
        if (!$this->alive) {
            Daemon::log('Attempt to write to dead IOStream (' . get_class($this) . ')');
            return false;
        }
        if (!isset($this->bevWrite)) {
            return false;
        }
        if (!mb_orig_strlen($data)) {
            return true;
        }
        $this->writing = true;
        Daemon::$noError = true;
        if (!$this->bevWrite->write($data) || !Daemon::$noError) {
            $this->close();
            return false;
        }
        return true;
    }
680979
private function serialize($data)
    {
        if ($this->type == 'db') {
            return $this->db->encode($data, $this->packed);
        }

        return $this->packed ? serialize($data) : $data;
    }
1325165
function _stream_write($data)
    {
        switch ($this->mode) {
            case 'r':
                return false;
        }

        $result = $this->sftp->put($this->path, $data, SFTP::SOURCE_STRING, $this->pos);
        if (isset($this->notification) && is_callable($this->notification)) {
            if (!$result) {
                call_user_func($this->notification, STREAM_NOTIFY_FAILURE, STREAM_NOTIFY_SEVERITY_ERR, $this->sftp->getLastSFTPError(), NET_SFTP_OPEN, 0, 0);
                return 0;
            }
            // seems that PHP splits up strings into 8k blocks before calling stream_write
            call_user_func($this->notification, STREAM_NOTIFY_PROGRESS, STREAM_NOTIFY_SEVERITY_INFO, '', 0, strlen($data), strlen($data));
        }

        if ($result === false) {
            return false;
        }
        $this->pos+= strlen($data);
        if ($this->pos > $this->size) {
            $this->size = $this->pos;
        }
        $this->eof = false;
        return strlen($data);
    }
748805
protected function _writeLine($data = null)
    {
        if ($data !== null) {
            if (fwrite($this->_socket, $data) === false) {
                throw new TransmitException(['send data failed: :url', 'url' => $this->_url]);
            }
            file_put_contents($this->_file, $data, FILE_APPEND);
        }

        file_put_contents($this->_file, PHP_EOL, FILE_APPEND);

        if (fwrite($this->_socket, "\r\n") === false) {
            throw new TransmitException(['send data failed: :url', 'url' => $this->_url]);
        }

        return $this;
    }
214080
public function stream_write($data)
    {
        if (!$this->_objectName) {
            return 0;
        }
        $len = strlen($data);
        $this->_objectBuffer .= $data;
        $this->_objectSize += $len;
        // TODO: handle current position for writing!
        return $len;
    }