`
zjnbshifox
  • 浏览: 318706 次
  • 性别: Icon_minigender_1
  • 来自: 宁波
社区版块
存档分类
最新评论

学习使用spring data连接mongodb replset

阅读更多
1、分别在两个命令窗口中以replset方式启动两个mongodb进程
D:\mongodb\bin>mongod.exe --dbpath=d:\mongodata\data0 --port=10001 --replSet rcw
/127.0.0.1:20001

D:\mongodb\bin>mongod.exe --dbpath=d:\mongodata\data1 --port=20001 --replSet rcw
/127.0.0.1:10001

2、连接到任何一个mongodb实例,初始话replset
mongo 127.0.0.1:10001/admin

> db.runCommand({"replSetInitiate":{
... "_id":"rcw",
... "members":[{
... "_id":1,
... "host":"127.0.0.1:10001"
... },
... {
... "_id":2,
... "host":"127.0.0.1:20001"
... }
... ]
... }})

3、再加入一个仲裁服务器
D:\mongodb\bin>mongod.exe --dbpath=d:\mongodata\data1 --port 30001 replSet 127.0.0.1:10001
mongo 127.0.0.1:10001/admin
>rs.addArb({"127.0.0.1:30001"})


4、下载spring,spring-data-common即(spring-data-core)以及spring-mongodb,注意这里的data-common要下载1.2.1的,才能和mongodb1.0.1配合,最新版会出错,建立一个spring mvc项目,配置文件
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>人才信息管理</display-name>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:/config/spring/app-config.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <servlet>
    <servlet-name>SpringMVC</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:/config/spring/mvc-config.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>SpringMVC</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
  <filter>
    <filter-name>encodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
      <param-name>forceEncoding</param-name>
      <param-value>true</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <listener>
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
  </listener>
  <listener>
    <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
  </listener>
  <!-- <filter>
    <filter-name>hibernateFilter</filter-name>
    <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>hibernateFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping> -->
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <error-page>
    <error-code>500</error-code>
    <location>/WEB-INF/views/commons/timeout.jsp</location>
  </error-page>
  <error-page>
    <error-code>404</error-code>
    <location>/WEB-INF/views/commons/timeout.jsp</location>
  </error-page>
  <error-page>
    <error-code>403</error-code>
    <location>/WEB-INF/views/commons/timeout.jsp</location>
  </error-page>
</web-app>


app-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mongo="http://www.springframework.org/schema/data/mongo"
	xsi:schemaLocation="http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context-3.0.xsd
          http://www.springframework.org/schema/data/mongo
          http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
          http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
 
	
	<context:property-placeholder location="classpath:/config/db.properties" />

	<!-- Activate Spring Data MongoDB repository support -->
  	<mongo:repositories base-package="com.fox.mongo" />

	<!-- Add Replica Set support -->
	<mongo:mongo id="mongo" replica-set="${mongo.replica.set}"/>
 
	<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
		<constructor-arg ref="mongo"/>
  		<constructor-arg value="${mongo.db.name}"/>
  		<!-- <constructor-arg value="example"/> -->
	</bean>


	<!-- Service for initializing MongoDB with sample data using MongoTemplate -->
	<bean id="initMongoService" class="com.fox.service.InitService" init-method="init"/>
 
	<!-- To translate any MongoExceptions thrown in @Repository annotated classes -->
	<context:component-scan base-package="com.fox">    
       <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>   
    </context:component-scan>
    
	<context:annotation-config />
 
</beans>



db.properties文件的内容
mongo.db.name=test
#mongo.host.name=localhost
#mongo.host.port=27017

mongo.replica.set=127.0.0.1:10001,127.0.0.1:20001

mvc-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
		http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
	<!-- 只搜索@Controller 标注的类 不搜索其他标注的类 -->
	<context:component-scan base-package="com.fox.controller"	use-default-filters="false">
		<context:include-filter type="annotation" 	expression="org.springframework.stereotype.Controller" />
	</context:component-scan>

	<context:annotation-config />

	<!-- 对某些静态资源,如css,图片等进行过滤 ,有引用 "/resources/**" 的路径引用转到工程的/resources/目录取资源 -->
	<!-- <mvc:resources mapping="/favicon.ico" location="/favicon.ico"/> -->
	<mvc:resources location="/resources/" mapping="/resources/**" />

	<!-- Configures the @Controller programming model -->
	<mvc:annotation-driven />
	
	
	<!-- Declare a view resolver -->
	<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
	    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
	    <property name="prefix" value="/WEB-INF/views/"></property>
	    <property name="suffix" value=".jsp"/>
	</bean>

</beans>

CRUD的代码都是复制过来稍微修改了一下,映射类的代码
package com.fox.mongo;

import java.io.Serializable;

import org.springframework.data.mongodb.core.mapping.Document;

/**
 * A simple POJO representing a Person
 * 
 * @author Krams at {@link http://krams915@blogspot.com}
 */
@Document(collection="example")
public class Person implements Serializable {

	private static final long serialVersionUID = -5527566248002296042L;

	private String pid;
	private String firstName;
	private String lastName;
	private Double money;

	public String getPid() {
		return pid;
	}

	public void setPid(String pid) {
		this.pid = pid;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public Double getMoney() {
		return money;
	}

	public void setMoney(Double money) {
		this.money = money;
	}
}


service层的代码
package com.fox.service;

import java.util.List;
import java.util.UUID;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.WriteResultChecking;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.fox.mongo.Person;

/**
 * Service for processing {@link Person} objects.
 * Uses Spring's {@link MongoTemplate} to perform CRUD operations.
 * <p>
 * For a complete reference to MongoDB
 * see http://www.mongodb.org/
 * <p>
 * For a complete reference to Spring Data MongoDB 
 * see http://www.springsource.org/spring-data
 * 
 * @author Krams at {@link http://krams915@blogspot.com}
 */
@Service("personService")
@Transactional
public class PersonService {

	protected static Log logger = LogFactory.getLog("service");
	
	@Resource(name="mongoTemplate")
	private MongoTemplate mongoTemplate;
	
	/**
	 * Retrieves all persons
	 */
	public List<Person> getAll() {
		logger.debug("Retrieving all persons");
 
		// Find an entry where pid property exists
        Query query = new Query(Criteria.where("pid").exists(true));
        // Execute the query and find all matching entries
        List<Person> persons = mongoTemplate.find(query, Person.class);
        
		return persons;
	}
	
	/**
	 * Retrieves a single person
	 */
	public Person get( String id ) {
		logger.debug("Retrieving an existing person");
		
		// Find an entry where pid matches the id
        Query query = new Query(Criteria.where("pid").is(id));
        // Execute the query and find one matching entry
        Person person = mongoTemplate.findOne(query, Person.class);
    	
		return person;
	}
	
	/**
	 * Adds a new person
	 */
	public Boolean add(Person person) {
		logger.debug("Adding a new user");
		
		try {
			
			// Set a new value to the pid property first since it's blank
			person.setPid(UUID.randomUUID().toString());
			// Insert to db
		    mongoTemplate.insert(person);

			return true;
			
		} catch (Exception e) {
			logger.error("An error has occurred while trying to add new user", e);
			return false;
		}
	}
	
	/**
	 * Deletes an existing person
	 */
	public Boolean delete(String id) {
		logger.debug("Deleting existing person");
		
		try {
			
			// Find an entry where pid matches the id
	        Query query = new Query(Criteria.where("pid").is(id));
	        // Run the query and delete the entry
	        mongoTemplate.remove(query);
	        
			return true;
			
		} catch (Exception e) {
			logger.error("An error has occurred while trying to delete new user", e);
			return false;
		}
	}
	
	/**
	 * Edits an existing person
	 */
	public Boolean edit(Person person) {
		logger.debug("Editing existing person");
		
		try {
			
			// Find an entry where pid matches the id
	        Query query = new Query(Criteria.where("pid").is(person.getPid()));
	        
			// Declare an Update object. 
	        // This matches the update modifiers available in MongoDB
			Update update = new Update();
	        
	        update.set("firstName", person.getFirstName());
	        mongoTemplate.updateMulti(query, update, "example");
	        
	        update.set("lastName", person.getLastName());
	        mongoTemplate.updateMulti(query, update,"example");
	        
	        update.set("money", person.getMoney());
	        mongoTemplate.updateMulti(query, update,"example");
	        
			return true;
			
		} catch (Exception e) {
			logger.error("An error has occurred while trying to edit existing user", e);
			return false;
		}
		
	}
}

controller
package com.fox.controller;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.fox.mongo.Person;
import com.fox.service.PersonService;


/**
 * Handles and retrieves person request
 * 
 * @author Krams at {@link http://krams915@blogspot.com}
 */
@Controller
@RequestMapping("/main")
public class MainController {

	protected static Log logger = LogFactory.getLog("controller");
	
	@Resource(name="personService")
	private PersonService personService;
	
	/**
	 * Handles and retrieves all persons and show it in a JSP page
	 * 
	 * @return the name of the JSP page
	 */
    @RequestMapping(value = "/persons", method = RequestMethod.GET)
    public String getPersons(Model model) {
    	
    	
    	logger.debug("Received request to show all persons");
    	
    	// Retrieve all persons by delegating the call to PersonService
    	List<Person> persons = personService.getAll();
    	
    	// Attach persons to the Model
    	model.addAttribute("persons", persons);
    	
    	// This will resolve to /WEB-INF/jsp/personspage.jsp
    	return "personspage";
	}
    
    /**
     * Retrieves the add page
     * 
     * @return the name of the JSP page
     */
    @RequestMapping(value = "/persons/add", method = RequestMethod.GET)
    public String getAdd(Model model) {
    	logger.debug("Received request to show add page");
    
    	// Create new Person and add to model
    	// This is the formBackingOBject
    	model.addAttribute("personAttribute", new Person());

    	// This will resolve to /WEB-INF/jsp/addpage.jsp
    	return "addpage";
	}
 
    /**
     * Adds a new person by delegating the processing to PersonService.
     * Displays a confirmation JSP page
     * 
     * @return  the name of the JSP page
     */
    @RequestMapping(value = "/persons/add", method = RequestMethod.POST)
    public String add(@ModelAttribute("personAttribute") Person person) {
		logger.debug("Received request to add new person");
		
    	// The "personAttribute" model has been passed to the controller from the JSP
    	// We use the name "personAttribute" because the JSP uses that name
		
		// Call PersonService to do the actual adding
		personService.add(person);

    	// This will resolve to /WEB-INF/jsp/addedpage.jsp
		return "addedpage";
	}
    
    /**
     * Deletes an existing person by delegating the processing to PersonService.
     * Displays a confirmation JSP page
     * 
     * @return  the name of the JSP page
     */
    @RequestMapping(value = "/persons/delete", method = RequestMethod.GET)
    public String delete(@RequestParam(value="pid", required=true) String id, 
    										Model model) {
   
		logger.debug("Received request to delete existing person");
		
		// Call PersonService to do the actual deleting
		personService.delete(id);
		
		// Add id reference to Model
		model.addAttribute("pid", id);
    	
    	// This will resolve to /WEB-INF/jsp/deletedpage.jsp
		return "deletedpage";
	}
    
    /**
     * Retrieves the edit page
     * 
     * @return the name of the JSP page
     */
    @RequestMapping(value = "/persons/edit", method = RequestMethod.GET)
    public String getEdit(@RequestParam(value="pid", required=true) String id,  
    										Model model) {
    	logger.debug("Received request to show edit page");
    
    	// Retrieve existing Person and add to model
    	// This is the formBackingOBject
    	model.addAttribute("personAttribute", personService.get(id));
    	
    	// This will resolve to /WEB-INF/jsp/editpage.jsp
    	return "editpage";
	}
    
    /**
     * Edits an existing person by delegating the processing to PersonService.
     * Displays a confirmation JSP page
     * 
     * @return  the name of the JSP page
     */
    @RequestMapping(value = "/persons/edit", method = RequestMethod.POST)
    public String saveEdit(@ModelAttribute("personAttribute") Person person, 
    										   @RequestParam(value="pid", required=true) String id, 
    												Model model) {
    	logger.debug("Received request to update person");
    
    	// The "personAttribute" model has been passed to the controller from the JSP
    	// We use the name "personAttribute" because the JSP uses that name
    	
    	// We manually assign the id because we disabled it in the JSP page
    	// When a field is disabled it will not be included in the ModelAttribute
    	person.setPid(id);
    	
    	// Delegate to PersonService for editing
    	personService.edit(person);
    	
    	// Add id reference to Model
		model.addAttribute("pid", id);
		
    	// This will resolve to /WEB-INF/jsp/editedpage.jsp
		return "editedpage";
	}
    
}

分享到:
评论

相关推荐

    spring+mongodb集群搭建Demo

    在Spring应用中,我们需要使用`MongoClient`或`MongoClients.create()`方法来连接MongoDB集群。配置文件(如application.properties)中,提供连接字符串,包括所有mongos的地址。 6. **创建Spring Data MongoDB...

    SpringDataMongoDB多文档事务的实现

    本文将详细介绍如何使用 Spring Data MongoDB 实现多文档事务,并提供了详细的配置和实现步骤。 多文档事务简介 多文档事务是指在多个文档中执行的一系列操作,保证这些操作要么都成功,要么都失败。这种机制可以...

    Mongodb3.0.5 副本集搭建及spring和java连接副本集配置详细介绍

    spring.data.mongodb.uri=mongodb://admin:admin@192.168.0.160:57017,192.168.0.211:57017,192.168.0.213:57017/reptest?replicaSet=reptest ``` 在Java应用程序中,使用`MongoClientSettings`构建器创建客户端...

    可商用版PHP个人逍遥商城系统源码 手机版+电脑版

    安装步骤: 1.逍遥商城系统需要PHP+mysql运行环境,可以在windows或linux下运行,具体的php和mysql的版本没有特殊要求,兼容范围还是比较广的,推荐php5.6以上,mysql5.0以上。 2.把文件夹所有文件解压缩在站点目录中, 2.执行http://127.0.0.1/install/index.php进行安装 3.安装完成后,把install目录删掉。

    wordpress可视化数据采集Scrapes插件,WP博客网站自动采集发布

    wordpress可视化数据采集Scrapes插件,WP博客网站自动采集发布 支持 PHP7.4,PHP8.0 及以上不支持 上传插件到 wp-content/plugins 目录,然后解压 不需要写采集规则,傻瓜式操作,只需要对方的网址域名,在后台动动鼠标即可。

    STM32F103使用NRF2401通过ACK响应双向通讯(HAL库)

    STM32F103使用NRF2401通过ACK响应双向通讯(HAL库) 简单的应用。

    libmodbus编译好的windows x86 版本的dll

    Libmodbus 是一个用于 Modbus 协议的开源库,提供了丰富的函数接口,可方便实现设备间的 Modbus 通信,支持多种平台,能轻松移植到不同系统中,有助于开发人员快速构建 Modbus 相关应用程序。我已编译好windows x86 版本的dll

    LabVIEW在汽车EPS转向器海纳传感器标定中的应用与优化

    内容概要:本文详细介绍了LabVIEW在汽车EPS转向器海纳传感器标定中的应用,重点探讨了如何通过LabVIEW解决传统标定方法中存在的数据采集实时性不足、标定过程缺乏自动化、数据分析难度大的问题。文中展示了具体的代码实现,包括数据采集、分析、校准和报告生成等功能模块,并通过实际案例展示了该系统的高效性和准确性。此外,文章还讨论了一些常见的调试问题及其解决方案,如通信握手逻辑、信号异常检测、温度补偿等。 适合人群:从事汽车电子、传感器标定及相关领域的工程师和技术人员。 使用场景及目标:适用于需要提高传感器标定效率和精度的企业和个人。目标是通过LabVIEW的应用,实现传感器标定的自动化和智能化,从而提升产品质量和生产效率。 其他说明:文章强调了LabVIEW在处理复杂标定任务中的灵活性和强大功能,提供了多个实用的技术细节和实践经验,对于希望深入了解LabVIEW在工业应用中的开发者非常有价值。

    嵌入式系统开发中Simulink If模块的DBC与硬件信号自动导入及代码生成技术

    内容概要:本文深入探讨了Simulink If模块在嵌入式系统开发中的强大功能,特别是在汽车电子和工业自动化领域的应用。主要介绍了两种核心技术:一是DBC文件的自动导入生成模型及代码,二是硬件信号的导入生成模型及代码。DBC文件的自动导入能够快速构建CAN总线通信模型,简化信号解析和报文处理,生成的代码可以直接应用于AUTOSAR架构,实现ASW和BSW的无缝对接。硬件信号导入功能则允许开发者轻松地将硬件设备产生的信号集成到Simulink模型中,自动生成带有滤波和其他预处理功能的代码,适用于实时数据采集和控制算法实现。 适合人群:从事嵌入式系统开发、汽车电子、工业自动化等相关领域的工程师和技术人员。 使用场景及目标:① 快速搭建基于DBC文件的CAN总线通信模型,提高开发效率;② 实现硬件信号的实时处理和控制,优化数据采集和信号处理流程;③ 自动生成符合AUTOSAR标准的高质量代码,减少手动编码错误。 其他说明:文中提供了多个Matlab代码示例,展示了具体的操作步骤和生成代码的结构,帮助读者更好地理解和应用这些功能。同时,文中还分享了一些实用技巧,如DBC文件的功能模块拆分、硬件信号的时间戳对齐以及代码生成的优化设置等。

    流变学仿真方法:流变学仿真参数设置.zip

    流变学仿真方法:流变学仿真参数设置.zip

    【算法设计与分析】基于动态规划的0-1背包问题求解:二维与一维滚动数组实现及应用

    内容概要:本文详细介绍了0-1背包问题的两种动态规划解法,包括二维DP数组和优化后的一维滚动DP数组方法。首先定义了最大物品数量和背包容量等常量,接着通过两个数组分别存储每个物品的重量和价值。文中给出的代码实现了完整的算法逻辑:初始化边界条件,迭代更新状态转移方程,最终计算出能够放入背包的最大价值。此外还提供了回溯功能,可以找出具体的最优解组合。为了提高空间效率,文章进一步解释了一维滚动数组的使用方法,并附有完整的C++代码实现。 适合人群:计算机科学专业学生或有一定编程基础、对算法设计与分析感兴趣的读者。 使用场景及目标:①学习经典的动态规划问题解决思路;②理解如何通过状态转移方程来优化复杂度;③掌握二维DP向一维DP转换的技术手段以节省内存开销。 阅读建议:建议读者先理解0-1背包问题的基本概念,再逐步深入研究两种不同的解法,注意对比两者之间的异同点,特别是空间复杂度方面的改进。同时可以通过修改输入数据来测试不同情况下的运行结果,加深对算法的理解。

    natsort-3.0.0.tar.gz

    该资源为natsort-3.0.0.tar.gz,欢迎下载使用哦!

    一维抛物热传导方程的数值解法及其MATLAB实现

    内容概要:本文详细介绍了求解一维抛物热传导方程的各种经典数值方法,包括显式欧拉法、隐式欧拉法、Crank-Nicolson格式(即梯形公式)、二阶BDF格式以及不同的差分格式(如五点差分、九点差分和紧差分)。每种方法不仅给出了理论公式的推导,还提供了完整的MATLAB源码实现,并附有详细的代码解释和数值例子的数据图解分析。通过对不同方法的比较,展示了它们在稳定性和精度方面的优劣。 适合人群:具备一定数学和编程基础的学生、科研人员及工程师。 使用场景及目标:适用于需要解决热传导问题的研究项目,帮助使用者理解并选择合适的数值方法进行仿真计算,优化求解过程。 其他说明:文中强调了边界条件处理的重要性,并建议初学者从简单的Dirichlet边界条件入手练习。此外,还提到了一些常见的陷阱,如MATLAB矩阵索引与物理空间坐标的错位问题,提醒开发者注意这些问题以确保正确性。

    一个人的经历信息和个人简介

    一个人的经历信息和个人简介

    三菱FX3U PLC圆弧插补程序解析及其在运动控制中的应用

    内容概要:本文详细介绍了三菱FX3U PLC的圆弧插补程序,涵盖从中断扫描初始化、U型插补主程序、移动控制函数到急停复位程序的具体实现方法。通过具体的代码示例,展示了如何利用U型插补指令和服务调用来实现精确的圆弧轨迹控制。此外,文中还讨论了插补过程中的一些关键技术点,如中断优先级设置、插补结果存储、角度参数设置以及误差补偿等。同时,提供了关于脉冲输出、坐标计算和方向控制的实际操作技巧,强调了脉冲当量换算的重要性,并分享了一些调试经验和注意事项。 适合人群:从事工业自动化、运动控制领域的工程师和技术人员,特别是那些对PLC编程有一定基础并希望深入了解三菱FX3U PLC圆弧插补功能的人群。 使用场景及目标:适用于需要进行高精度圆弧轨迹控制的应用场景,如CNC控制系统、机器人运动控制等。目标是帮助读者掌握三菱FX3U PLC的圆弧插补编程技能,提高其在实际项目中的应用能力。 其他说明:文中提供的程序实例不仅有助于理解三菱FX3U PLC的工作原理,还能作为实际项目的参考模板。建议读者在实践中不断优化和完善相关程序,以适应不同的应用场景。

    西门子200 Smart PLC在60吨/小时反渗透+混床纯水项目中的应用与优化

    内容概要:本文详细介绍了在一个60吨/小时的反渗透+混床纯水项目中,如何利用西门子200 Smart PLC和Smart Line触摸屏进行系统设计与优化。主要内容涵盖硬件架构搭建(如CPU SR40、AI模块、TM模块)、模拟量处理(如电导率、压力、流量等信号的采集与转换)、数据滤波(如滑动平均值算法)、时钟同步(如自动和手动校准)、用户权限管理(如多级权限设置)、报警处理(如状态位轮询和异或运算)以及混床再生控制(如PID指令和状态机编程)。此外,还涉及了一些实用技巧,如数据追溯功能、报警弹窗中的应急处置指引、隐藏的debug模式等。 适合人群:从事工业自动化控制领域的工程师和技术人员,尤其是熟悉西门子PLC和触摸屏编程的人群。 使用场景及目标:适用于需要深入了解和掌握西门子200 Smart PLC在水处理项目中的具体应用和优化方法的专业人士。目标是提高系统稳定性、可靠性和易用性,确保水处理过程高效、精准地运行。 其他说明:文中提供了大量具体的程序代码片段和实践经验分享,对于实际项目实施具有很高的参考价值。同时,作者强调了细节处理的重要性,如模拟量的精确转换、报警系统的完善设计等,这些都是保障系统正常运行的关键因素。

    WMware的mac版本

    找了一大圈终于找到了,有些e xing博主发的还有密码和要米,本资源真实可用

    matlab-配备MPPT(P & O)控制增压转换器的PMSG风力涡轮机仿真模型

    增压转换器和涡轮机的功率为1千瓦。它们适合风速高达12 m/s。涡轮机参考旋转速度150转/分

    卷积神经网络(CNN)项目源码-基于CNN的行为姿态识别代码

    卷积神经网络(CNN)项目源码-基于CNN的行为姿态识别代码

    jspm酒店客房预定管理系统.docx

    jspm酒店客房预定管理系统

Global site tag (gtag.js) - Google Analytics