C++優秀串口庫

serial::Serial Class Reference

#include <serial.h>

Data Structures

class ?ScopedReadLock
class ?ScopedWriteLock

Public Member Functions公有成員方法(編程用的都在這里了,那些私有的如果不開源一般跟我們沒有關系了)

Serial?(const std::string &port="", uint32_t baudrate=9600,?Timeout?timeout=Timeout(),?

bytesize_t?bytesize=eightbits,?parity_t?parity=parity_none,?

stopbits_t?stopbits=stopbits_one,?flowcontrol_t?flowcontrol=flowcontrol_none)構造函數

virtual?~Serial?()析構函數
void?open?()
bool?isOpen?() const
void?close?()
size_t?available?()
size_t?read?(uint8_t *buffer, size_t size)
size_t?read?(std::vector< uint8_t > &buffer, size_t size=1)
size_t?read?(std::string &buffer, size_t size=1)
std::string?read?(size_t size=1)
size_t?readline?(std::string &buffer, size_t size=65536, std::string eol="\n")
std::string?readline?(size_t size=65536, std::string eol="\n")
std::vector< std::string >?readlines?(size_t size=65536, std::string eol="\n")
size_t?write?(const uint8_t *data, size_t size)
size_t?write?(const std::vector< uint8_t > &data)
size_t?write?(const std::string &data)
void?setPort?(const std::string &port)
std::string?getPort?() const
void?setTimeout?(Timeout?&timeout)
void?

setTimeout?(uint32_t inter_byte_timeout, uint32_t read_timeout_constant,

uint32_t read_timeout_multiplier, uint32_t write_timeout_constant,

uint32_t write_timeout_multiplier)

TimeoutgetTimeout?() const
void?setBaudrate?(uint32_t baudrate)
uint32_t?getBaudrate?() const
void?setBytesize?(bytesize_t?bytesize)
bytesize_tgetBytesize?() const
void?setParity?(parity_t?parity)
parity_tgetParity?() const
void?setStopbits?(stopbits_t?stopbits)
stopbits_tgetStopbits?() const
void?setFlowcontrol?(flowcontrol_t?flowcontrol)
flowcontrol_tgetFlowcontrol?() const
void?flush?()
void?flushInput?()
void?flushOutput?()
void?sendBreak?(int duration)
void?setBreak?(bool level=true)
void?setRTS?(bool level=true)
void?setDTR?(bool level=true)
bool?waitForChange?()
bool?getCTS?()
bool?getDSR?()
bool?getRI?()
bool?getCD?()

Detailed Description(后面是對以上表格內容的詳細介紹)

Class that provides a portable serial port interface.


Constructor & Destructor Documentation構造函數+析構函數

serial::Serial::Serial(const std::string &?port?=?"",
uint32_t?baudrate?=?9600,
Timeouttimeout?=?Timeout(),
bytesize_tbytesize?=?eightbits,
parity_tparity?=?parity_none,
stopbits_tstopbits?=?stopbits_one,
flowcontrol_tflowcontrol?=?flowcontrol_none?
)

Creates a?Serial?object and opens the port if a port is specified, otherwise it remains closed until?serial::Serial::open?is called.

創建一個串口對象,如果制定了端口號,那么這個串口將打開,否則現在不會打開,會等到調用open函數的時候再打開

Parameters:

portA std::string containing the address of the serial port, which would be something like 'COM1' on Windows and '/dev/ttyS0' on Linux.(地址值:Windows系統類似于COM1,LINUX系統類似于/dev/ttyS0這樣的款式)
baudrateAn unsigned 32-bit integer that represents the baudrate波特率:是一個32位的int類型數據
timeoutA?serial::Timeout?struct that defines the timeout conditions for the serial port.超時的時間值

See also:

serial::Timeout

Parameters:(對上面的timeout結構體詳細介紹,一下是結構體的成員變量)

bytesize

字長

Size of each byte in the serial transmission of data, default is eightbits, possible values are: fivebits, sixbits, sevenbits, eightbits默認字長是8位,可以是5,6,7,8好像不能是9位

parity

效驗位

Method of parity, default is parity_none, possible values are: parity_none, parity_odd, parity_even

stopbits

停止位

Number of stop bits used, default is stopbits_one, possible values are: stopbits_one, stopbits_one_point_five, stopbits_two

flowcontrol

流控

Type of flowcontrol used, default is flowcontrol_none, possible values are: flowcontrol_none, flowcontrol_software, flowcontrol_hardware

Exceptions:

PortNotOpenedException

Serial::~Serial()[virtual]

Destructor

{delete pimpl_;
}

Member Function Documentation

size_t?Serial::available()

Return the number of characters in the buffer.

{return pimpl_->available ();
}

void?Serial::close()

Closes the serial port.

{pimpl_->close ();
}

void?Serial::flush()

Flush the input and output buffers

{ScopedReadLock(this->pimpl_);ScopedWriteLock(this->pimpl_);pimpl_->flush ();read_cache_.clear ();
}

void?Serial::flushInput()

Flush only the input buffer

{ScopedReadLock(this->pimpl_);pimpl_->flushInput ();
}

void?Serial::flushOutput()

Flush only the output buffer

{ScopedWriteLock(this->pimpl_);pimpl_->flushOutput ();read_cache_.clear ();
}

uint32_t?Serial::getBaudrate()const

Gets the baudrate for the serial port.獲取波特率

Returns:

An integer that sets the baud rate for the serial port.

See also:

Serial::setBaudrate

Exceptions:

InvalidConfigurationException
{return uint32_t(pimpl_->getBaudrate ());
}

bytesize_t?Serial::getBytesize()const

Gets the bytesize for the serial port.設置“數據字長”一般是8位

See also:

Serial::setBytesize

Exceptions:

InvalidConfigurationException
{return pimpl_->getBytesize ();
}

bool?Serial::getCD()

Returns the current status of the CD line.

{return pimpl_->getCD ();
}

bool?Serial::getCTS()

Returns the current status of the CTS line.

{return pimpl_->getCTS ();
}

bool?Serial::getDSR()

Returns the current status of the DSR line.

{return pimpl_->getDSR ();
}

flowcontrol_t?Serial::getFlowcontrol()const

Gets the flow control for the serial port.

See also:

Serial::setFlowcontrol

Exceptions:

InvalidConfigurationException
{return pimpl_->getFlowcontrol ();
}

parity_t?Serial::getParity()const

Gets the parity for the serial port.

See also:

Serial::setParity

Exceptions:

InvalidConfigurationException
{return pimpl_->getParity ();
}

string?Serial::getPort()const

Gets the serial port identifier.

See also:

Serial::setPort

Exceptions:

InvalidConfigurationException
{return pimpl_->getPort ();
}

bool?Serial::getRI()

Returns the current status of the RI line.

{return pimpl_->getRI ();
}

stopbits_t?Serial::getStopbits()const

Gets the stopbits for the serial port.

See also:

Serial::setStopbits

Exceptions:

InvalidConfigurationException
{return pimpl_->getStopbits ();
}

serial::Timeout?Serial::getTimeout()const

Gets the timeout for reads in seconds.

Returns:

A?Timeout?struct containing the inter_byte_timeout, and read and write timeout constants and multipliers.

See also:

Serial::setTimeout

                          {return pimpl_->getTimeout ();
}

bool?Serial::isOpen()const

Gets the open status of the serial port.

Returns:

Returns true if the port is open, false otherwise.

{return pimpl_->isOpen ();
}

void?Serial::open()

Opens the serial port as long as the port is set and the port isn't already open.

If the port is provided to the constructor then an explicit call to open is not needed.

See also:

Serial::Serial

Exceptions:

std::invalid_argument
serial::SerialExecption
serial::IOException
{pimpl_->open ();
}

size_t?Serial::read(uint8_t *?buffer,
size_t?size?
)

Read a given amount of bytes from the serial port into a given buffer.

這不就是我們的目的:從串口讀取數據

The read function will return in one of three cases:(我覺得一般不用管后面這幾種情況)

  • The number of requested bytes was read.
    • In this case the number of bytes requested will match the size_t returned by read.
  • A timeout occurred, in this case the number of bytes read will not match the amount requested, but no exception will be thrown. One of two possible timeouts occurred:
    • The inter byte timeout expired, this means that number of milliseconds elapsed between receiving bytes from the serial port exceeded the inter byte timeout.
    • The total timeout expired, which is calculated by multiplying the read timeout multiplier by the number of requested bytes and then added to the read timeout constant. If that total number of milliseconds elapses after the initial call to read a timeout will occur.
  • An exception occurred, in this case an actual exception will be thrown.

Parameters:函數參數

bufferAn uint8_t array of at least the requested size.一個uint8_t數據類型的數組,長度至少達到size指定大小
sizeA size_t defining how many bytes to be read.

Returns:函數返回值

A size_t representing the number of bytes read as a result of the call to read.(從串口讀取了多少個字符串就把字符串長度作為返回值,所以可以根據返回值是否等于size參數判斷是否發生異常)

{ScopedReadLock (this->pimpl_);return this->pimpl_->read (buffer, size);
}

size_t?Serial::read(std::vector< uint8_t > &?buffer,
size_t?size?=?1?
)

Read a given amount of bytes from the serial port into a give buffer.這跟上邊那個數組幾乎完全一樣

Parameters:

bufferA reference to a std::vector of uint8_t.
sizeA size_t defining how many bytes to be read.

Returns:

A size_t representing the number of bytes read as a result of the call to read.

{ScopedReadLock (this->pimpl_);uint8_t *buffer_ = new uint8_t[size];size_t bytes_read = this->pimpl_->read (buffer_, size);buffer.insert (buffer.end (), buffer_, buffer_+bytes_read);delete[] buffer_;return bytes_read;
}

size_t?Serial::read(std::string &?buffer,
size_t?size?=?1?
)

Read a given amount of bytes from the serial port into a give buffer.

Parameters:

bufferA reference to a std::string.
sizeA size_t defining how many bytes to be read.

Returns:

A size_t representing the number of bytes read as a result of the call to read.

{ScopedReadLock (this->pimpl_);uint8_t *buffer_ = new uint8_t[size];size_t bytes_read = this->pimpl_->read (buffer_, size);buffer.append (reinterpret_cast<const char*>(buffer_), bytes_read);delete[] buffer_;return bytes_read;
}

string?Serial::read(size_t?size?=?1)

Read a given amount of bytes from the serial port and return a string containing the data.

Parameters:

sizeA size_t defining how many bytes to be read.

Returns:

A std::string containing the data read from the port.

{std::string buffer;this->read (buffer, size);return buffer;
}

這里

size_t?serial::Serial::readline(std::string &?buffer,
size_t?size?=?65536,
std::string?eol?=?"\n"?
)

Reads in a line or until a given delimiter has been processed.

Reads from the serial port until a single line has been read.

Parameters:

bufferA std::string reference used to store the data.
sizeA maximum length of a line, defaults to 65536 (2^16)
eolA string to match against for the EOL.

Returns:

A size_t representing the number of bytes read.

std::string?serial::Serial::readline(size_t?size?=?65536,
std::string?eol?=?"\n"?
)

Reads in a line or until a given delimiter has been processed.

Reads from the serial port until a single line has been read.

Parameters:

sizeA maximum length of a line, defaults to 65536 (2^16)
eolA string to match against for the EOL.

Returns:

A std::string containing the line.

vector< string >?Serial::readlines(size_t?size?=?65536,
std::string?eol?=?"\n"?
)

Reads in multiple lines until the serial port times out.

This requires a timeout > 0 before it can be run. It will read until a timeout occurs and return a list of strings.

Parameters:

sizeA maximum length of combined lines, defaults to 65536 (2^16)
eolA string to match against for the EOL.

Returns:

A vector<string> containing the lines.

{ScopedReadLock (this->pimpl_);std::vector<std::string> lines;size_t eol_len = eol.length ();uint8_t *buffer_ = static_cast<uint8_t*>(alloca (size * sizeof (uint8_t)));size_t read_so_far = 0;size_t start_of_line = 0;while (read_so_far < size) {size_t bytes_read = this->read_ (buffer_+read_so_far, 1);read_so_far += bytes_read;if (bytes_read == 0) {if (start_of_line != read_so_far) {lines.push_back (string (reinterpret_cast<const char*> (buffer_ + start_of_line),read_so_far - start_of_line));}break; // Timeout occured on reading 1 byte}if (string (reinterpret_cast<const char*>(buffer_ + read_so_far - eol_len), eol_len) == eol) {// EOL foundlines.push_back(string(reinterpret_cast<const char*> (buffer_ + start_of_line),read_so_far - start_of_line));start_of_line = read_so_far;}if (read_so_far == size) {if (start_of_line != read_so_far) {lines.push_back(string(reinterpret_cast<const char*> (buffer_ + start_of_line),read_so_far - start_of_line));}break; // Reached the maximum read length}}return lines;
}

void?Serial::sendBreak(int?duration)

Sends the RS-232 break signal. See tcsendbreak(3).

{pimpl_->sendBreak (duration);
}

void?Serial::setBaudrate(uint32_t?baudrate)

Sets the baudrate for the serial port.

Possible baudrates depends on the system but some safe baudrates include: 110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 56000, 57600, 115200 Some other baudrates that are supported by some comports: 128000, 153600, 230400, 256000, 460800, 921600

Parameters:

baudrateAn integer that sets the baud rate for the serial port.

Exceptions:

InvalidConfigurationException
{pimpl_->setBaudrate (baudrate);
}

void?Serial::setBreak(bool?level?=?true)

Set the break condition to a given level. Defaults to true.

{pimpl_->setBreak (level);
}

void?Serial::setBytesize(bytesize_tbytesize)

Sets the bytesize for the serial port.

Parameters:

bytesizeSize of each byte in the serial transmission of data, default is eightbits, possible values are: fivebits, sixbits, sevenbits, eightbits

Exceptions:

InvalidConfigurationException
{pimpl_->setBytesize (bytesize);
}

void?Serial::setDTR(bool?level?=?true)

Set the DTR handshaking line to the given level. Defaults to true.

{pimpl_->setDTR (level);
}

void?Serial::setFlowcontrol(flowcontrol_tflowcontrol)

Sets the flow control for the serial port.

Parameters:

flowcontrolType of flowcontrol used, default is flowcontrol_none, possible values are: flowcontrol_none, flowcontrol_software, flowcontrol_hardware

Exceptions:

InvalidConfigurationException
{pimpl_->setFlowcontrol (flowcontrol);
}

void?Serial::setParity(parity_tparity)

Sets the parity for the serial port.

Parameters:

parityMethod of parity, default is parity_none, possible values are: parity_none, parity_odd, parity_even

Exceptions:

InvalidConfigurationException
{pimpl_->setParity (parity);
}

void?Serial::setPort(const std::string &?port)

Sets the serial port identifier.

Parameters:

portA const std::string reference containing the address of the serial port, which would be something like 'COM1' on Windows and '/dev/ttyS0' on Linux.

Exceptions:

InvalidConfigurationException
{ScopedReadLock(this->pimpl_);ScopedWriteLock(this->pimpl_);bool was_open = pimpl_->isOpen ();if (was_open) close();pimpl_->setPort (port);if (was_open) open ();
}

void?Serial::setRTS(bool?level?=?true)

Set the RTS handshaking line to the given level. Defaults to true.

{pimpl_->setRTS (level);
}

void?Serial::setStopbits(stopbits_tstopbits)

Sets the stopbits for the serial port.

Parameters:

stopbitsNumber of stop bits used, default is stopbits_one, possible values are: stopbits_one, stopbits_one_point_five, stopbits_two

Exceptions:

InvalidConfigurationException
{pimpl_->setStopbits (stopbits);
}

void?Serial::setTimeout(serial::Timeout?&?timeout)

Sets the timeout for reads and writes using the?Timeout?struct.

There are two timeout conditions described here:

  • The inter byte timeout:
    • The inter_byte_timeout component of?serial::Timeout?defines the maximum amount of time, in milliseconds, between receiving bytes on the serial port that can pass before a timeout occurs. Setting this to zero will prevent inter byte timeouts from occurring.
  • Total time timeout:
    • The the constant and multiplier component of this timeout condition, for both read and write, are defined in?serial::Timeout. This timeout occurs if the total time since the read or write call was made exceeds the specified time in milliseconds.
    • The limit is defined by multiplying the multiplier component by the number of requested bytes and adding that product to the constant component. In this way if you want a read call, for example, to timeout after exactly one second regardless of the number of bytes you asked for then set the read_timeout_constant component of?serial::Timeout?to 1000 and the read_timeout_multiplier to zero. This timeout condition can be used in conjunction with the inter byte timeout condition with out any problems, timeout will simply occur when one of the two timeout conditions is met. This allows users to have maximum control over the trade-off between responsiveness and efficiency.

Read and write functions will return in one of three cases. When the reading or writing is complete, when a timeout occurs, or when an exception occurs.

Parameters:

timeoutA?serial::Timeout?struct containing the inter byte timeout, and the read and write timeout constants and multipliers.

See also:

serial::Timeout

{pimpl_->setTimeout (timeout);
}

void?serial::Serial::setTimeout(uint32_t?inter_byte_timeout,
uint32_t?read_timeout_constant,
uint32_t?read_timeout_multiplier,
uint32_t?write_timeout_constant,
uint32_t?write_timeout_multiplier?
)[inline]

Sets the timeout for reads and writes.

  {Timeout timeout(inter_byte_timeout, read_timeout_constant,read_timeout_multiplier, write_timeout_constant,write_timeout_multiplier);return setTimeout(timeout);}

bool?Serial::waitForChange()

Blocks until CTS, DSR, RI, CD changes or something interrupts it.

Can throw an exception if an error occurs while waiting. You can check the status of CTS, DSR, RI, and CD once this returns. Uses TIOCMIWAIT via ioctl if available (mostly only on Linux) with a resolution of less than +-1ms and as good as +-0.2ms. Otherwise a polling method is used which can give +-2ms.

Returns:

Returns true if one of the lines changed, false if something else occurred.

Exceptions:

SerialException
{return pimpl_->waitForChange();
}

size_t?Serial::write(const uint8_t *?data,
size_t?size?
)

Write a string to the serial port.

Parameters:

dataA const reference containing the data to be written to the serial port.
sizeA size_t that indicates how many bytes should be written from the given data buffer.

Returns:

A size_t representing the number of bytes actually written to the serial port.

{ScopedWriteLock(this->pimpl_);return this->write_(data, size);
}

size_t?Serial::write(const std::vector< uint8_t > &?data)

Write a string to the serial port.

Parameters:

dataA const reference containing the data to be written to the serial port.

Returns:

A size_t representing the number of bytes actually written to the serial port.

{ScopedWriteLock(this->pimpl_);return this->write_ (&data[0], data.size());
}

size_t?serial::Serial::write(const std::string &?data)

Write a string to the serial port.

Parameters:

dataA const reference containing the data to be written to the serial port.

Returns:

A size_t representing the number of bytes actually written to the serial port.


The documentation for this class was generated from the following files:

  • include/serial/serial.h
  • src/serial.cc

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/211528.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/211528.shtml
英文地址,請注明出處:http://en.pswp.cn/news/211528.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

用chatGPT開發項目:我想的無人的智慧樹網站 流量之神 利用人工智能的算法將人吸引住 GPT4是不是越來越難用了,問一下就要證明一下自己是不是人類

廣度發散&#xff1a;讓AI給出時代或今日或你關注的熱點事件 比如采集新聞頭條&#xff0c;根據內容或標題&#xff0c;以不同的角度&#xff0c;或各種人群的角色&#xff0c;生成50篇簡短的文章。一下就能占傳統的搜索引擎。這是AI最擅長的【千人千面&#xff0c;海量生成】…

【中國海洋大學】操作系統隨堂測試6整理

1. IO系統的層次機構包括&#xff1a;IO硬件、中斷處理程序、&#xff08;&#xff09;程序、設備獨立性軟件、用戶層軟件。 答&#xff1a;設備驅動 2. IO設備和控制器之間的接口包括三種類型的信號&#xff1a;數據信號線、控制信號線和&#xff08;&#xff09;&#xff1…

qt反射基礎

最近研究了一下QT的反射機制&#xff0c; Qt的元對象系統除了提供信號/槽機制的特性之外&#xff0c;它還提供了以下特性: QObject::metaObject() 返回關聯的元對象 QMetaObject::className() 在運行時狀態下返回類名 QObject::inherits() 判斷類的繼承關系 QObject::tr()&…

鴻蒙開發之封裝優化

面向對象開發離不開封裝&#xff0c;將重復的可以復用的代碼封裝起來&#xff0c;提高開發效率。 基于之前的List&#xff0c;對代碼進行封裝。 1、抽取component 將List的頭部抽離出來作為一個新的component。可以創建一個新的ArkTS文件&#xff0c;寫我們的頭部代碼 為了…

代理模式:解析對象間的間接訪問與控制

目錄 引言 理解代理模式 不同類型的代理模式 代理模式的應用場景 代理模式的優缺點 優點 缺點 實際案例&#xff1a;Java中的代理模式應用 結語 引言 代理模式是軟件設計模式中的一種結構型模式&#xff0c;旨在為其他對象提供一種代理以控制對這個對象的訪問。它允許你…

消息隊列使用指南

介紹 消息隊列是一種常用的應用程序間通信方法&#xff0c;可以用來在不同應用程序或組件之間傳遞數據或消息。消息隊列就像一個緩沖區&#xff0c;接收來自發送方的消息&#xff0c;并存儲在隊列中&#xff0c;等待接收方從隊列中取出并處理。 在分布式系統中&#xff0c;消…

死鎖問題,4個必要條件+避免死鎖

目錄 引入 死鎖 概念 示例 多把鎖 單鎖 4個必要條件 用途 引入 我們用加鎖的方式保證了多個線程訪問臨界資源時,不會出現數據紊亂的問題 但是,鎖的引入,會導致出現其他的問題 死鎖 概念 在多線程或多進程的并發環境中&#xff0c;兩個或多個進程或線程被永久阻塞&…

esxi全稱“VMware ESXi

esxi全稱“VMware ESXi”&#xff0c;是可直接安裝在物理服務器上的強大的裸機管理系統&#xff0c;是一款虛擬軟件&#xff1b;ESXi本身可以看做一個操作系統&#xff0c;采用Linux內核&#xff0c;安裝方式為裸金屬方式&#xff0c;可直接安裝在物理服務器上&#xff0c;不需…

數據結構算法-希爾排序算法

引言 在一個普通的下午&#xff0c;小明和小森決定一起玩“誰是老板”的撲克牌游戲。這次他們玩的可不僅僅是娛樂&#xff0c;更是要用撲克牌來決定誰是真正的“大老板”。 然而&#xff0c;小明的牌就像剛從亂麻中取出來的那樣&#xff0c;毫無頭緒。小森的牌也像是被小丑擲…

Agent學習筆記

背景&#xff1a;LLM → \to → Agent ChatGPT為代表的大語言模型就不用過多的介紹了&#xff0c;ChatGPT很強大&#xff0c;但是也有做不到的東西。例如&#xff1a; 實時查詢問題&#xff1a;實時的天氣&#xff0c;地理位置&#xff0c;最新新聞報道&#xff0c;現實世界…

十年婚姻·總結八

十年婚姻總結八 女人一生的合伙人不能只是帥哥哥 女人一生的合伙人不能只是帥哥哥 浪漫的本質還是你的籌碼。 比如你送男人5萬的手表&#xff0c;但你沒什么其他籌碼&#xff08;皮膚粗糙蠟黃、沒人脈金錢資源、長的胖&#xff09;。 那個男人會覺得你胡鬧&#xff0c;你送的…

分類預測 | SSA-HKELM-Adaboost麻雀算法優化混合核極限學習機的數據分類預測

分類預測 | SSA-HKELM-Adaboost麻雀算法優化混合核極限學習機的數據分類預測 目錄 分類預測 | SSA-HKELM-Adaboost麻雀算法優化混合核極限學習機的數據分類預測分類效果基本描述程序設計參考資料 分類效果 基本描述 1.SSA-HKELM-Adaboost麻雀算法優化混合核極限學習機的數據分類…

引用文獻算作重復率么【一文讀懂】

大家好&#xff0c;今天來聊聊引用文獻算作重復率么&#xff0c;希望能給大家提供一點參考。 以下是針對論文重復率高的情況&#xff0c;提供一些修改建議和技巧&#xff1a; 引用文獻算作重復率么 在學術研究和論文撰寫過程中&#xff0c;引用文獻是不可或缺的一部分小發貓偽…

shell學習1——txt文件備份,文件名加個年月日的后綴,如test.txt對于備份文件為test.txt_20231205

跟B站Up主學習shell腳本——阿銘linux 3461576172505894 需求 txt文件備份&#xff0c;文件名加個年月日的后綴&#xff0c;如test.txt對于備份文件為test.txt_20231205 代碼 #!/bin/bash ##定義后綴變量 suffixdate %Y%m%d##找到/test/目錄下的txt文件 for f in find /tes…

ubuntu源配置文件/etc/apt/sources.list不存在

若使用命令sudo apt-get update報錯&#xff1a;apt-get:找不到命令&#xff0c;八成是源配置文件/etc/apt/sources.list不存在。但是一般來說不會不存在&#xff0c;若真的不小心刪除的話&#xff0c;我們也可以進行恢復。 首先創建/etc/apt/sources.list文件&#xff0c;然后…

安卓與串口通信-如何區分連接的設備?

前言與背景 一般來說&#xff0c;不管是在什么平臺上需要與外接硬件交互&#xff0c;第一件事都是應該能夠正確的識別出目標硬件。 例如在 Windows 上&#xff0c;當一個新的外設設備被插入到我們的電腦時&#xff0c;系統會通過 Hardware IDs 、Compatible IDs 來確定連接的…

看圖學源碼之 Atomic 類源碼淺析二(cas + 分治思想的原子累加器)

原子累加器 相較于上一節看圖學源碼 之 Atomic 類源碼淺析一&#xff08;cas 自旋操作的 AtomicXXX原子類&#xff09;說的的原子類&#xff0c;原子累加器的效率會更高 XXXXAdder 和 XXXAccumulator 區別就是 Adder只有add 方法&#xff0c;Accumulator是可以進行自定義運算方…

ufw常用命令解析

命令 舉例 解釋 ufw enable — 啟用防火墻 ufw disable — 禁用防火墻 ufw status — 查看防火墻狀態與規則 ufw default ARG sudo ufw default allow sudo ufw default deny 將默認策略設置為允許所有未明確規定的流量 將默認策略設置為拒絕所有未明確規定的流量…

大數據技術5:OLAP引擎對比分析

前言&#xff1a;數據倉庫建設&#xff0c;初級的理解就是建表&#xff0c;將業務數據、日志數據、消息隊列數據等&#xff0c;通過各種調度任務寫入到表里供OLAP引擎使用。但要想建好數倉也是一個復雜、龐大的工程&#xff0c;比如要考慮&#xff1a;數據清洗、數據建模&#…

001 LLM大模型之Transformer 模型

參考《大規模語言模型--從理論到實踐》 目錄 一、綜述 二、Transformer 模型 三、 嵌入表示層&#xff08;位置編碼代碼&#xff09; 一、綜述 語言模型目標是建模自然語言的概率分布&#xff0c;在自然語言處理研究中具有重要的作用&#xff0c;是自然 語言處理基礎任務之一…