设为首页收藏本站

最大的系统仿真与系统优化公益交流社区

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6540|回复: 5

关于flexsim连接数据库

  [复制链接]
发表于 2009-3-12 22:09:59 | 显示全部楼层 |阅读模式
5仿真币
flexsim 2.5的说明书上写着
The database must have an odbc alias defined before it is opened.
This is done using the "Data Sources" option in the windows control panel.
不过我找不到"Data Sources" option
求教各位高手了。。。


//////////////////////////////////////////////////////////////
///初始化参数
//////////////////////////////////////////////////////////////
runspeed(6);                                                                                                ///六倍速度运行
reset();                                                                                                        ///模型重置
go();                                                                                                                ///运行模型

//////////////////////////////////////////////////////////////
//这是flexsim2.6 StartQueue OnReset()事件响应函数
/////////////////////////////////////////////////////////////
fsnode *current = ownerobject(c);                                                      ///c是用来返回对活动节点的引用。如果是事件响应函数c返回一个包含这个事件的对象引用
                                                                                                                        ///ownerobject(); 返回包含结点的对象
                                                                                                                        ///fsnode× flesim中常用的数据类型,表示指向flexsim tree的指针
//PROSESTART                                                                                                ///这部分间的内容会显示在下拉框中
//Initialize things that drive the racks. Incoming/Outgoing wave times, etc.//下拉框内容
//PROSEEND                                                                                                    ///下拉框结束
//PARAMSTART                                                                                                ///flexsim脚本引用的可修改参数
                                                                                                                         ///参数
//PARAMEND                                                                                                    ///引用修改参数结束
//PROSESTART   
//
//PROSEEND                                                                                                    ///描述结束
float numrows = 0;
int x = 0;

setlabelnum(current,"incomingwave",1);                                            ///设置表识
setlabelnum(current,"outgoingwave",1);

// Get the IncomingWave times and start up the IncomingWaves userevent
if (dbgetmode() != 1)                                                                                ///判断当前数据库打开状态 0 没有数据库打开 1 数据库已sql模式打开 2 以全局表模式打开
{
  dbclose();                                                                                                ///如果数据库不是sql模式关闭
  dbopen("wdemo","select WaveNumber, Time from Waves where Type = 1",0);///打开数据库 1 表模式 0 sql模式
}
else
{
  dbsqlquery("select WaveNumber, Time from Waves where Type = 1");     ///如果数据库已打开则查询
}
numrows = dbgetnumrows();                                                                        ///行数为返回结果行数
settablesize("IncomingWaves",numrows,1);                                        ///设置全局表大小 参数一 表名 参数二 rows 参数三 cols//如果表大小设置不当可能造成数据不全或上次数据残留
for (x = 1; x <= numrows; x++)                                                            ///设置表元素值
  settablenum("IncomingWaves",x,1,stringtonum(dbgettablecell(x,2)));///去sql查询返回值 填充全局表

fsnode *incoming = node("/Tools/UserEvents/IncomingWaves",model());        /// 返回结点relative to model()路径/Tools/UserEvents/IncomingWaves
UserEvent *incomingdata = &o(UserEvent,incoming);                        ///连接 UserEvent与fsnode并把地址传递给UserEvent指针
incomingdata->v_time = gettablenum("IncomingWaves",1,1);        ///填充时间参数
incomingdata->v_repeat = 1;
destroyeventsofobject(incoming);                                                        ///删除资源tree中的对象(任何对象)
createevent(incoming,incomingdata->v_time,1,"UserEvent");        ///创建事件

// Get the OutgoingWave times and start up the OutgoingWaves userevent
dbsqlquery("select WaveNumber, Time from Waves where Type = 2");     ///取第二种数据
numrows = dbgetnumrows();
settablesize("OutgoingWaves",numrows,1);
for (x = 1; x <= numrows; x++)
  settablenum("OutgoingWaves",x,1,stringtonum(dbgettablecell(x,2)));

fsnode *outgoing = node("/Tools/UserEvents/OutgoingWaves",model());
UserEvent *outgoingdata = &o(UserEvent,outgoing);
outgoingdata->v_time = gettablenum("OutgoingWaves",1,1);
outgoingdata->v_repeat = 1;
destroyeventsofobject(outgoing);
createevent(outgoing,outgoingdata->v_time,1,"UserEvent");

// Set up the initial inventory
// The Inventory table has one extra row at the start that should never be deleted
// It is to hold the names of columns and their data types
//A wave of 0 in the Incomming table defines the intial inventory in the warehouse
dbsqlquery("select * from incoming where wave = 0");                                        ///填充表
numrows = dbgetnumrows();
settablesize("Inventory",numrows+1,5);
for (x=1; x<=numrows; x++)
{
  settablestr("Inventory",x+1,1,dbgettablecell(x,2));
  for (int y=2; y<=5; y++)
    settablenum("Inventory",x+1,y,stringtonum(dbgettablecell(x,y+1)));
}

[[i] 本帖最后由 BGN 于 2009-3-16 16:49 编辑 [/i]]

 楼主| 发表于 2009-3-12 22:11:10 | 显示全部楼层
北京创时能 2007-12-10 19:22
这个问题其实比较高级了,悬赏金有点太少(:lol )o!xi2d6s5jr+k
实现数据库和全局表动态连接是完全可能的。下面是V2.5版本时的例,是一个物流中心下达Picking List的例。DB为Access,不过在系统中你必须事先登录Database Aliases。
0}k#kM0X8A ?6C({*R setlabelnum(current,"pickoutwave",1);0y Z5M,|F a
//GET the pickwave times and start up the pick_create usereventZ9SH@b~t
if (dbgetmode() !=1)/L {OK ^]!x5c
{
]YN-Vh\.Y   dbclose();L VM/ii+H
  dbopen("orupis_db","select wavenumber,wavetime from wave_time",0);#dT1l#t$Xt*VCu.ms}
}
.gZ&d }$eA:u else Q D%CXvW#[ pp#g
{
$~�A6c-R)Z-b/cy(} U3G dbsqlquery("select wavenumber,wavetime from wave_time");
0?,H)g;w]u }8v^7dT {${ vS Uf
numrows = dbgetnumrows();bq _:V(S
settablesize("wave_T",numrows,2);
;t)k ~9c [5P1P:F'|"?f for ( x=1;x<=numrows;x++)
`2O Al0Qo$m%k {
3_)Ac!yS7H7X;`Kb E#^   settablenum("wave_T",x,1,stringtonum(dbgettablecell(x,1))); ow8D.C'B[,xyG
  settablenum("wave_T",x,2,stringtonum(dbgettablecell(x,2)));3o,Mv;b3z8y6H/u'e
}
hP1_&xk'y(XsR 省去userevent部分。.x&nV3z ~-c5]$I~ M7w
希望能对你有所帮助。
 楼主| 发表于 2009-3-12 22:11:30 | 显示全部楼层
[url=http://www.simulway.com/bbs/archiver/?tid-10062.html]http://www.simulway.com/bbs/archiver/?tid-10062.html[/url]


不过在系统中你必须事先登录Database Aliases。这句话不懂。求教。。。
 楼主| 发表于 2009-3-13 16:03:09 | 显示全部楼层

一些线索

A model which reads data from the Access 2003 Database "Sample_Database_TD.mdb".

Be sure there is an alias (Sample_Database_TD) created for the database. This is done using the "Data Sources" option in the Windows Control Panel.
In German Windows this is done under: Systemsteuerung | BDE Administrator.

On Reset the database connection is done and the table of the database opens, to show the data.
These data in the database define properties of the items like itemtype, itemname, itemsize and color.
Defining the color is special because in the database the name of the color is written (blue, green, yellow). This makes is necessary to use executestring which concats a command and executes it.

Code can be found:
UserEventInit
Trigger on Exit of Source
Trigger on Entry of Sink


Attention:
Do not delete or rename the object Logo_FlexsimD, because otherwise the model will not work correctly. Also do not rename, delete or rerank other objects.

Path:
\userprojects\SampleModels\

Files:
Sample_Database_TD.fsm
Sample_Database_TD.mdb

Tom David
aka
tom the (A)tom

Flexsim Version: v4.32

[url]http://www.flexsim.com/community/forum/downloads.php?do=file&id=148&act=down[/url]
 楼主| 发表于 2009-3-14 19:44:30 | 显示全部楼层
不用上了,答案在上面
发表于 2015-8-7 17:29:14 | 显示全部楼层
:lol
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|SimulWay 道于仿真   

GMT+8, 2024-4-24 04:37 , Processed in 0.012279 second(s), 14 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表