Tracking_自定义Profile筛选(2)

本文介绍如何使用存储过程更新工作流配置文件至数据库,并查询配置版本的方法。通过具体代码示例展示了参数设置及执行流程。

Pofile对象的XML串存入数据库

该方法 调用了Tacking数据库的默认存储过程UpdateTrackingProfile,也可用自已的方式直接对Tacking数据库操作

None.gif private static void 插入Profile的XML串到数据库(string XML字串, Version 版本)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif{
InBlock.gif
string sql = @"Initial Catalog=Tracking;Data Source=WXWINTER\SQLEXPRESS;Integrated Security=SSPI;";
InBlock.gif            
//调用存储过程UpdateTrackingProfile
InBlock.gif
            SqlCommand command = new SqlCommand();
InBlock.gif
InBlock.gif            command.CommandType 
= CommandType.StoredProcedure; //类型是存储过程
InBlock.gif
            command.CommandText = "dbo.UpdateTrackingProfile"//操作 的存储过程
InBlock.gif
            command.Connection = new SqlConnection(sql);       //数据库连接字串
InBlock.gif
            try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//字段---------------------------------------------
InBlock.gif
                SqlParameter typeFullName = new SqlParameter();
InBlock.gif                typeFullName.ParameterName 
= "@TypeFullName";
InBlock.gif                typeFullName.SqlDbType 
= SqlDbType.NVarChar;
InBlock.gif
InBlock.gif                
//值为要设置工作流类的类名 : typeof(wxdlzm1).ToString()
InBlock.gif
                typeFullName.SqlValue = typeof(wxdlzm_wxwinter).ToString();
InBlock.gif                command.Parameters.Add(typeFullName);
InBlock.gif
InBlock.gif
InBlock.gif                
//字段----------------------------------------------------
InBlock.gif
                SqlParameter assemblyFullName = new SqlParameter();
InBlock.gif                assemblyFullName.ParameterName 
= "@AssemblyFullName";
InBlock.gif                assemblyFullName.SqlDbType 
= SqlDbType.NVarChar;
InBlock.gif
InBlock.gif                
//值为要设置工作流类的全称名 : typeof(wxdlzm1).Assembly.FullName
InBlock.gif
                assemblyFullName.SqlValue = typeof(wxdlzm_wxwinter).Assembly.FullName;
InBlock.gif                command.Parameters.Add(assemblyFullName);
InBlock.gif
InBlock.gif
InBlock.gif                
//TrackingProfile表Version字段--------------------------------
InBlock.gif
                SqlParameter versionId = new SqlParameter();
InBlock.gif                versionId.ParameterName 
= "@Version";
InBlock.gif                versionId.SqlDbType 
= SqlDbType.VarChar;
InBlock.gif
InBlock.gif                
//值为要指定的片本号的字串:格式"3.0.0.7"
InBlock.gif
                versionId.SqlValue = 版本.ToString();
InBlock.gif                command.Parameters.Add(versionId);
InBlock.gif
InBlock.gif
InBlock.gif                
//TrackingProfile表TrackingProfileXml字段-----------------------
InBlock.gif
                SqlParameter trackingProfile = new SqlParameter();
InBlock.gif                trackingProfile.ParameterName 
= "@TrackingProfileXml";
InBlock.gif                trackingProfile.SqlDbType 
= SqlDbType.NVarChar;
InBlock.gif
InBlock.gif                
//值为TrackingProfile格式的XML字串
InBlock.gif
                trackingProfile.SqlValue = XML字串;
InBlock.gif                command.Parameters.Add(trackingProfile);
InBlock.gif
InBlock.gif                
//-----------------------------------------------------------
InBlock.gif
                command.Connection.Open();//打开连接
InBlock.gif
                command.ExecuteNonQuery();//执行
InBlock.gif
                
InBlock.gif                Console.WriteLine();
InBlock.gif                Console.WriteLine(
"已将Profile插入");
InBlock.gif                Console.WriteLine();
InBlock.gif
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (SqlException e)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Console.WriteLine();
InBlock.gif                Console.WriteLine(
"插入Profile方法的Try捕获:插入数据出错了:");
InBlock.gif                Console.WriteLine(e.Message);
InBlock.gif                Console.WriteLine();
InBlock.gif
InBlock.gif                command.Dispose();
InBlock.gif                
return;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if ((null != command) && (null != command.Connection) && (ConnectionState.Closed != command.Connection.State))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    command.Connection.Close();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            command.Dispose();
ExpandedBlockEnd.gif        }

None.gif

查询自定义Pofile的版本

该方法 调用了Tacking数据库的默认存储过程GetTrackingProfile,也可用自已的方式直接对Tacking数据库操作
None.gif private static Version 得到Profile版本()
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif{
InBlock.gif            
//调用存储过程GetTrackingProfile
InBlock.gif
string sql = @"Initial Catalog=Tracking;Data Source=WXWINTER\SQLEXPRESS;Integrated Security=SSPI;";
InBlock.gif            TrackingProfile profile 
= null;
InBlock.gif            SqlDataReader SQL读取对象
= null;
InBlock.gif            SqlCommand command 
= new SqlCommand();
InBlock.gif
InBlock.gif            command.CommandType 
= CommandType.StoredProcedure;//类型是存储过程
InBlock.gif
            command.CommandText = "dbo.GetTrackingProfile";   //操作的存储过程
InBlock.gif
            command.Connection = new SqlConnection(sql);      //数据库连接字串
InBlock.gif
           
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{   
InBlock.gif                
//字段
InBlock.gif
                SqlParameter typeFullName = new SqlParameter();
InBlock.gif                typeFullName.ParameterName 
= "@TypeFullName";
InBlock.gif                typeFullName.SqlDbType 
= SqlDbType.NVarChar;
InBlock.gif
InBlock.gif                
//值为要查询的工作流类的类名: typeof(wxdlzm1).ToString() 或typeof(wxdlzm1).FullName
InBlock.gif
                typeFullName.SqlValue = typeof(wxdlzm_Wxwinter).FullName; //
InBlock.gif
                command.Parameters.Add(typeFullName);
InBlock.gif
InBlock.gif                
InBlock.gif                
//字段
InBlock.gif
                SqlParameter assemblyFullName = new SqlParameter();
InBlock.gif                assemblyFullName.ParameterName 
= "@AssemblyFullName";
InBlock.gif                assemblyFullName.SqlDbType 
= SqlDbType.NVarChar;
InBlock.gif
InBlock.gif                
//值为要查询工作流类的全称名: typeof(wxdlzm1).Assembly.FullName
InBlock.gif
                assemblyFullName.SqlValue = typeof(wxdlzm_Wxwinter).Assembly.FullName;
InBlock.gif                command.Parameters.Add(assemblyFullName);
InBlock.gif
InBlock.gif                
InBlock.gif                
//
InBlock.gif
                SqlParameter versionId = new SqlParameter();
InBlock.gif                versionId.ParameterName 
= "@Version";
InBlock.gif                versionId.SqlDbType 
= SqlDbType.VarChar;
InBlock.gif                command.Parameters.Add(versionId);
InBlock.gif
InBlock.gif               
InBlock.gif                
//
InBlock.gif
                SqlParameter createDefault = new SqlParameter();
InBlock.gif                createDefault.ParameterName 
= "@CreateDefault";
InBlock.gif                createDefault.SqlDbType 
= SqlDbType.Bit;
InBlock.gif                createDefault.SqlValue 
= 0;
InBlock.gif                command.Parameters.Add(createDefault);
InBlock.gif
InBlock.gif                command.Connection.Open();
InBlock.gif                SQL读取对象
= command.ExecuteReader();                
InBlock.gif              
InBlock.gif                
if (SQL读取对象.Read())
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
string profile的Xml字串= SQL读取对象[0as string;
InBlock.gif                    
InBlock.gif                    
if (null != profile的Xml字串)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        TrackingProfileSerializer 串行化对象
= new TrackingProfileSerializer();
InBlock.gif                        StringReader stringReader对象
= null;
InBlock.gif                        
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            stringReader对象
= new StringReader(profile的Xml字串);
InBlock.gif                            profile 
= 串行化对象.Deserialize(stringReader对象);
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            
if (stringReader对象!= null)
InBlock.gif                                stringReader对象.Close();
ExpandedSubBlockEnd.gif                        }

ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
//--------以上得到从数据库中得到profile的Xml字串,并将其返串为TrackingProfile对象
InBlock.gif
            
InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if ((SQL读取对象!= null&& (!SQL读取对象.IsClosed))
InBlock.gif                    SQL读取对象.Close();
InBlock.gif                
if ((command != null&& (command.Connection != null&& (ConnectionState.Closed != command.Connection.State))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    command.Connection.Close();
ExpandedSubBlockEnd.gif                }

InBlock.gif                command.Dispose();
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
//----------------------------------
InBlock.gif

InBlock.gif            
if (profile != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return new Version(profile.Version.ToString());
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{//如果数据库中没有,就返回"0.0.0.0"格式,表示没有,此为自定义约定
InBlock.gif
                return new Version("0.0.0.0");
ExpandedSubBlockEnd.gif            }

ExpandedBlockEnd.gif        }

None.gif

#include <ti/driverlib/m0p/dl_interrupt.h> #include “ti_msp_dl_config.h” #include “oled_hardware_i2c.h” volatile uint32_t S2, S3; volatile uint32_t S1,S4; void TB662L_f(uint8_t a,uint8_t b){ if( a== 0&&b == 0){ DL_GPIO_clearPins(TB662L_PORT, TB662L_BIN2_PIN |TB662L_AIN2_PIN); DL_GPIO_setPins(TB662L_PORT, TB662L_BIN1_PIN |TB662L_AIN1_PIN); } if(a == 1&&b == 1) { DL_GPIO_setPins(TB662L_PORT, TB662L_BIN2_PIN |TB662L_AIN2_PIN); DL_GPIO_clearPins(TB662L_PORT, TB662L_BIN1_PIN |TB662L_AIN1_PIN); } if(a == 1&&b == 0) { DL_GPIO_setPins(TB662L_PORT, TB662L_BIN2_PIN |TB662L_AIN2_PIN); DL_GPIO_setPins(TB662L_PORT, TB662L_BIN1_PIN |TB662L_AIN1_PIN); } } void PWM(uint32_t h,uint32_t f){ DL_TimerA_setCaptureCompareValue(PWM_0_INST, h, DL_TIMER_CC_1_INDEX); DL_TimerA_setCaptureCompareValue(PWM_0_INST, f, DL_TIMER_CC_0_INDEX); } void Motor(){ if(((DL_GPIO_readPins(Tracking_S2_PORT,Tracking_S2_PIN) & Tracking_S2_PIN)? 1:0) ==0&((DL_GPIO_readPins(Tracking_S3_PORT,Tracking_S3_PIN) & Tracking_S3_PIN)? 1:0) == 0){ TB662L_f(1,0); while (1) { TB662L_f(1,1); PWM(0,150); if(((DL_GPIO_readPins(Tracking_S2_PORT,Tracking_S2_PIN) & Tracking_S2_PIN)? 1:0) == 1&&((DL_GPIO_readPins(Tracking_S3_PORT,Tracking_S3_PIN) & Tracking_S3_PIN)? 1:0) == 1) break; } TB662L_f(1,0); delay_cycles(32000000/500); TB662L_f(1,1); } if(((DL_GPIO_readPins(Tracking_S2_PORT,Tracking_S2_PIN) & Tracking_S2_PIN)? 1:0) == 0&&((DL_GPIO_readPins(Tracking_S3_PORT,Tracking_S3_PIN) & Tracking_S3_PIN)? 1:0) == 1){ PWM(400,300); } if(((DL_GPIO_readPins(Tracking_S2_PORT,Tracking_S2_PIN) & Tracking_S2_PIN)? 1:0) == 1&&((DL_GPIO_readPins(Tracking_S3_PORT,Tracking_S3_PIN) & Tracking_S3_PIN)? 1:0) == 0){ PWM(300,400); } if(((DL_GPIO_readPins(Tracking_S2_PORT,Tracking_S2_PIN) & Tracking_S2_PIN)? 1:0) == 1&&((DL_GPIO_readPins(Tracking_S3_PORT,Tracking_S3_PIN) & Tracking_S3_PIN)? 1:0) == 1){ PWM(250,250); } if(((DL_GPIO_readPins(Tracking_S1_PORT,Tracking_S1_PIN) & Tracking_S1_PIN)? 1:0) == 1&&((DL_GPIO_readPins(Tracking_S4_PORT,Tracking_S4_PIN) & Tracking_S4_PIN)? 1:0) == 0){ PWM(300,400); } if(((DL_GPIO_readPins(Tracking_S1_PORT,Tracking_S1_PIN) & Tracking_S1_PIN)? 1:0) == 0&&((DL_GPIO_readPins(Tracking_S4_PORT,Tracking_S4_PIN) & Tracking_S4_PIN)? 1:0) == 1){ PWM(400,300); } } void Key1(void){ while(((DL_GPIO_readPins(Key_PORT,Key_Key1_PIN) & Key_Key1_PIN )? 1:0)) { OLED_ShowString(40,0,(uint8_t *)“Motor1”,16); OLED_ShowString(0,2,(uint8_t *)“S2:”,16); OLED_ShowString(0,4,(uint8_t *)“S3:”,16); OLED_ShowNum(20,2,S3,1,16); OLED_ShowNum(20,4,S2,1,16); } } int main(void) { SYSCFG_DL_init(); //清除定时器中断标志 //使能定时器中断 NVIC_EnableIRQ(TIMER_0_INST_INT_IRQN); DL_TimerG_startCounter(PWM_0_INST); TB662L_f(1,1); OLED_Init(); DL_GPIO_setPins(LED_PORT , LED_PIN_0_PIN); Key1(); while (1) { S1 = ((DL_GPIO_readPins(Tracking_S1_PORT,Tracking_S1_PIN) & Tracking_S1_PIN)? 1:0); S2 = ((DL_GPIO_readPins(Tracking_S2_PORT,Tracking_S2_PIN) & Tracking_S2_PIN)? 1:0); S3 = ((DL_GPIO_readPins(Tracking_S3_PORT,Tracking_S3_PIN) & Tracking_S3_PIN)? 1:0); S4 = ((DL_GPIO_readPins(Tracking_S4_PORT,Tracking_S4_PIN) & Tracking_S4_PIN)? 1:0); Motor(); } } @c:\Users\33225\Desktop\empty_driverlib_src_LP_MSPM0G3507_nortos_ticlang/ 设计制作一个简易自行瞄准装置,该装置包括自动寻迹小车及瞄准模块两部 分。自动寻迹小车行驶必须采用TI MSPM0系列MCU(简称MSPM0)控制(包 括巡迹、电机控制);要求MSPM0 小车行驶轨迹外沿为 100cm×100cm 的正方形,边线为黑色,线宽 1.8cm±0.2cm。正方形四个外顶点为 A、B、C 和 D 点。小车可沿行驶轨迹自动 寻迹逆时针方向行驶。 二、 要求 基本要求 (1)小车可以沿行驶轨迹自动寻迹行驶,行驶圈数N可在1~5之间设定, 行驶时间t ≤20s。此时瞄准模块电源开关断开。请在原代码的基础上在ccs环境改写MSPM0G3507芯片的代码写出第一问代码,要求评委任意指定小车行驶圈数,小车行驶完指定圈数后停止在起点。基本要求(1)中,行驶圈数可设1-5通键盘设定来控制圈数。代码下发和下面原代码一致,请将新添加的引脚指出来并用sysconfig图形化工具配置,原代码的引脚配置不变,只写循迹小车部分完成基本要求(1),瞄准模块不用管。四路灰度传感器循迹就用原代码方式实现。只在原代码基础上改动完成第一问,写在empty.c里面,其中不可以在赛道做任何标记。若想增加一个按键就Key2,引脚为PA21
08-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值