|
SetChannelSettings |
|
|
Change the current communication channel settings: provide a new COM port number or TCP/IP address, or change the serial port settings (baud rate, parity settings, ...).
NOTE: For most applications it is not necessary to use SetChannelSettings or its companion, GetChannelSettings. Communication parameters can be chosen in the Project Settings dialog, and stored in the Docklight project file (see Saving and Loading Your Project Data and the Open Project method).
Return Value
Boolean
Syntax
result = DL.SetChannelSettings( newSettings [, channelNo] [, dontTest])
The SetChannelSettings method syntax has these parts:
The newSettings argument accepts the following values:
Remarks
You can only change the channel settings while the communication is stopped (see StopCommunication).
The SetChannelSettings method is intended for advanced Docklight Scripting applications, where control of the communication channel settings during script runtime is required. It allows you to create scripts that access different COM ports (see example below), or walk through a list of IP addresses.
SetChannelSettings method will produce an error, if an illegal value is passed with newSettings.
If the newSettings argument is ok (and the dontTest flag is not set), the communication channel will be opened and closed again immediately for a test.
If dontTest is True, SetChannelSettings will not open/close the channel for testing, and return always True. This is useful in networking applications, where additional connect/disconnect attempts might confuse the other host/device. Problems have been experienced for example with Telnet server applications.
The return value of SetChannelSettings is True, if the channel could be successfully opened. The return value is False, if an error occurred while trying to access the port (e.g. the COM port already in use, or the Firewall denied the TCP/IP access).
NOTE: Modifying the FlowControl parameter when Project Settings: Flow Control is other than "Off" can result in undefined behavior.
See also GetChannelSettings and GetChannelStatus.
Example
' Example SetChannelSettings / GetChannelSettings ' (requires Docklight in Send/Receive mode)
DL.ClearCommWindows
DL.AddComment "Searching for first COM port available on this PC..." portAvailable = DL.SetChannelSettings("COM1:9600,NONE,8,1") While Not portAvailable oldPort = DL.GetChannelSettings() ' try next COM port portAvailable = DL.SetChannelSettings(">") newPort = DL.GetChannelSettings() ' tried out already all COM ports on this PC? If (oldPort = newPort) Then DL.AddComment "No COM port available" DL.Quit End If Wend DL.AddComment "Using COM port " & DL.GetChannelSettings()
' Try a few different baud rates baudRatesStr = "9600,14400,57600,115200" baudRatesArray = Split(baudRatesStr, ",") For i = 0 To UBound(baudRatesArray) ' Tweak the serial port settings DL.SetChannelSettings(baudRatesArray(i) + ",NONE,8,1") DL.AddComment DL.AddComment DL.AddComment "Testing with settings " & DL.GetChannelSettings() ' Send a modem test command and allow some waiting time for the answer DL.StartCommunication DL.SendSequence "", "ATI3" + Chr(13) + Chr(10) DL.Pause 200 DL.StopCommunication Next
After running the script on a computer with a built-in modem on COM3, the Docklight communication window could look like this:
Searching for first COM port available on this PC... Using COM port COM3:9600,NONE,8,1
Testing with settings COM3:9600,NONE,8,1
28.01.2008 16:28:36.26 [TX] - ATI3<CR><LF>
28.01.2008 16:28:36.26 [RX] - ATI3<CR> <CR><LF> Agere SoftModem Version 2.1.46<CR><LF> <CR><LF> OK<CR><LF>
Testing with settings COM3:14400,NONE,8,1
28.01.2008 16:28:37.46 [TX] - ATI3<CR><LF>
28.01.2008 16:28:37.46 [RX] - ATI3<CR> <CR><LF> Agere SoftModem Version 2.1.46<CR><LF> <CR><LF> OK<CR><LF>
Testing with settings COM3:57600,NONE,8,1
28.01.2008 16:28:38.60 [TX] - ATI3<CR><LF>
28.01.2008 16:28:38.60 [RX] - ATI3<CR> <CR><LF> Agere SoftModem Version 2.1.46<CR><LF> <CR><LF> OK<CR><LF>
Testing with settings COM3:115200,NONE,8,1
28.01.2008 16:28:39.73 [TX] - ATI3<CR><LF>
28.01.2008 16:28:39.73 [RX] - ATI3<CR> <CR><LF> Agere SoftModem Version 2.1.46<CR><LF> <CR><LF> OK<CR><LF>
|