本站所列毕业设计(论文)资料均属于原创者所有,初衷是为大家在毕业设计(论文)过程中参考和学习交流之用。

毕业设计我帮你

MCGS嵌入版概述MCGS组态软件相关技术--MCGS串口父设备使用技巧

www.bysj580.com / 2016-11-14
MCGS组态软件相关技术--MCGS串口父设备使用技巧
 
(1)通用串口父设备
通用串口父设备是提供串口通讯功能父设备,下面可以挂接所有串口连接设备,提供Modem进行远程采集或远程监听功能。并可以运行时动态改变拨出电话号码。

基本属性页中,设置了串口基本属性,包括端口号,通讯波特率,数据位位数,停止位位数,数据校验方式,这些设置可以设备要求来设置。
数据采集方式规定了串口父设备下子设备采集方式,使用同步采集时,所有子设备都父设备采集周期依次采集。使用异步采集时,每个子设备可以设置自己采集时间,需要时候采集。子设备可以把采集时间设置为0,使此子设备一般情况下不采集,只使用设备命令采集一次时候才采集数据。
使用串口来进行通讯,进行这些设置就足够了。想要使用MCGS内建电话访问功能,就需要进行电话连接属性页设置。
这一页设置中,不选择第一个选择框“使用Modem通讯”,就只能使用RTS延时控制功能,选择使用RTS延时控制后,可以设置两个等待时间,这两个等待时间作用是对RTS信号进行翻转后,延时等待时间,这两个时间分别为t1和t2,则整个通讯过程为:RTS信号开,延时t1毫秒后,上位机开始发送数据,数据发送完毕后,延时t2毫秒后,RTS信号关,上位机开始等待数据到达。此功能主要使用于半双工无线电台,部分Hart-232转换器和部分半双工通讯转换器,这些转换器都要求数据发送前,RTS上建立高电平信号,通知转换器处于发送状态,发送完毕后,接收数据前,把RTS信号置低,使转换器处于接收状态。仔细调整延时时间长短,可以保证系统工作稳定可靠。
选择了选项” 使用Modem通讯”,则可以使用Modem来进行Modem通讯。
选择使用Modem通讯之后,以下一些功能就可以设置了。
子设备电话号码:这里设置每个子设备电话号码。设置了电话号码子设备采集或处理设备命令时,将自动拨通这个电话,然后进行设备采集处理。没有设置电话号码,则这个子设备设备主动拨通上位机时才能通讯(所有硬件设备都能主动拨通上位机)。电话号码中可以使用各种AT拨号字符,如:0,804表示先拨0,等待拨号音响起,然后再拨剩下电话号码804,这个功能可以用于分机拨外线时拨号。
通讯后挂断电话:使用这个选项,当子设备拨通自己电话号码并完成采集工作后,将挂断电话。这个性能主要应用于每个子设备自己有自己电话号码,电话线不宜长时间占用情况,如使用Modem整点时查询一组设备值,之后挂断电话,就应该使用这个选项。想要使用Modem连续采集某个设备值,直到改变连接到另一个设备为止,就应该去掉这个选项,否则子设备每次通讯都会重新拨号。
电话占线时重试:使用这个选项,可以通讯时,遇到对方电话占线后,等待规定秒数后,重新拨号,通常,等待一到两分钟后重试,重试次数3次左右比较合适。
错误状态输出连接:使用这个选项,并连接一个字符串变量后,串口通讯父设备拨号时,将把当前拨号状态输出到这个字符串变量中。
响铃次数:响铃次数设定了上位机监听状态时,电话响铃多少次后接听电话,通常设置为1次。
初始化远程MODEM:使用这个按钮,可以当前串口设置,响铃次数来初始化远程使用Modem。
串口通讯父设备设备命令:
    1)ChangePort(端口号)
    这个命令将运行时改变串口父设备连接串口。端口号是一个数值,1对应端口1,2对应端口2,依次类推。
    2)ChangePhone(子设备名,电话号码)
    使用这个命令可以运行时改变子设备连接电话号码。
    这个设备命令是发送给父设备,电话号码部分直接写改变后电话号码,也可以连接字符型变量,但要把其改为字符串。例如:ChangePhone(子设备名,”+phone+”),其中phone是字符型变量。
    特别要注意是,挂断电话时,设备命令为ChangePhone(子设备名,)
    3)CallPhone(电话号码字符串)
    命令串口通讯父设备拨通指定电话号码。使用这个命令时,应该配置串口父设备不使用Modem通讯,否则内建Modem通讯策略会覆盖这个电话号码。
    这个命令通常用于完全由设备命令来建立电话连接。
    4) ListenPhone()
    命令串口通讯父设备挂断电话并处于接听状态。与上一个命令CallPhone一样,这个命令通常只完全由设备命令来建立电话连接时使用。
    使用Modem进行通讯,有多种连接方式,通讯呼出与建立方式,拨号时间安排以及拨号号码变化。针对这些通讯方式使用,下面来一一列举使用方法。
    首先,进行这些试验,需要准备如下器材:Modem两台或更多(需要进行多台设备轮巡拨号采集),建议使用外置Modem,这样可以方便观察Modem状态,也能够排除内置Modem安装不正确引起一系列问题,另外,某些非常便宜Modem尤其是软Modem,缺少保留Modem设置功能,不能用于远程数据通讯。电话线两根或更多(轮巡拨号),也可以使用一台小型电话交换机。需要通讯设备,如西门子PLC S7-200,需要通讯设备是485协议,还需要准备485转换模块(S7-200PLC就需要这个转换模块),以及用于组态计算机一台,用于连接电线若干。
    其次,我们需要明确几个概念:
    1、 上位机,用于上位通讯计算机,通常就是用户组态使用计算机。
    2、 远程设备,本例里,就是S7-200。
    3、 本Modem,232接口与上位机连接Modem。
    4、 远程Modem,232接口与远程设备连接Modem,本例里,还需要232-485转换模块。
实验1:使用MCGS远程采集功能来采集S7-200数据。
    1) 检查PLC设备和485转换模块是否正常。
    设备组态窗口中,创建一个串口通讯父设备,父设备下面创建一个S7-200 PPI子设备,子设备属性对话框中,按下帮助按钮,可以弹出S7-200使用帮助,S7-200 PPI驱动中帮助,设置串口通讯父设备串口号和波特率,以及子设备址号,以本通讯方式与S7-200设备建立通讯连接,然后S7-200中帮助进行硬件连接,组态和连接全部正确,通讯测试页中,可以看到通讯成功标志。通讯不成功,可以S7-200驱动帮助,排除错误。
    2) 初始化远程Modem。
    从串口上取下与232-485转换模块连线,连接上一个Modem,准备把他初始化成远程Modem。打开上一步组态串口通讯父设备属性页,切换到第二页电话连接,选择使用电话连接。按下初始化远程Modem按钮,MCGS将串口父设备中有关波特率,校验,以及等待响铃次数等设置初始化远程Modem,此时应该注意这些配置与设备通讯要求配置一致。短暂发送数据后,MCGS将报告远程Modem初始化是否成功。不成功,应该检查一下连线是否正确,连线正确,初始化Modem按钮按下瞬间,Modem发送和接收指示灯应该短暂闪烁。发送和接收指示灯闪烁而仍然报告初始化不成功,说明Modem没有能够正确处理MCGS发出AT指令,某些过分便宜Modem中,经常容易内部Flash存储器失效而引起这些问题。
    初始化Modem成功后,断开Modem电源,从计算机上取下Modem,然后,没有连接任何设备情况下,给Modem上电,此时,Modem上AA灯(自动应答指示)应该点亮,否则,此Modem不会自动接听电话。
    同时,Modem上TR灯(终端就绪指示)也应该点亮,否则Modem会接听电话,某些Modem中会发生这种情况。发生这种情况,最好办法是更换Modem,必须要使用这个Modem,应该把这个Modem第4脚和第6脚连通,这样,人为提供了一个终端就绪信号,这就使TR灯点亮了。
    此时,给这个Modem插上电话线,向这条电话线拨号,这个Modem应该自动接听,并发出Modem握手声音。否则说明Modem初始化没有成功,可以换一个其他型号Modem来测试。
    3) 连接远程设备
    把远程Modem和232-485转换模块连接起来,注意,必须把Modem发送脚连接到转换模块接收脚,把Modem接收脚连接到转换模块发送脚。把232-485转换模块和S7-200连接起来(这第一步中应该已经完成了)。
    4) 连接本Modem
把另一个Modem连接到上位机上,并把电话线连接好。
    5) 测试通讯
    串口通讯父设备属性页中,填写S7-200子设备对应电话号码。选择错误状态输出,然后连接到一个字符型变量上,运行环境中提示拨号状态。关闭父设备属性页,打开子设备属性页,切换到测试页上,MCGS应该向Modem发送数据,开始拨号,拨号完毕后,远程Modem应该自动应答,并接听电话,开始Modem握手过程。这个过程没有正确进行,可能原因包括:1、计算机上有其他程序如超级终端占用了串口;串口号不正确;
    Modem握手过程完成后,应该看到两边Modem发送灯和接收灯闪烁,进行持续通讯。握手过程完成后Modem立即挂断,通常是远程Modem载波检测错误引起,这种情况某些Modem上会发生。更换一个远程Modem或把远程Modem第一脚和第六脚短接,强制远程Modem载波检测。
    连通后,两边Modem不停发送数据,没有数据接收,可能原因是远程Modem初始化状态不正确,请确认初始化远程Modem时,波特率,校验位,数据位,停止位是设置成需要状态。
    连通后,两边Modem不停发送和接收数据,MCGS仍然报告通讯错误,原因可能是Modem加入时延导致设备通讯时序不正确,此时,串口通讯父设备组态当中,选择使用RTS延时控制,仔细调节RTS关闭延时为大约150~250毫秒之间,就可以建立起通讯。
    6) 实际运行
    组态环境中连接一些PLC变量,并界面上组态显示这些变量以及错误输出变量,切换到运行环境中,可以看到MCGS自动建立拨号连接,并开始采集数据。
实验2:整点定时采集PLC设备
    1) 首先完成实验1内步骤。
    2) 串口通讯父设备属性页中,选择异步采集数据。并选择通讯后挂断电话
    3) 子设备属性页中,设置采集时间为0。
    4) 组态一个定时整点运行策略,策略中,调用子设备采集一次。
    5) 进入运行并等待整点,此时MCGS将自动拨号,完成一次子设备采集,然后挂断电话。
实验3:动态设定电话号码
    1) 完成实验1内步骤
    2) 需要改变子设备连接电话号码时,向父设备发送设备命令ChangeChildPhone(子设备名,电话号码字符串)。此时子设备将自动更换电话号码,注意电话号码要使用双引号括起来。 
 MCGS configuration software, related technology, the MCGS father serial devices using skills
 
1 general serial parent equipment general serial port serial communication function parent the parent equipment is provided, the following can be articulated all serial ports connected devices, provide a Modem for remote acquisition or remote monitor function. And can run time dynamic change dial out phone number.
Basic properties page, set the serial port basic attributes, including port number, communication baud rate, data bits digit, stop bit figures, data validation, these Settings can be set equipment requirements. Specifies the serial port data acquisition methods are father following equipment acquisition methods, using synchronous acquisition, all child devices are parent equipment acquisition cycle collection in turn. When using asynchronous acquisition, each device can set their acquisition time, need time to collect. Child device can put the acquisition time is set to 0, make the child devices usually does not collect, only use the equipment ordered collection when collecting data at a time. Using a serial port to communicate, these Settings will be enough. Want to use the MCGS built-in phone access function, you need to phone connection properties page Settings.
Settings in this page, not to choose the first option box "USES Modem communications", can only use the RTS delay control function, choose to use RTS delay control after, you can set the two waiting time, the waiting time is used to flip the RTS signal after the delay waiting time, the two time t1 and t2, respectively, for the entire communication process: the RTS signal, delay the t1 milliseconds later, PC start sending data, the data is sent after the delay t2 milliseconds later, the RTS signal, PC start to wait for data to arrive. This function is mainly used in half-duplex wireless radio, parts Hart - 232 converter and half duplex communication converter, the converter is required before sending data, RTS on a high level signal, notify the converter in the sending state, after sending, receiving data, put the RTS signal is low, the converter in the receiving state. Carefully adjust the delay time length, can ensure system work stable and reliable. Choose the option "use Modem communications", you can use Modem for Modem communication.
As shown in figure, choose to use a Modem communication, the following functions can be set up. A device number: here set each equipment number. Set up a phone number collection or processing equipment orders, will automatically dial the telephone, then equipment acquisition processing. Son does not set a phone number, the equipment can initiative called upper machine communication (all hardware devices are able to take the initiative called PC). Dial phone Numbers can be used in all kinds of ats characters, such as: 0804 dial 0 first, wait for dialing sound, then you dial the phone number left in 804, this feature can be used to dial extension dial an outside. Hang up the phone after communication: use this option, when the equipment is called his phone number and complete the acquisition work, will hang up the phone. This performance is mainly used in each equipment you have his phone number, telephone line shoulds not be long time usage, such as using the Modem the hour query values to a set of equipment, then hang up the phone, you should use this option. Want to use the Modem value of the equipment for collecting a, until change connection to another device, you should remove this option, otherwise equipment every communication dial again. Retry when the line was busy: use this option, can communication, meet each other after the line is busy, wait for after the specified number of seconds, redial, usually, retry after waiting for a minute or two, retries about 3 times more appropriate. Error status output connection: use this option, and connect a string variable, dial device, serial port communication father will dial the current state of the output to the string variable. Ring a bell ring number: the number listening state set up the upper machine, the phone ring many times after answering the telephone, usually set to 1. Can initialize remote MODEM: use this button, the current serial port Settings, ring number to initialize remote use MODEM.
A serial port communication equipment command: father ChangePort l (port number) this command will run time change a serial port parent device to connect a serial port. Port number is a number, 1 corresponding port corresponding port 1, 2, 2, and so on. L ChangePhone (a device name, phone number) to use this command to run when device to connect telephone number change. Command is sent to the parent and the devices, the phone number part writing changed phone number directly, also can connect character variables, but to change it to a string. For example: ChangePhone (a device name, "+ phone +"), the phone is a character variable. Paying special attention to is, when hang up the phone, equipment orders for ChangePhone (a device name,) l CallPhone parent device (phone number string) command serial interface communication dial phone number specified. Father when using this command, you should configure a serial port equipment does not use the Modem communications, or built-in Modem communications strategy will cover the phone number. This command is often used to complete command of equipment to set up telephone connections. L ListenPhone parent () command serial interface communication equipment hang up the phone and in a state of answer. With a command on the CallPhone, this command is usually only completely command to set up the telephone connection of equipment to use. Using Modem communication, there are a variety of connection, communication exhaled and build mode, dial time arrangement and dialing number changes. According to these communication methods used, to list using the methods below. First of all, these tests are carried out, need to prepare the following equipment: Modem two or more (the need for multiple devices wheel round dial collection), it is recommended to use external Modem, so that we can convenient to observe Modem state, also can eliminate the built-in Modem installation is not correct cause a series of problems, in addition, some very cheap Modem soft Modem, in particular, the lack of reserve Modem Settings function, cannot be used for remote data communication. Cruise dial-up telephone line of two or more (round), can also use a small telephone exchange. Need to communication equipment, such as Siemens PLC S7-200, need to communication equipment is 485 agreement, you also need to prepare 485 conversion module (S7-200 PLC requires the transformation module), and used to configure a computer, some used to connect wire. Second, we need to clear some concepts: 1, the upper machine, used for upper computer communication, users usually is configured to use a computer. 2, the remote device, in this case, it is S7-200. 3, this Modem, 232 interface and PC connected to the Modem. 4, remote modems, 232 interface and remote device connected to the Modem, in this case, you also need to 232-485 conversion module.
Experiment 1: use the MCGS remote to S7-200 data acquisition function. 1, check the PLC device and 485 conversion module is normal. Equipment configuration window, to create a parent device serial communication, the parent equipment below to create a S7-200 PPI equipment, the equipment properties dialog, press the help button, popup S7-200 can be used to help, help in S7-200 PPI driver set the parent equipment serial number and the serial communication baud rate, and the device address number, with this communication way establishing connection with S7-200 equipment, then help with S7-200 hardware connection, configuration and connection is correct, all communications test page, you can see the communication success marks. Communication is not successful, can help drive S7-200, rule out mistakes. 2, initialize remote Modem. Down from the serial port and 232-485 conversion module connection, connected to a Modem, ready to put his initialize remote Modem. Open the parent step configuration on the serial interface communication device properties page, switch to the second page phone connection, choose to use a telephone connection. Initialize remote Modem button, the MCGS will father serial port device in the baud rate, parity, and waiting for the ring initialization Settings such as remote Modem times, this time should pay attention to these configuration configuration with the device communication request. After brief sends data, the MCGS remote Modem will report the initialization was successful. Don't succeed, you should check the attachment whether it is right, the attachment is correct, initializing Modem button momentarily, Modem sends and receives flashing lights should is short. Sending and receiving light is flashing and still report initialization is not successful, that Modem failed to correctly handle the MCGS the AT command, some excessively cheap Modem, often easy to internal Flash memory failure caused by these problems. Disconnect the Modem initialization after the success of the Modem power, removed from the computer Modem, and then, without any device connected to the Modem with electricity, at this point, the Modem on AA light should light up (to be automatic reply instructions), otherwise, the Modem will not automatically answer the phone. At the same time, the Modem on the TR lamp (terminal ready instructions) should also be lit, or Modem will answer the phone, this situation would happen in certain Modem. This happens, the best way is to replace the Modem, must want to use the Modem, should put the feet and 6 feet 4 Modem connected, so people provides a ready signal terminal, which makes the TR lamp lighted up. At this point, to plug in the Modem telephone line and dial the telephone, the Modem should be answered automatically, and Modem shake hands sounds. Otherwise the Modem initialization failed, can change a other model Modem to test. 3, and 232-485 to connect to a remote device to remote Modem transformation module connected, notice that must be the Modem connected to the converter module receive send the feet, the Modem is connected to the converter module to send receive the feet. The 232-485 conversion module and S7-200 to connect (which ought to have been completed in the first step). 4. Connect the Modem to another Modem to connect to the upper machine, and the phone connection is good. 5 parent communication serial port communication and test device attributes page, fill in the S7-200 equipment corresponding to the phone number. Select error status output, then connected to a character variable, prompt dial-up state running environment. Close the parent device properties page, open the equipment properties page, switch to the test page, MCGS should send data to the Modem, and began to dial, dial, remote Modem should be automatic response, and answering the telephone, began to Modem handshake. This process is not correct, possible reasons include: 1, there are other programs such as super on computer terminal takes up a serial port; 2, the serial number is not correct; 3, number fill in error, and so on. On both sides of the Modem handshake completes, you should see a Modem to send light and receive light flashing, constant communication. Handshake process hangs up, immediately after the completion of the Modem is usually remote Modem carrier detect error cause, this kind of situation will happen some Modem. Replace a remote Modem or take remote Modem first short feet and 6 feet, forcing remote Modem carrier detection. After connected, on both sides of Modem sends data, data reception, may cause is remote Modem initialization status is not correct, please make sure the initialize remote Modem, baud rate, parity, data bits, stop bit is set to need. After connected, on both sides of Modem constantly send and receive data, the MCGS communication still report errors, reason may be that Modem join delay lead to equipment communication timing is not correct, at this time, father a serial port communication equipment configuration, choose to use RTS delay control, carefully adjust the RTS closing delay for about 150 ~ 250 milliseconds, can set up communication. 6, the actual running connect some PLC configuration environment variables, and interface configuration according to these variables, and error output, switch to the running environment, you can see the MCGS automatic dial-up connections, and start to collect data.
Timing acquisition PLC device 1 and experiment 2: the hour first completed step 1. 2 father, serial port communication device properties page, select asynchronous sampling data. And select communications 3, the son hung up the phone after device properties page, set the acquisition time is zero. 4, configuration a timing control strategy, operation strategy, call son equipment acquisition. 5, in operation and wait for the hour when the MCGS automatically dial-up, completed a second equipment acquisition, and then hang up the phone.
Experiment 3: dynamic set phone number 1, complete experiment 1 step 2, need to change the device connection number, send the parent equipment equipment command ChangeChildPhone (string representing a device name, phone number). Child device will automatically change the phone number right now, pay attention to the phone number to use enclosed in double quotation marks.  
 
收缩