set_serial_paramT_set_serial_paramSetSerialParamSetSerialParamset_serial_param (算子)
名称
set_serial_paramT_set_serial_paramSetSerialParamSetSerialParamset_serial_param — 设置串行设备的参数。
签名
void SetSerialParam(const HTuple& SerialHandle, const HTuple& BaudRate, const HTuple& DataBits, const HTuple& FlowControl, const HTuple& Parity, const HTuple& StopBits, const HTuple& TotalTimeOut, const HTuple& InterCharTimeOut)
void HSerial::SetSerialParam(const HTuple& BaudRate, const HTuple& DataBits, const HString& FlowControl, const HString& Parity, const HTuple& StopBits, const HTuple& TotalTimeOut, const HTuple& InterCharTimeOut) const
void HSerial::SetSerialParam(Hlong BaudRate, Hlong DataBits, const HString& FlowControl, const HString& Parity, Hlong StopBits, Hlong TotalTimeOut, Hlong InterCharTimeOut) const
void HSerial::SetSerialParam(Hlong BaudRate, Hlong DataBits, const char* FlowControl, const char* Parity, Hlong StopBits, Hlong TotalTimeOut, Hlong InterCharTimeOut) const
void HSerial::SetSerialParam(Hlong BaudRate, Hlong DataBits, const wchar_t* FlowControl, const wchar_t* Parity, Hlong StopBits, Hlong TotalTimeOut, Hlong InterCharTimeOut) const
(
Windows only)
static void HOperatorSet.SetSerialParam(HTuple serialHandle, HTuple baudRate, HTuple dataBits, HTuple flowControl, HTuple parity, HTuple stopBits, HTuple totalTimeOut, HTuple interCharTimeOut)
void HSerial.SetSerialParam(HTuple baudRate, HTuple dataBits, string flowControl, string parity, HTuple stopBits, HTuple totalTimeOut, HTuple interCharTimeOut)
void HSerial.SetSerialParam(int baudRate, int dataBits, string flowControl, string parity, int stopBits, int totalTimeOut, int interCharTimeOut)
def set_serial_param(serial_handle: HHandle, baud_rate: Union[int, str], data_bits: Union[int, str], flow_control: str, parity: str, stop_bits: Union[int, str], total_time_out: Union[int, str], inter_char_time_out: Union[int, str]) -> None
描述
set_serial_paramset_serial_paramSetSerialParamSetSerialParamSetSerialParamset_serial_param can be used to set the parameters of a
serial device. The parameter BaudRateBaudRateBaudRateBaudRatebaudRatebaud_rate determines the input
and output speed of the device. It should be noted that not all
devices support all possible speeds. The number of sent and
received data bits is set with DataBitsDataBitsDataBitsDataBitsdataBitsdata_bits. The parameter
FlowControlFlowControlFlowControlFlowControlflowControlflow_control determines if and what kind of data flow
control should be used. Software control ('xon_xoff'"xon_xoff""xon_xoff""xon_xoff""xon_xoff""xon_xoff")
and hardware control ('cts_rts'"cts_rts""cts_rts""cts_rts""cts_rts""cts_rts" and 'dtr_dsr'"dtr_dsr""dtr_dsr""dtr_dsr""dtr_dsr""dtr_dsr")
can be used. Multiple values can be set separated by a space
within one string (e.g., 'cts_rts dtr_dsr'"cts_rts dtr_dsr""cts_rts dtr_dsr""cts_rts dtr_dsr""cts_rts dtr_dsr""cts_rts dtr_dsr").
If and what
kind of parity check of the transmitted data should be performed can
be determined by ParityParityParityParityparityparity. The number of stop bits sent is
set with StopBitsStopBitsStopBitsStopBitsstopBitsstop_bits. Finally, two timeout for reading from
the serial device can be set. The parameter TotalTimeOutTotalTimeOutTotalTimeOutTotalTimeOuttotalTimeOuttotal_time_out
determines the maximum time, which may pass in read_serialread_serialReadSerialReadSerialReadSerialread_serial
until the first character arrives, independent of the actual number
of characters requested. The parameter InterCharTimeOutInterCharTimeOutInterCharTimeOutInterCharTimeOutinterCharTimeOutinter_char_time_out
determines the time which may pass between the reading of individual
characters, if multiple characters are requested with
read_serialread_serialReadSerialReadSerialReadSerialread_serial。If one of the timeouts is set to -1,
the system waits an arbitrary amount of time for the arrival of
characters. If both timeouts are set to 0 the system
doesn't wait and returns the available or none characters. Thus, on
Windows systems, a total timeout of TotalTimeOutTotalTimeOutTotalTimeOutTotalTimeOuttotalTimeOuttotal_time_out + n
InterCharTimeOutInterCharTimeOutInterCharTimeOutInterCharTimeOutinterCharTimeOutinter_char_time_out results if n characters are to be read.
On Unix-like systems, only one of the two timeouts can be set. Thus, if
both timeouts are passed larger than -1, only the total timeout is
used. The unit of both timeouts is milliseconds. It should be
noted, however, that the timeout is specified in increments of one
tenths of a second on Unix-like systems, i.e., the minimum timeout
that has any effect is 100. For each parameter, the
current values can be left in effect by passing
'unchanged'"unchanged""unchanged""unchanged""unchanged""unchanged".
执行信息
- 多线程类型:可重入(与非独占算子并行运行)。
- 多线程作用域:全局(可从任何线程调用)。
- 未采用并行化处理。
此算子修改后续输入参数的状态:
在执行此算子时,若该参数值需在多个线程间使用,则必须对其访问进行同步。
参数
SerialHandleSerialHandleSerialHandleSerialHandleserialHandleserial_handle (输入控制,状态被修改) serial → HSerial, HTupleHHandleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)
Serial interface handle.
BaudRateBaudRateBaudRateBaudRatebaudRatebaud_rate (输入控制) integer → HTupleUnion[int, str]HTupleHtuple (integer / string) (int / long / string) (Hlong / HString) (Hlong / char*)
Speed of the serial interface.
默认值:
'unchanged'
"unchanged"
"unchanged"
"unchanged"
"unchanged"
"unchanged"
值列表:
50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, 38400, 57600, 76800, 115200, 153600, 230400, 307200, 460800, 'unchanged'"unchanged""unchanged""unchanged""unchanged""unchanged"
DataBitsDataBitsDataBitsDataBitsdataBitsdata_bits (输入控制) integer → HTupleUnion[int, str]HTupleHtuple (integer / string) (int / long / string) (Hlong / HString) (Hlong / char*)
Number of data bits of the serial interface.
默认值:
'unchanged'
"unchanged"
"unchanged"
"unchanged"
"unchanged"
"unchanged"
值列表:
5, 6, 7, 8, 'unchanged'"unchanged""unchanged""unchanged""unchanged""unchanged"
FlowControlFlowControlFlowControlFlowControlflowControlflow_control (输入控制) string → HTuplestrHTupleHtuple (string) (string) (HString) (char*)
Type of flow control of the serial interface.
默认值:
'unchanged'
"unchanged"
"unchanged"
"unchanged"
"unchanged"
"unchanged"
值列表:
'cts_rts dtr_dsr xon_xoff'"cts_rts dtr_dsr xon_xoff""cts_rts dtr_dsr xon_xoff""cts_rts dtr_dsr xon_xoff""cts_rts dtr_dsr xon_xoff""cts_rts dtr_dsr xon_xoff", 'cts_rts dtr_dsr'"cts_rts dtr_dsr""cts_rts dtr_dsr""cts_rts dtr_dsr""cts_rts dtr_dsr""cts_rts dtr_dsr", 'cts_rts xon_xoff'"cts_rts xon_xoff""cts_rts xon_xoff""cts_rts xon_xoff""cts_rts xon_xoff""cts_rts xon_xoff", 'cts_rts'"cts_rts""cts_rts""cts_rts""cts_rts""cts_rts", 'dtr_dsr xon_xoff'"dtr_dsr xon_xoff""dtr_dsr xon_xoff""dtr_dsr xon_xoff""dtr_dsr xon_xoff""dtr_dsr xon_xoff", 'dtr_dsr'"dtr_dsr""dtr_dsr""dtr_dsr""dtr_dsr""dtr_dsr", 'none'"none""none""none""none""none", 'unchanged'"unchanged""unchanged""unchanged""unchanged""unchanged", 'xon_xoff'"xon_xoff""xon_xoff""xon_xoff""xon_xoff""xon_xoff"
ParityParityParityParityparityparity (输入控制) string → HTuplestrHTupleHtuple (string) (string) (HString) (char*)
Parity of the serial interface.
默认值:
'unchanged'
"unchanged"
"unchanged"
"unchanged"
"unchanged"
"unchanged"
值列表:
'even'"even""even""even""even""even", 'none'"none""none""none""none""none", 'odd'"odd""odd""odd""odd""odd", 'unchanged'"unchanged""unchanged""unchanged""unchanged""unchanged"
StopBitsStopBitsStopBitsStopBitsstopBitsstop_bits (输入控制) integer → HTupleUnion[int, str]HTupleHtuple (integer / string) (int / long / string) (Hlong / HString) (Hlong / char*)
Number of stop bits of the serial interface.
默认值:
'unchanged'
"unchanged"
"unchanged"
"unchanged"
"unchanged"
"unchanged"
值列表:
1, 2, 'unchanged'"unchanged""unchanged""unchanged""unchanged""unchanged"
TotalTimeOutTotalTimeOutTotalTimeOutTotalTimeOuttotalTimeOuttotal_time_out (输入控制) integer → HTupleUnion[int, str]HTupleHtuple (integer / string) (int / long / string) (Hlong / HString) (Hlong / char*)
Total timeout of the serial interface in ms.
默认值:
'unchanged'
"unchanged"
"unchanged"
"unchanged"
"unchanged"
"unchanged"
建议值:
-1, 0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 'unchanged'"unchanged""unchanged""unchanged""unchanged""unchanged"
InterCharTimeOutInterCharTimeOutInterCharTimeOutInterCharTimeOutinterCharTimeOutinter_char_time_out (输入控制) integer → HTupleUnion[int, str]HTupleHtuple (integer / string) (int / long / string) (Hlong / HString) (Hlong / char*)
Inter-character timeout of the serial interface
in ms.
默认值:
'unchanged'
"unchanged"
"unchanged"
"unchanged"
"unchanged"
"unchanged"
建议值:
-1, 0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 'unchanged'"unchanged""unchanged""unchanged""unchanged""unchanged"
结果
If the parameters are correct and the parameters of the device could
be set, the operator set_serial_paramset_serial_paramSetSerialParamSetSerialParamSetSerialParamset_serial_param 返回值 2 ( H_MSG_TRUE )。否则将抛出异常。
可能的前趋
open_serialopen_serialOpenSerialOpenSerialOpenSerialopen_serial,
get_serial_paramget_serial_paramGetSerialParamGetSerialParamGetSerialParamget_serial_param
可能的后继
read_serialread_serialReadSerialReadSerialReadSerialread_serial,
write_serialwrite_serialWriteSerialWriteSerialWriteSerialwrite_serial
另见
get_serial_paramget_serial_paramGetSerialParamGetSerialParamGetSerialParamget_serial_param
模块
基础