> For the complete documentation index, see [llms.txt](https://sdk.twelite.info/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sdk.twelite.info/hw-api-ref/perifuraru/uart/fprintf-raiburari/tsfile.md).

# tsFILE

[vfPrintf](/hw-api-ref/perifuraru/uart/fprintf-raiburari/vfprintf.md)() [vPutChar](/hw-api-ref/perifuraru/uart/fprintf-raiburari/vputchar.md)() で指定する出力先を定義した構造体。

### メンバー

| uint8                                               | u8Device | シリアルポート (E\_AHI\_UART\_0 または E\_AHI\_UART\_1 を指定する）              |
| --------------------------------------------------- | -------- | ---------------------------------------------------------------- |
| bool\_t (\*bPutChar) (uint8 u8Device, uint8 u8Char) | bPutChar | 出力用の関数ポインタ。SERIAL ライブラリ用には SERIAL\_bTxChar() が準備されているので、これを指定する。 |

{% hint style="info" %}
SERIAL\_bTxChar() は、u8Char として渡されたバイトを SERIAL ライブラリ内の FIFO キューに投入します。

独自に出力関数を準備することで、UART 以外への文字列の出力にも利用できます。
{% endhint %}

### サンプルコード

```c
#include "serial.h"
#include "fprintf.h"

tsFILE sSerStream;
tsSerialPortSetup sSerPort;

void vSerialInit(uint32 u32Baud, tsUartOpt *pUartOpt) {
	// initialize sSerPort
	...
	SERIAL_vInit(&sSerPort); 

	// for vfPrintf()
	sSerStream.bPutChar = SERIAL_bTxChar;
	sSerStream.u8Device = E_AHI_UART_0;
}

void vSerOut() {
    vfPrintf(&sSerStream, "HELLO!");
}

```

以下は、キャラクタ LCD の出力コードとして利用した一例です。

```c
#include "serial.h"
#include "fprintf.h"

tsFILE sLcdStream;

// handle LCD display
PUBLIC bool_t LCD_bTxChar(uint8 u8Device, uint8 u8Data) {
	int i;

	switch (u8Data) {
	case '\n':
	...
}

void vInitHardware() {
    /* Initisalise the LCD */
    vLcdReset(3, 0);
    
    /* register for vfPrintf() */
    sLcdStream.bPutChar = LCD_bTxChar;
    sLcdStream.u8Device = 0xFF;
}

void vSomeOutput() {
    vfPrintf(&sLcdStream, "Hello World!\n");
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://sdk.twelite.info/hw-api-ref/perifuraru/uart/fprintf-raiburari/tsfile.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
