有关于MSComm控件详解 wincc mscomm控件

Visual Basic: MSComm Control TheMSComm control provides serial communications for yourapplication by allowing the transmission and reception of datathrough a serial port.1.Error Messages (MS CommControl)

The following table lists the trappable errors for theMSComm control.

ConstantValueDescription
comInvalidPropertyValue380Invalid property value
comSetNotSupported383Property is read-only
comGetNotSupported394Property is read-only
comPortOpen8000Operation not valid while the port is opened
8001Timeout value must be greater than zero
comPortInvalid8002Invalid Port Number
8003Property available only at run time
8004Property is read only at runtime
comPortAlreadyOpen8005Port already open
8006The device identifier is invalid or unsupported
8007The device's baud rate is unsupported
8008The specified byte size is invalid
8009The default parameters are in error
8010The hardware is not available (locked by another device)
8011The function cannot allocate the queues
comNoOpen8012The device is not open
8013The device is already open
8014Could not enable comm notification
comSetCommStateFailed8015Could not set comm state
8016Could not set comm event mask
comPortNotOpen8018Operation valid only when the port is open
8019Device busy
comReadError8020Error reading comm device
comDCBError8021Internal error retrieving device control block for theport

2.Properties Description

Althoughthe MSComm control has many important properties, there area few that you should be familiar with first.

CommPortSets and returns the communications port number.
SettingsSets and returns the baud rate, parity, data bits, and stop bits asa string.
PortOpenSets and returns the state of a communications port. Also opens andcloses a port.
InputReturns and removes characters from the receive buffer.
OutputWrites a string of characters to the transmit buffer.


CommEvent

Returns the most recent communication event or error. This propertyis not available at design time and is read-only at run time.

Syntax

object.CommEvent

The CommEvent property syntax has these parts:

Part Description
object An object expression that evaluates to an object in theApplies To list.


Remarks

Although the OnComm event is generated whenever a communicationerror or event occurs, the CommEvent property holds the numericcode for that error or event. To determine the actual error orevent that caused the OnComm event, you must reference theCommEvent property.

The CommEvent property returns one of the following values forcommunication errors or events. These constants can also be foundin the Object Library for this control.

Communication errors include the following settings:

ConstantValueDescription
comEventBreak1001A Break signal was received.
有关于MSComm控件详解 wincc mscomm控件
comEventFrame1004Framing Error. The hardware detected a framing error.
comEventOverrun1006Port Overrun. A character was not read from thehardwarebefore the next character arrived and was lost.
comEventRxOver1008Receive Buffer Overflow. There is no room inthereceive buffer.
comEventRxParity1009Parity Error. The hardware detected a parity error.
comEventTxFull1010Transmit Buffer Full. The transmit buffer wasfullwhile trying to queue a character.
comEventDCB1011Unexpected error retrieving Device ControlBlock(DCB) for the port.


Communications events include the following settings:

ConstantValueDescription
comEvSend1There are fewer than Sthreshold numberofcharacters in the transmit buffer.
comEvReceive2Received Rthreshold number of characters. This eventisgenerated continuously until you use the Input propertytoremove the data from the receive buffer.
comEvCTS3Change in Clear To Send line.
comEvDSR4Change in Data Set Ready line. This event is onlyfiredwhen DSR changes from 1 to 0.
comEvCD5Change in Carrier Detect line.
comEvRing6Ring detected. Some UARTs (universalasynchronousreceiver-transmitters) may not support this event.
comEvEOF7End Of File (ASCII character 26) character received.


Data Type Integer


EOFEnable
The EOFEnable property determines if the MSComm control looks forEnd Of File (EOF) characters during input. If an EOF character isfound, the input will stop and the OnComm event will fire with theCommEvent property set to comEvEOF.

Syntax

object.EOFEnable [ = value ]

The EOFEnable property syntax has these parts:

Part Description
object An object expression that evaluates to an object in theApplies To list.
value A boolean expression that determines whether the OnComm eventis fired when an EOF character is found, as described inSettings.


Settings

The settings for value are:

Setting Description
True The OnComm event is fired when an EOF character isfound.
False (Default) The OnComm event isn't fired when an EOF characteris found.


Remarks

When EOFEnable property is set to False, the control will not scanthe input stream for EOF characters.

InBufferCount


Returns the number of characters waiting in the receive buffer.This property is not available at design time.

Syntax

object.InBufferCount[ = value ]

The InBufferCount property syntax has these parts:

Part Description
object An object expression that evaluates to an object in theApplies To list.
value An integer expression specifying the number of characterswaiting in the receive buffer.


Remarks

InBufferCount refers to the number of characters that have beenreceived by the modem and are waiting in the receive buffer for youto take them out. You can clear the receive buffer by setting theInBufferCount property to 0.

Note Do not confuse thisproperty with the InBufferSize property. The InBufferSize propertyreflects the total size of the receive buffer.

Data TypeInteger

InBufferSize


Sets and returns the size of the receive buffer in bytes.

Syntax

object.InBufferSize[ = value ]

The InBufferSize property syntax has these parts:

Part Description
object An object expression that evaluates to an object in theApplies To list.
value An integer expression specifying the size of the receivebuffer in bytes.


Remarks

InBufferSize refers to the total size of the receive buffer. Thedefault size is 1024 bytes. Do not confuse this property with theInBufferCount property which reflects the number of characterscurrently waiting in the receive buffer.

Note Note that the largeryou make the receive buffer, the less memory you have available toyour application. However, if your buffer is too small, it runs therisk of overflowing unless handshaking is used. As a general rule,start with a buffer size of 1024 bytes. If an overflow erroroccurs, increase the buffer size to handle your application'stransmission rate.

Data Type Integer

Input


Returns and removes a stream of data from the receive buffer. Thisproperty is not available at design time and is read-only at runtime.

Syntax

object.Input

The Input property syntax has these parts:

Part Description
object An object expression that evaluates to an object in theApplies To list.


Remarks

The InputLen property determines the number of characters thatare read by the Input property. Setting InputLen to 0 causes theInput property to read the entire contents of the receivebuffer.

The InputMode property determines the type of data that isretrieved with the Input property. If InputMode is set tocomInputModeText then the Input property returns text data in aVariant. If InputMode is comInputModeBinary then the Input propertyreturns binary data in an array of bytes in a Variant.

Data Type Variant


InputLen


Sets and returns the number of characters the Input property readsfrom the receive buffer.

Syntax

object.InputLen [ = value ]

The InputLen property syntax has these parts:

Part Description
object An object expression that evaluates to an object in theApplies To list.
value An integer expression specifying the number of characters theInput property reads from the receive buffer.


Remarks

The default value for the InputLen property is 0. SettingInputLen to 0 causes the MSComm control to read the entire contentsof the receive buffer when Input is used.

If InputLen characters are not available in the receive buffer,the Input property returns a zero-length string (""). The user canoptionally check the InBufferCount property to determine if therequired number of characters are present before using Input.

This property is useful when reading data from a machine whoseoutput is formatted in fixed-length blocks of data.

Data Type Integer


InputMode


Sets or returns the type of data retrieved by the Inputproperty.

Syntax

object.InputMode [ = value ]

The InputMode property syntax has these parts:

Part Description
object An object expression that evaluates to an object in theApplies To list.
value A value or constant that specifies the input mode, asdescribed in Settings.


Settings

The settings for value are:

Constant Value Description
comInputModeText 0 (Default) Data is retrieved through the Inputproperty as text.
comInputModeBinary 1 Data is retrieved through the Input propertyas binary data.


Remarks

The InputMode property determines how data will be retrievedthrough the Input property. The data will either be retrieved asstring or as binary data in a byte array.

Use comInputModeText for data that uses the ANSI character set.Use comInputModeBinary for all other data such as data that hasembedded control characters, Nulls, etc.


OutBufferCount


Returns the number of characters waiting in the transmit buffer.You can also use it to clear the transmit buffer. This property isnot available at design time.

Syntax

object.OutBufferCount [ = value ]

The OutBufferCount property syntax has these parts:

Part Description
object An object expression that evaluates to an object in theApplies To list.
value An integer expression specifying the number of characterswaiting in the transmit buffer.


Remarks

You can clear the transmit buffer by setting the OutBufferCountproperty to 0.

Note Do not confuse theOutBufferCount property with the OutBufferSize property whichreflects the total size of the transmit buffer.

Data Type Integer


OutBufferSize


Sets and returns the size, in bytes, of the transmit buffer.

Syntax

object.OutBufferSize [ = object ]

The OutBufferSize property syntax has these parts:

Part Description
object An object expression that evaluates to an object in theApplies To list.
value An integer expression specifying the size of the transmitbuffer.


Remarks

OutBufferSize refers to the total size of the transmit buffer.The default size is 512 bytes. Do not confuse this property withthe OutBufferCount which reflects the number of bytes currentlywaiting in the transmit buffer.

Note The larger you make thetransmit buffer, the less memory you have available to yourapplication. However, if your buffer is too small, you run the riskof overflowing unless you use handshaking. As a general rule, startwith a buffer size of 512 bytes. If an overflow error occurs,increase the buffer size to handle your application's transmissionrate.

Data Type Integer


Output


Writes a stream of data to the transmit buffer. This property isnot available at design time and is write-only at run time.

Syntax

object.Output [ = value ]

The Output property syntax has these parts:

Part Description
object An object expression that evaluates to an object in theApplies To list.
value A string of characters to write to the transmit buffer.


Remarks

The Output property can transmit text data or binary data. Tosend text data using the Output property, you must specify aVariant that contains a string. To send binary data, you must passa Variant which contains a byte array to the Output property.

Normally, if you are sending an ANSI string to an application,you can send it as text data. If you have data that containsembedded control characters, Null characters, etc., then you willwant to pass it as binary data.

Data Type Variant

RThreshold


Sets and returns the number of characters to receive before theMSComm control sets the CommEvent property to comEvReceive andgenerates the OnComm event.

Syntax

object.Rthreshold [ = value ]

The Rthreshold property syntax has these parts:

Part Description
object An object expression that evaluates to an object in theApplies To list.
value An integer expression specifying the number of characters toreceive before generating the OnComm event.


Remarks

Setting the RThreshold property to 0 (the default) disablesgenerating the OnComm event when characters are received.

Setting RThreshold to 1, for example, causes the MSComm controlto generate the OnComm event every time a single character isplaced in the receive buffer.

Data Type Integer

SThreshold


Sets and returns the minimum number of characters allowable in thetransmit buffer before the MSComm control sets the CommEventproperty to comEvSend and generates the OnComm event.

Syntax

object.SThreshold [ = value ]

The SThreshold property syntax has these parts:

Part Description
object An object expression that evaluates to an object in theApplies To list.
value An integer expression representing the minimum number ofcharacters in the transmit buffer before the OnComm event isgenerated.


Remarks

Setting the SThreshold property to 0 (the default) disablesgenerating the OnComm event for data transmission events. Settingthe SThreshold property to 1 causes the MSComm control to generatethe OnComm event when the transmit buffer is completely empty.

If the number of characters in the transmit buffer is less thanvalue, the CommEvent property is set to comEvSend, and the OnCommevent is generated. The comEvSend event is only fired once, whenthe number of characters crosses the SThreshold. For example, ifSThreshold equals five, the comEvSend event occurs only when thenumber of characters drops from five to four in the output queue.If there are never more than SThreshold characters in the outputqueue, the event is never fired.

Data Type Integer

  

爱华网本文地址 » http://www.aihuau.com/a/25101011/44220.html

更多阅读

SQL Server SQL触发器经验详解 sqlserver 触发器调试

【SQL Server】SQL触发器经验详解——简介自从上次在经验中使用了触发器,有读者询问我一些关于触发器的相关信息,个人推荐首先你需要先去把触发器最基础的东西了解清楚,然后通过这次的经验,希望能在你理解的基础上,加深你对触发器的了解,

开通QQ会员有什么好处?详解 qq会员开通活动

开通QQ会员有什么好处?【详解】——简介普通QQ用户只能使用QQ的基本功能服务,开通QQ会员后,就可以享受高级QQ服务功能了。开通QQ会员的账号,有多种好处,下面一一道来。开通QQ会员有什么好处?【详解】——好处开通QQ会员有什么好处?【详解

广告联盟赚钱初识及如何加入详解 广告联盟骗局

广告联盟赚钱初识及如何加入详解——简介现在网络上出现的“广告联盟”,究竟是什么意思?传说的能赚钱到底是真是假?又有哪些广告联盟呢?下面,小编就和大家一一道来。广告联盟赚钱初识及如何加入详解——工具/原料电脑互联网广告联盟赚

声明:《有关于MSComm控件详解 wincc mscomm控件》为网友独守寂寥分享!如侵犯到您的合法权益请联系我们删除