您的当前位置:首页正文

WinCC脚本案例保留

2023-12-23 来源:易榕旅网
WinCC脚本案例保留 2010-09-16 16:44

最近做一个WinCC跟ERP通讯的一个小项目,将脚本语言保留下来,以备不时之需! 仅仅是保留,各位看官如发现不妥之处请加以指教.

1.通过扫描枪扫描到ID号传给PLC,WinCC读取到ID号从ERP数据库中查找相关数据,写回到PLC,并给PLC一个写完成确认信号.(数据库是SqlServer2000)

Dim DB240trigger,db241trigger

db240trigger=HMIRuntime.Tags(\"db240itrigger\").Read db241trigger=HMIRuntime.Tags(\"DB241itrigger\").Read Dim ss,str

str=HMIRuntime.Tags(\"DB240szcoil_ID\").Read ss=CStr(str)

If (db240trigger=1 And db241trigger=0 ) Then Dim sPro,sDsn,sSer,sCon,sSql

Dim oRsMaterial,conn,oCom,oItem,oRsSCHEMA Dim database,server,uid,pwd

sCon =\"driver=sql server;server=10.51.103.96;DATABASE=brgs_release;uid=sa;pwd=pasword\" Set conn = CreateObject(\"ADODB.Connection\") conn.ConnectionString = sCon conn.Open

Set oRsMaterial = CreateObject(\"ADODB.Recordset\")

sSql= \"SELECT * FROM dbo.BRGS_GP_Material where MkNo='\" & CStr(ss) & \"'\" oRsMaterial.open ssql,conn,1,1 Dim m,n

m=oRsMaterial.recordcount

If m<>1 Then

MsgBox \"这个ID号找不到唯一的一条参数信息,请手动输入信息!\" Exit Function End If

Dim sCon2,sSql2

Dim oRsnftz,conn2

sCon2=\"driver=sql server;server=10.51.103.115;DATABASE=db_01;uid=sa;pwd=12345\" Set conn2 = CreateObject(\"ADODB.Connection\") conn2.ConnectionString = sCon2 conn2.Open

Dim LAST

LAST=orsMaterial.fields(\"LastProcedure\").value LAST=LAST+1

Set oRsnftz = CreateObject(\"ADODB.Recordset\")

sSql2= \"SELECT * FROM MF_TZ where ZC_ITM=\" & CInt(LAST) & \" And MO_No='\" & orsMaterial.fields(\"MO_NO\").value & \"'\" oRsnftz.open ssql2,conn2,1,1

Dim GJID,PIHAO,PANHAO,GANGZHONG,ZHIJING,ZHONGLIANG,P Dim PP

PP=oRsnftz.fields(\"ZC_NO\").value

If (Left(PP,1) = \"P\") Then HMIRuntime.Trace \"P\"

HMIRuntime.Tags(\"visible_error\").Write 0,1 Else

HMIRuntime.Trace \"not p ,will exit!\"

HMIRuntime.Tags(\"DB241szCOIL_ID\").Write \"error state\HMIRuntime.Tags(\"error_text\").Write PP,1 HMIRuntime.Tags(\"visible_error\").Write 1,1

MsgBox \"该材料现在不在P处理模式,请核实,或者手动输入信息!\" Exit Function End If

GJID=HMIRuntime.Tags(\"DB240szcoil_ID\").Read PIHAO=orsMaterial.fields(\"Mo_No\").value

PANHAO=orsMaterial.fields(\"Plant_No\").value GANGZHONG=orsMaterial.fields(\"Snm\").value ZHIJING=orsMaterial.fields(\"CardSPC\").value

ZHONGLIANG=orsMaterial.fields(\"CurrentWeight\").value

HMIRuntime.Tags(\"DB241iProg_NO\").Write P,1

HMIRuntime.Tags(\"DB241rDiameter\").Write ZHIJING,1 HMIRuntime.Tags(\"DB241rWeight\").Write ZHONGLIANG,1 HMIRuntime.Tags(\"DB241szSTEELGRADE\").Write GANGZHONG,1 HMIRuntime.Tags(\"DB241szPRODUNCTION_NO\").Write PIHAO,1 HMIRuntime.Tags(\"DB241szCOIL_NO\").Write PANHAO ,1 HMIRuntime.Tags(\"DB241szCOIL_ID\").Write GJID,1 HMIRuntime.Tags(\"DB241itrigger\").Write 1,1 oRsMaterial.Close

Set oRsMaterial = Nothing oRsnftz.Close

Set oRsnftz = Nothing conn.Close

Set conn = Nothing conn2.Close

Set conn2 = Nothing End If

2.开始上料程序

PLC接受到上料按钮的命令,将处理数据传给相应的DB数据块,并产生一条开始处理记录.插入到ERP的数据库中. Dim a,b,c,d,itrigger1,itrigger2

itrigger1=HMIRuntime.Tags(\"DB242itrigger\").Read itrigger2=HMIRuntime.Tags(\"DB243itrigger\").Read If (itrigger1=1 And itrigger2<>1 ) Then

a=HMIRuntime.Tags(\"DB242szCOIL_ID1\").Read b=HMIRuntime.Tags(\"DB242szCOIL_ID2\").Read c=HMIRuntime.Tags(\"DB242szCOIL_ID3\").Read d=HMIRuntime.Tags(\"DB242szCOIL_ID4\").Read HMIRuntime.Tags(\"DB243szCOIL_ID1\").Write a,1 HMIRuntime.Tags(\"DB243szCOIL_ID2\").Write b,1 HMIRuntime.Tags(\"DB243szCOIL_ID3\").Write c,1 HMIRuntime.Tags(\"DB243szCOIL_ID4\").Write d,1 HMIRuntime.Tags(\"DB243itrigger\").Write 1,1 End If

/////插入记录的程序

Dim sPro,sDsn,sSer,sCon,sSql

Dim oRsMaterial,conn,conn2,oCom,oItem,oRsSCHEMA Dim database,server,uid,pwd Dim ss,str

str=HMIRuntime.Tags(\"MKNO\").Read ss=CStr(str)

Dim lianjiezifuchuan,shujuku,shanchusql

lianjiezifuchuan =\"driver=sql server;server=127.0.0.1\\WINCC;DATABASE=Master;uid=;pwd=\" Set shujuku = CreateObject(\"ADODB.Connection\") shujuku.ConnectionString = lianjiezifuchuan shujuku.Open

shanchusql= \"Delete from load_unload WHERE shangxia=1 and MkNo='\"& ss &\"'\" Dim mingling

Set mingling =CreateObject(\"ADODB.Command\") With mingling

.ActiveConnection=shujuku .ComMandText=shanchusql End With

mingling.Execute Set mingling=Nothing shujuku.Close

Set shujuku = Nothing

If (ss<> \"\" )Then

'sCon =\"driver=sql server;server=10.51.103.96;DATABASE=brgs_release;uid=sa;pwd=pasword\"

sCon =\"driver=sql server;server=PC-201003161557\\WINCC;DATABASE=brgs_release;uid=sa;pwd=123456\" Set conn = CreateObject(\"ADODB.Connection\") conn.ConnectionString = sCon conn.Open

Set oRsMaterial = CreateObject(\"ADODB.Recordset\")

sSql= \"SELECT * FROM dbo.BRGS_GP_Material where mkNo='\" & CStr(ss) & \"'\" oRsMaterial.open ssql,conn,1,1

Dim mm

mm= oRsMaterial.recordcount If mm<1 Then

MsgBox \"条码\"& sS & \"查询不到相关的数据,请检查\" Exit Sub End If

If mm>1 Then

MsgBox \"条码\"& sS & \"查询到相关的数据不止一条,请检查\" Exit Sub End If

Dim STRState

STRState=oRsMaterial.fields(\"MaterialState\").value If STRState<>20 Then

MsgBox \"条码\"& sS & \"查询到的材料状态不是20,请检查!\" Exit Sub End If

Dim intlastprocedure,intlastprocedure2,cailiaohao

intlastprocedure=orsMaterial.fields(\"LastProcedure\").value intlastprocedure2=intlastprocedure+1

cailiaohao=orsMaterial.fields(\"Material_No\").value Set conn2 = CreateObject(\"ADODB.Connection\") conn2.ConnectionString = sCon conn2.Open

sSql= \"SELECT * FROM dbo.BRGS_GP_SCHEMA where UseFlag=0 and MkSeq= \" & intlastprocedure2 & \" And Material_NO='\" & CStr(cailiaohao) & \"'\"

Set oRsSCHEMA = CreateObject(\"ADODB.Recordset\") oRsSCHEMA.open ssql,conn2,1,1

Dim n

n=oRsSCHEMA.recordcount If n>1 Then

MsgBox \"条码\"& sS & \"查询到的调度信息不止一条,请检查\" Exit Sub End If

If n<1 Then

MsgBox \"条码\"& sS & \"查询不到调度信息,请检查\" Exit Sub End If

Dim gonghao,banzu,shike

gonghao=HMIRuntime.Tags(\"gonghao\").Read banzu=HMIRuntime.Tags(\"banzu\").Read shike=HMIRuntime.Tags(\"shike\").Read Dim s1,s2,s3,s4,s5,s6,s7

Dim A1,A2,A3,A4,A5,A6,A7,A8,A9,A10

Dim A11,A12,A13,A14,A15,A16,A17,A18,A19,A20 Dim A21,A22,A23,A24,A25,A26,A27,A28,A29,A30 Dim A31,A32,A33,A34,A35,A36,A37,A38,A39,A40

A1=orsMaterial.fields(\"Material_No\").value ''引用自BRGS_GP_Material表

A2=orsMaterial.fields(\"Plant_No\").value ''从BRGS_GP_MATERIAL表中Plant_No中复制过来 A3=orsMaterial.fields(\"Stuff_No\").value ''从BRGS_GP_MATERIAL表中Stuff_no中复制过来 A4=orsMaterial.fields(\"MaterialPre_No\").value ''从BRGS_GP_MATERIAL表中MaterialPre_No中复制过来

A28=orsMaterial.fields(\"BfNo\").value ''从BRGS_GP_MATERIAL表中Bf_No中复制过来 A20=orsMaterial.fields(\"MkNo\").value ''这个就是条码上的内容//////这个要确定

A5=orsMaterial.fields(\"Snm\").value ''钢种,从BRGS_GP_MATERIAL表中Snm中复制过来 A29=orsMaterial.fields(\"FirstSPC\").value ''原料规格,从BRGS_GP_MATERIAL表中FirstSPC中复制过来 A30=orsMaterial.fields(\"CardSPC\").value ''开工时的标称规格,从BRGS_GP_MATERIAL表中CardSPC中复制过来

A31=orsMaterial.fields(\"CardSPC\").value ''完工时的标称规格,从BRGS_GP_MATERIAL表中CardSPC中复制过来

A32=orsMaterial.fields(\"RealSPC\").value ''开工时的实测规格,从BRGS_GP_MATERIAL表中RealSPC中复制过来

A33=orsMaterial.fields(\"RealSPC\").value ''完工时的实测规格,从BRGS_GP_MATERIAL表中RealSPC中复制过来

A7=orsMaterial.fields(\"Mo_No\").value ''制令单号,从BRGS_GP_MATERIAL表中Mo_No中复制过来 '''''''''''''''''''''''''''''''

'''''''from schema table''''''' '''''''''''''''''''''''''''''''

A8=oRsSCHEMA.fields(\"SUnit\").value ''制程代码,从BRGS_GP_SCHEMA表中的SUnit读取 A9=oRsSCHEMA.fields(\"TzNo\").value ''通知单号,从BRGS_GP_SCHEMA表中的TzNo读取 A10=oRsSCHEMA.fields(\"ZcNo\").value ''制程名称,从BRGS_GP_SCHEMA表中的ZcNo读取 A11=oRsSCHEMA.fields(\"ZcRem\").value ''制程说明,从BRGS_GP_SCHEMA表中的ZcRem读取 A21=oRsSCHEMA.fields(\"SUnit\").value ''计划机台,从BRGS_GP_SCHEMA表中的SUnit读取

A37=oRsSCHEMA.fields(\"rowid\").value ''调度号,对应BRGS_GP_SCHEMA中的主键,表明本次操作,对应那一个调度

A12=\"401202J\" ''工作的机组,对于自动酸洗线是401202J

A34=\"\" ''拉丝模具号,这里为空字符串

A35=\"\" ''酸洗的吊钩号,这里为空 A13=1 ''始终为1 A14=CStr(shike) ''开工时间 A15=CStr(gonghao) ''开工操作员工号

A16=\"\" ''完工时间

A17=\"99999\" ''完工操作员工号 A25=CStr(banzu) ''开工的班组

A27=\"\" ''完工的班组

A19=0 ''切头切尾量,不理会,设置为0

A22=1 ''质检标志,永远为1 A23=\"system\" ''质检人员,永远为System A24=\"\" ''质检时间,与完工时间一致,暂时未空

A36=21 ''工序的类型,对于酸洗,永远是21

A38=0 ''在插入时设置为0,后面的操作不要更动这个字段

A40=\"\" ''在插入时设置为空串,后面的操作不要更动这个字段

A39=0 ''设置为0

A6=\"\" ''未作说明,设置为0 A18=0 ''ENDWEIGHT A26=0 ''BeginWeight

sSql= \"insert into BRGS_GP_PROCEDURE values(133,'\" & A1 & \"','\" & A2 & \"','\" & A3 & \"','\" & A4 & \"','\" & A5 & \"','\" & A6 & \"','\" & A7 & \"','\" & A8 & \"','\" & A9 & \"','\" & A10 & \"','\" & A11 & \"','\" & A12 & \"',\"& CInt(A13) &\CStr(A14)& \"','\" & A15 & \"','\" & CStr(A16)& \"','\" & A17 & \"',\"& CInt(A13) &\A21 & \"',\"& CInt(A22) &\\"','\" & A29 & \"','\" & A30 & \"','\" & A31 & \"','\" & A32 & \"','\" & A33 & \"','\" & A34 & \"','\" & A35 & \"',\"& CInt(A36) &\Dim objCommand

Set objCommand=CreateObject(\"ADODB.Command\")

With objCommand

.ActiveConnection=Conn .ComMandText=ssql End With

objCommand.Execute

Dim objCommand2

Set objCommand2=CreateObject(\"ADODB.Command\")

sSql= \"update dbo.BRGS_GP_Material set MaterialState='22',Region='401202J',LastProcedure=\" & intlastprocedure2 & \" where mkNo='\" & CStr(ss) & \"'\" With objCommand2

.ActiveConnection=Conn .ComMandText=ssql End With

objCommand2.Execute

Dim objCommand3

Set objCommand3=CreateObject(\"ADODB.Command\")

sSql= \"update dbo.BRGS_GP_SCHEMA set UseFlag=1 where UseFlag=0 and MkSeq= \" & intlastprocedure2 & \" And Material_NO='\" & CStr(cailiaohao) & \"'\" With objCommand3

.ActiveConnection=Conn .ComMandText=ssql End With

objCommand3.Execute

Set objCommand=Nothing Set objCommand2=Nothing Set objCommand3=Nothing oRsMaterial.Close

Set oRsMaterial = Nothing oRsSCHEMA.Close

Set oRsSCHEMA = Nothing conn.Close

Set conn = Nothing End If

3.下料程序

PLC接收到下料按钮的信号,更新ERP数据库中的信息,并将相关的ID号回传做二次对比. Dim a,b,c,d,itrigger1,itrigger2 Dim id2

itrigger1=HMIRuntime.Tags(\"DB244itrigger\").Read itrigger2=HMIRuntime.Tags(\"DB245itrigger\").Read If (itrigger1=1 And itrigger2<>1 And id2=0) Then a=HMIRuntime.Tags(\"DB244szCOIL_ID1\").Read b=HMIRuntime.Tags(\"DB244szCOIL_ID2\").Read c=HMIRuntime.Tags(\"DB244szCOIL_ID3\").Read d=HMIRuntime.Tags(\"DB244szCOIL_ID4\").Read HMIRuntime.Tags(\"DB245szCOIL_ID1\").Write a,1 HMIRuntime.Tags(\"DB245szCOIL_ID2\").Write b,1 HMIRuntime.Tags(\"DB245szCOIL_ID3\").Write c,1 HMIRuntime.Tags(\"DB245szCOIL_ID4\").Write d,1 HMIRuntime.Tags(\"DB245itrigger\").Write 1,1 End If

/////更新ERP中相关的数据

Dim sPro,sDsn,sSer,sCon,sSql

Dim oRsMaterial,conn,conn2,oCom,oItem,oRsSCHEMA Dim database,server,uid,pwd Dim ss,str

str=HMIRuntime.Tags(\"MKNO\").Read ss=CStr(str)

Dim lianjiezifuchuan,shujuku,shanchusql

lianjiezifuchuan =\"driver=sql server;server=127.0.0.1\\WINCC;DATABASE=Master;uid=;pwd=\" Set shujuku = CreateObject(\"ADODB.Connection\") shujuku.ConnectionString = lianjiezifuchuan shujuku.Open

shanchusql= \"Delete from load_unload WHERE shangxia=2 and MkNo='\"& ss &\"'\" Dim mingling

Set mingling =CreateObject(\"ADODB.Command\") With mingling

.ActiveConnection=shujuku .ComMandText=shanchusql End With

mingling.Execute Set mingling=Nothing shujuku.Close

Set shujuku = Nothing

If (ss<> \"\") Then

'sCon =\"driver=sql server;server=10.51.103.96;DATABASE=brgs_release;uid=sa;pwd=password\"

sCon =\"driver=sql server;server=PC-201003161557\\WINCC;DATABASE=brgs_release;uid=sa;pwd=123456\" Set conn = CreateObject(\"ADODB.Connection\") conn.ConnectionString = sCon conn.Open

Dim gonghao,banzu,shike

gonghao=HMIRuntime.Tags(\"gonghao\").Read banzu=HMIRuntime.Tags(\"banzu\").Read shike=HMIRuntime.Tags(\"shike\").Read

Dim objCommand

Set objCommand=CreateObject(\"ADODB.Command\")

sSql= \"update dbo.BRGS_GP_PROCEDURE set QCTime='\" & CStr(shike)& \"', EndTime='\" & CStr(shike) & \"',EndEmpNo='\"& CStr(gonghao) & \"',EndShift='\"& CStr(banzu) & \"' where endempno='99999' and mkNo='\" & CStr(ss) & \"'\"

With objCommand

.ActiveConnection=Conn .ComMandText=ssql End With

objCommand.Execute

Set oRsMaterial = CreateObject(\"ADODB.Recordset\")

sSql= \"SELECT * FROM dbo.BRGS_GP_Material where mkNo='\" & CStr(ss) & \"'\" oRsMaterial.open ssql,conn,1,1 Dim mm

mm= oRsMaterial.recordcount

If mm<=0 Then

MsgBox \"下料的扫描号码为\"& str & \"没有在数据库中找到上料信息\" Exit Sub End If

Dim intlastprocedure,intlastprocedure2,cailiaohao

intlastprocedure=orsMaterial.fields(\"LastProcedure\").value intlastprocedure2=intlastprocedure+1

cailiaohao=orsMaterial.fields(\"Material_No\").value

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Set conn2 = CreateObject(\"ADODB.Connection\") conn2.ConnectionString = sCon conn2.Open

sSql= \"SELECT * FROM dbo.BRGS_GP_SCHEMA where UseFlag=0 and MkSeq= \" & intlastprocedure2 & \" And Material_NO='\" & CStr(cailiaohao) & \"'\"

Set oRsSCHEMA = CreateObject(\"ADODB.Recordset\") oRsSCHEMA.open ssql,conn2,1,1 Dim n

n=oRsSCHEMA.recordcount

If n>1 Then

MsgBox \"调度表中关于条码\" & ss &\"的数据大于一条,请检查\" Exit Sub End If

Dim sql_last,rst_last,x_last,xxx

x_last=0

sql_last= \"SELECT * FROM dbo.BRGS_GP_SCHEMA where MkSeq>= \" & intlastprocedure2 & \" And Material_NO='\" & CStr(cailiaohao) & \"' order by mkseq asc\"

Set rst_last = CreateObject(\"ADODB.Recordset\") rst_last.open sql_last,conn2,1,1 xxx=rst_last.recordcount If xxx=0 Then x_last=100 Else

rst_last.movefirst End If

Dim y

Do While (Not rst_last.eof)

If rst_last.fields(\"UseFlag\").value=0 Then y=100

rst_last.movenext End If

rst_last.movenext Loop

x_last=y-x_last

Dim strzctype,zctypewrite

strzctype=oRsSCHEMA.fields(\"ZcType\").value If strzctype=21 Then zctypewrite=20 End If

If strzctype=22 Then zctypewrite=40 End If

If strzctype=23 Then zctypewrite=30 End If

If x_last=100 Then zctypewrite=50 End If

Dim objCommand2

Set objCommand2=CreateObject(\"ADODB.Command\") sSql= \"update dbo.BRGS_GP_Material set Region='BLQ',MaterialState=\" & CStr(zctypewrite) & \" where mkNo='\" & CStr(ss) & \"'\"

With objCommand2

.ActiveConnection=Conn .ComMandText=ssql End With

objCommand2.Execute

If x_last=100 Then Dim objCommand3

Set objCommand3=CreateObject(\"ADODB.Command\")

sSql= \"update dbo.BRGS_GP_Material set IsProduct=1,ProductShift='\" & CStr(banzu)& \"',ProductMan='\" &

CStr(gonghao)& \"',ProductTime='\" & CStr(shike)& \"',MaterialState=\" & CStr(zctypewrite) & \" where mkNo='\" & CStr(ss) & \"'\"

With objCommand3

.ActiveConnection=Conn .ComMandText=ssql End With

objCommand3.Execute End If

Set objCommand=Nothing Set objCommand2=Nothing Set objCommand3=Nothing rst_last.close

Set rst_last=Nothing

oRsMaterial.Close

Set oRsMaterial = Nothing oRsSCHEMA.Close

Set oRsSCHEMA = Nothing conn.Close

Set conn = Nothing End If 4.缓冲信息

系统具备多个上料按钮,也就是说操作人员按下每个上料按钮的时间很短,而处理上料这块的程序又比较大,根据网络情况,有时候需要1分钟左右,这样,有可能会丢失信息,这个是不允许的,因为信息丢失后,在ERP中就反应不出来,材料的状态就不会发生改变,到下一步工序时,材料就没有办法进行处理,同样下料也是.

所以我做了一个缓冲数据库,.按下上料或者下料按钮时,缓冲数据库只记录上料时的ID号,班组号以及上料时间等简单数据.然后系统定时(1分钟)从缓冲数据库中取出一个最先插入的数据进行处理,更具ID号跟ERP进行通讯,处理相关程序,这样做到了异步处理(一个上料处理到下料的过程需要30分钟左右). /////上料插入程序,使用本机自带的SqlServer2000数据库 Dim conn,scon,ssql

Dim database,server,uid,pwd

Dim ss1,ss2,ss3,ss4,str1,str2,str3,str4 Dim id1

Dim uesr,banzu

uesr=HMIRuntime.Tags(\"uesr\").Read banzu=HMIRuntime.Tags(\"banzu\").Read

id1=HMIRuntime.Tags(\"ID1\").Read

str1=HMIRuntime.Tags(\"DB242szCOIL_ID1\").Read str2=HMIRuntime.Tags(\"DB242szCOIL_ID2\").Read str3=HMIRuntime.Tags(\"DB242szCOIL_ID3\").Read str4=HMIRuntime.Tags(\"DB242szCOIL_ID4\").Read ss1=CStr(str1) ss2=CStr(str2) ss3=CStr(str3) ss4=CStr(str4)

sCon =\"driver=sql server;server=127.0.0.1\\WINCC;DATABASE=Master;uid=;pwd=\" Set conn = CreateObject(\"ADODB.Connection\") conn.ConnectionString = sCon conn.Open

Dim A1,A2,A3

If (ss1<> \"\" And id1=0 )Then

A1=ss1 A2=1 ''1:load 2:unload A3=CStr(Now())

sSql= \"insert into load_unload values('\" & A1 & \"',\" & A2 & \

Dim objCommand1

Set objCommand1=CreateObject(\"ADODB.Command\") With objCommand1

.ActiveConnection=Conn .ComMandText=ssql End With

objCommand1.Execute Set objCommand1=Nothing End If

If (ss2<> \"\" And id1=0 )Then .............. End If

If (ss3<> \"\" And id1=0 )Then ......... End If

If (ss2<> \"\" And id1=0 )Then .......... End If

conn.Close

Set conn = Nothing

HMIRuntime.Tags(\"ID1\").Write 1,1

/////下料插入程序,使用本机自带的SqlServer2000数据库 Dim conn,scon,ssql

Dim database,server,uid,pwd

Dim ss1,ss2,ss3,ss4,str1,str2,str3,str4 Dim id1

Dim uesr,banzu

uesr=HMIRuntime.Tags(\"uesr\").Read banzu=HMIRuntime.Tags(\"banzu\").Read id1=HMIRuntime.Tags(\"ID2\").Read

str1=HMIRuntime.Tags(\"DB244szCOIL_ID1\").Read str2=HMIRuntime.Tags(\"DB244szCOIL_ID2\").Read str3=HMIRuntime.Tags(\"DB244szCOIL_ID3\").Read str4=HMIRuntime.Tags(\"DB244szCOIL_ID4\").Read ss1=CStr(str1) ss2=CStr(str2) ss3=CStr(str3) ss4=CStr(str4)

sCon =\"driver=sql server;server=127.0.0.1\\WINCC;DATABASE=Master;uid=;pwd=\" Set conn = CreateObject(\"ADODB.Connection\") conn.ConnectionString = sCon conn.Open

Dim A1,A2,A3

If (ss1<> \"\" And id1=0 )Then

A1=ss1 A2=2 ''1:load 2:unload A3=CStr(Now())

sSql= \"insert into load_unload values('\" & A1 & \"',\" & A2 & \

Dim objCommand1

Set objCommand1=CreateObject(\"ADODB.Command\") With objCommand1

.ActiveConnection=Conn .ComMandText=ssql

End With

objCommand1.Execute Set objCommand1=Nothing End If

If (ss2<> \"\" And id1=0 )Then ....... End If

If (ss3<> \"\" And id1=0 )Then .......... End If

If (ss4<> \"\" And id1=0 )Then ............... End If

conn.Close

Set conn = Nothing

HMIRuntime.Tags(\"ID2\").Write 1,1

5.定时一分钟处理的处理

/////具体上料和下料程序就是前面的第一条和第二条

Dim Connectstring,con,rst,sql,rstcount,x,MKNO,gonghao,banzu,shike

ConnectsTring =\"driver=sql server;server=127.0.0.1\\WINCC;DATABASE=Master;uid=;pwd=\" Set con = CreateObject(\"ADODB.Connection\") con.ConnectionString = connectstring con.Open

Set rst = CreateObject(\"ADODB.Recordset\")

sql= \"SELECT * FROM load_unload order by ID ASC\" rst.open sql,con,1,1 rstcount=rst.recordcount

If (rstcount<1) Then Exit Function End If rst.movefirst

x=rst.fields(\"shangxia\").value

MKNO=rst.fields(\"MKNO\").value

gonghao=rst.fields(\"gonghao\").value banzu=rst.fields(\"banzu\").value

shike=CStr(rst.fields(\"shijian\").value)

HMIRuntime.Tags(\"MKNO\").Write MKNO,1

HMIRuntime.Tags(\"gonghao\").Write gonghao,1 HMIRuntime.Tags(\"banzu\").Write banzu,1

HMIRuntime.Tags(\"shike\").Write shike,1

If (x=1) Then Call procedure1() End If '

If (x=2) Then Call procedure5() End If

rst.Close

Set rst = Nothing

con.Close

Set con = Nothing

程序的界面就是这么样,很简单,这个一般不需要人去操作,只是换班的时候账号什么的动动就行了,然后上料的时候那个扫描枪扫描条码就可以了,简化了操作人员的劳动强度,以前可是需要操作人员那个条码牌到触摸屏上去一个一个参数输入的哦. 令附一个账号密码的简单程序(不用wincc的,很简单的一个程序,wincc那个设置复杂,维护的人员闲麻烦): ////登陆账号

im ZH,MM,BZ

ZH=HMIRuntime.Tags(\"ZH\").Read MM=HMIRuntime.Tags(\"MM\").Read Dim sPro,sDsn,sSer,sCon,sSql Dim oRs,conn

Dim database,server,uid,pwd

sCon =\"driver=sql server;server=127.0.0.1\\WINCC;DATABASE=Master;uid=;pwd=\" Set conn = CreateObject(\"ADODB.Connection\") conn.ConnectionString = sCon conn.Open

Set oRs = CreateObject(\"ADODB.Recordset\")

sSql= \"SELECT * FROM mmb where ZH='\" & CStr(ZH) & \"' And MM='\" & CStr(MM) & \"'\" oRs.open ssql,conn,1,1

Dim m

m=oRs.recordcount If m<1 Then

MsgBox \"账号或者密码不正确,请重新输入!\" Exit Sub

End If

Dim uesr,banzu

uesr=ors.fields(\"ZH\").value Dim asd

asd=HMIRuntime.Tags(\"t\").Read If asd=1 Then banzu=\"甲班\" enD if If asd=2 Then banzu=\"乙班\" enD if If asd=4 Then banzu=\"丙班\" enD if If aSd=8 Then banZu=\"丁班\" enD if Dim S

S=HMIRuntime.Tags(\"uesr\").Read If (Left(S,1) = \"A\") Then

HMIRuntime.Tags(\"vis\").Write 1,1 banZu=\"管理员\" Else

HMIRuntime.Tags(\"vis\").Write 0,1 End If

HMIRuntime.Tags(\"uesr\").write uesr,1 HMIRuntime.Tags(\"banzu\").write banzu,1

oRs.Close

Set oRs = Nothing conn.Close

Set conn = Nothing

HMIRuntime.Tags(\"MM\").write \"\

////////增加账号和删除账号的程序 Dim ZH,MM,BZ

ZH=HMIRuntime.Tags(\"ZH\").Read MM=HMIRuntime.Tags(\"MM\").Read Dim sPro,sDsn,sSer,sCon,sSql Dim oRs,conn

Dim database,server,uid,pwd

sCon =\"driver=sql server;server=127.0.0.1\\WINCC;DATABASE=Master;uid=;pwd=\" Set conn = CreateObject(\"ADODB.Connection\") conn.ConnectionString = sCon

conn.Open

Set oRs = CreateObject(\"ADODB.Recordset\")

sSql= \"SELECT * FROM mmb where ZH='\" & CStr(ZH) & \"'\" oRs.open ssql,conn,1,1

Dim m

m=oRs.recordcount If m>=1 Then

MsgBox \"账号已经存在\" Exit Sub End If

If ZH=\"\" Then

MsgBox \"账号不能为空\" End If

If MM=\"\" Then

MsgBox \"密码不能为空\" End If

Dim objCommand3

Set objCommand3=CreateObject(\"ADODB.Command\")

sSql= \"insert into MMB VALUES('\"& ZH & \"','\" & MM & \"')\" With objCommand3

.ActiveConnection=Conn .ComMandText=ssql End With

objCommand3.Execute Set objCommand3=Nothing oRs.Close

Set oRs = Nothing conn.Close

Set conn = Nothing

Dim ZH,MM,BZ

ZH=HMIRuntime.Tags(\"ZHZH\").Read Dim sPro,sDsn,sSer,sCon,sSql Dim oRs,conn

Dim database,server,uid,pwd

sCon =\"driver=sql server;server=127.0.0.1\\WINCC;DATABASE=Master;uid=;pwd=\" Set conn = CreateObject(\"ADODB.Connection\") conn.ConnectionString = sCon conn.Open

Set oRs = CreateObject(\"ADODB.Recordset\")

sSql= \"SELECT * FROM mmb where ZH='\" & CStr(ZH) & \"'\" oRs.open ssql,conn,1,1

Dim m

m=oRs.recordcount If m<1 Then

MsgBox \"工号不存在\" Exit Sub End If

Dim objCommand3

Set objCommand3=CreateObject(\"ADODB.Command\") sSql= \"delete from MMB where ZH='\"& ZH & \"'\" With objCommand3

.ActiveConnection=Conn .ComMandText=ssql End With

objCommand3.Execute Set objCommand3=Nothing

oRs.Close

Set oRs = Nothing conn.Close

Set conn = Nothing

HMIRuntime.Tags(\"ZHZH\").Write \"\

因篇幅问题不能全部显示,请点此查看更多更全内容