№.2 Apr.2005Vol.23 JOURNALOFSHAANXIUNIVERSITYOFSCIENCE&TECHNOLOGY 101* :1000-5811(2005)02-00101-05DELPHIRS485李思辉1,张义斌2(1., 712081;2., 712000) :在工业控制中经常需要用到微机与其它设备的串行通信,作者在文中介绍了利用DELPHI编程实现WINDOWS环境下单台微机与多台西门子MicroMaster变频器的RS485串行通信控制,并以此说明了微机与其它串行设备通信的一般性问题。:ActiveX控件;RS485;串行通信;通信协议;变频器:TP393.04 :A0 、,,,。,,,,,,。,,,,,,。RS485,,DELPHIWINDOWSMicroMasterRS485,,。1 1,RS485。RS485、,,100kbit/s1200m;15m,10Mbit/s。RS232RS485,“RS232/485”RS232RS485,RS485,32。,,RS485。*:2004-05-18 :(1974-),,,,:23图1 微机与多台变频器串行通信的连接图 图2 微机与变频器的通信过程图2 2.1 变频器串口通信格式MicroMasterRS485:1+5~8+0~1+1~2。,19.2kbit/s。,RS485:1+7+1+1,11bit。2.2变频器的通信协议2,,。,。。,,。:STXLGEADRPKEINDVALSTWHSWBCC STX:,02H。LGE:,MicroMaster,0CH(12)。ADR:,0~31(Bit:0~4),51。PKE:16,,Bit:0 MicroMaster,0001,;0010,RAMEEPROM。1,0。。IND:16,,0。VAL:16,PKE。STW:16,。HSW:16,16384(4000H)100%,32767,200%。32768~65535,0%~200%,。BCC:,。1022:DELPHIRS4853#(03H)50%,:,,:STXLGEADRPKEINDVALZSWHIWBCC ,:STX+LGE+ADR+PKE+IND+VAL+STW+HSW+BCC,LGEADR~BCC,STX~BCC;PEK、IND、VAL、STW,IND,0000H,STW,。,,:STX+LGE+ADR+PKE+IND+VAL+ZSW+HIW+BCC。,ZSWSTW,HIWHSW,。ZSW,,HIW。,STX、LGE、ADR、BCC(8bit),(16bit)。14。3 3.1 ActiveX控件MicrosoftCommControl6.0介绍WINDOWS,,,APIActiveX。DELPHIActiveX,API,API,ActiveXMicrosoftCommunicationControl6.0(MSComm)DELPHI,DELPHIMSComm。MSComm,:CommPort:,1~16,COM1~COM16。Settings:、、、。PortOpen:,TRUE,FALSE。InputMode:,0,1。RThreshold:OnComm。Input:,。Output:。InBufferSize:。InBufferCount:。OutBufferSize:。OutBufferCount:。InputLen:Input,0。CommEvent:。Settings“BBBB,P,D,S”,BBBB,P(N:,E:,O:),D(5~8),S(1、1.5、2)。MSComm,。10323InBufferCountOutBufferCount,SetCom-mEvent(),,OnComm(),OnComm(),DOS。3.2 软件的编制,,。,。,14,14OnComm(),14,,,14,,14。图3 查询方式通信流程图,,3。(100ms)。14。STX、ADR、BCC,:STX02HADRBCC“”“”,。。(1):MSCOM1.CommPort:=1;//COM1MSCOM1.InBufferSize:=512;//512MSCOM1.OutBufferSize:=512;//512MSCOM1.InBufferCount:=0;//MSCOM1.OutBufferCount:=0;//MSCOM1.InputLen:=0;//MSCOM1.RThreshold:=0;//OnComm,MSCOM1.InputMode:=0;//MSCOM1.Settings:='9600,E,7,1';//9600,,7bit,1//MSCOM1.PortOpen:=true;//。(2)MSCOM1.Output:=’02’+’0C’+’03’+’0000’+’0000’+’0000’+’0C7F’+’2000’+’5E’;//3#50%Sleep(100);//100msS_recive:=MSCOM1.Iutput;//…,,3。S_recive,ZSW1042:DELPHIRS485HIW,。:;;;。4 (1),,,。,,,。(2),,。(3),。(4),,。,,。5 ,、,,、,、。〔1〕.〔M〕.:,1997.〔2〕.〔M〕.:,2003.〔3〕.DELPHI〔M〕.:,2001.THEREALIZATIONOFCOMMUNICATIONCONTROLBETWEENONECOMEUTERANDRS485OFSEVERIALTRANSDUCERSWITHDELPHIPROGRAMLISi-hui1,ZHANGYi-bin2(1.SchoolofComputerandInformationEngineering,ShaanxiUniversityofScience&Technology,Xianyang712081,China;2.XianyangPowerSupplyBureau,Xianyang712000,China)Abstract:Itoftenneedtheserialcommunicationsbetweencomputersandotherequipmentsinindustrialcontrols.ThistextintroduceshowtouseDELPHIprogrammingtorealizeacomputercommunicationwithtransducersofSIEMENSMicroMasterlinRS485protocolsundertheWINDOWSenvironment.Soastoexplainthegeneralitiesofthecomputercommunicationwithotherserialequipments.Keywords:ActiveXcontrol;RS485;serialcommunication;communicationprotocols;transducer105