file_get_contents有时能读出,有时读不出

十分不稳定,怎么解决?急死了,谁能回答十分感谢

[b]问题补充:[/b]
好的,十分感谢。

可是它把错误信息也获取到了:
Warning: file_get_contents(http://bbs.phpchina.com/rss.php?fid=17&auth=Lg37Y6QgN4fqGp%2F7E2hHFGk%2BoZG2VLcc5g) [function.file-get-contents]: failed to open stream: HTTP request failed! in E:\AppServ\www\demoWeb\xmlRead2.php on line 65

Warning: file_get_contents(http://bbs.phpchina.com/rss.php?fid=17&auth=Lg37Y6QgN4fqGp%2F7E2hHFGk%2BoZG2VLcc5g) [function.file-get-contents]: failed to open stream: HTTP request failed! in E:\AppServ\www\demoWeb\xmlRead2.php on line 65
Array ( [0] => AminoAcid Object ( [title] => 鏌ヨ鍔熻兘,浠d,鍚嶇О,鏃堕棿鏌ヨ鏃跺垽鏂棶棰� [link] => http://bbs.phpchina.com/viewthread.php?tid=128263 [description] => [category] => 闂瓟姹傚姪鍖� [author] => winver [pubDate] => Mon, 15 Jun 2009 08:00:19 +0000 ) [1] => AminoAcid Object ( [title] => smarty涓繍鐢╦s鐨勯棶棰� [link] => http://bbs.phpchina.com/viewthread.php?tid=128262 [description] => [category] => 闂瓟姹傚姪鍖� [author] => dayi4ban [pubDate] => Mon, 15 Jun 2009 07:53:31 +0000 ) [2] => AminoAcid Object ( [title] => jQuery Radio 鐨勫彇鍊�,Safari 涓柟娉曪紵 [link] => http://bbs.phpchina.com/viewthread.php?tid=128258 [description] => [category] => 闂瓟姹傚姪鍖� [author] => Rainstorm [pubDate] => Mon, 15 Jun

如何只得到xml内容,而得不到得错误信息输出则滤过呢??
得到的是string还是array,如何传值给js再处理呢??

php

3个回答

加入判断次数。假设只检查4次。

$i=0;
while(!$content or $i==4){
  @$content =file_get_contents($url);
  $i++;
}
if($i==4) exit("next");

@的作用:过滤错误提示

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
编译时出错,什么意思?有时不出,有时出
Extension.cpp(0) : error C2059: 语法错误 : “newline”rnExtension.cpp(0) : fatal error C1903: 无法从以前的错误中恢复;正在停止编译rn
http传图片,真机有时能读到有时读不到
使用http传图片时,真机(包括2.2包刷的平板还有htc的一部2.2的手机)有时能读到图片有时读不到(读不到的概率大于读的到,但貌似排除图片大过头了的情况下,越大的图片越容易读到),而且服务器端和客户端都不报错。但是在模拟器上就总是能读到图片,请问这是什么原因造成的。rnrn//服务端代码rnpublic void map() rn ServletOutputStream out = null;rn int mapId = 0;rn byte[] is = null;rn try rn String content = IOUtils.toString(getRequest().getInputStream());rn JSONObject json = new JSONObject(content);rn mapId = json.getInt("mapId");rn catch (Exception e) rn log.error("读取参数错误", e);rn return;rn rnrn try rn SystemInterface msi = SystemInterface.getInstance();rn // 从数据库读取图品的io流并转为byte[]rn is = msi.mapMap(mapId);rn catch (Exception e) rn log.error("读取失败", e);rn return;rn rn rn if(is != null)rn try rn out = getResponse().getOutputStream();rn out.write(is);rn out.flush();rn out.close();rn catch (IOException e) rn e.printStackTrace();rn rnrn rn rn rnrn//获取图片rn public static Bitmap getImageResult(String actionUrl, String request,int mapSize) rn Bitmap bm = null;rn try rn URL url = new URL("http://" + host + ":" + port + actionUrl);rn Log.d(TAG, String.format("Request (url: %s; Extra: %s)", url.toString(), request));rnrn HttpURLConnection connect = (HttpURLConnection) url.openConnection();rn connect.setDoOutput(true);rn connect.setDoInput(true);rn connect.setRequestMethod("POST");rn connect.setRequestProperty("Content-Type", "text/html");rn connect.setRequestProperty("Accept", "*/*");rn connect.setRequestProperty("Connection", "keep-alive");rn connect.setConnectTimeout(15 * 1000);rn connect.setRequestProperty("Accept-Language", "en-us");rn connect.setRequestProperty("Accept-Encoding", "gzip, deflate");rnrn OutputStreamWriter wr = new OutputStreamWriter(connect.getOutputStream());rn wr.write(request);rn wr.flush();rn InputStream is = connect.getInputStream();rn //图片rn if(is != null)rn BitmapFactory.Options options = new BitmapFactory.Options();rn options.inJustDecodeBounds = false;rn options.inSampleSize = mapSize;rn bm = BitmapFactory.decodeStream(is, null, options);rn rn is.close();rn catch (Exception e) rn e.printStackTrace();rn rn return bm;rn rnrnrn
超时已过期 有时能连上有时连不上。
Microsoft OLE DB Provider for ODBC Drivers 错误 '80004005' rnrn[Microsoft][ODBC SQL Server Driver]超时已过期 rnrn/active/news/newsFunction.asp,行 56 rnrn我的网站上出现这样一个错误rnrn那一行的代码是:rnrn56行: Set rstemp = Conn.Execute(Sql)rnrn连接字符串没有写错,几年了,代码没人动过,一直这样运行着,今天突然出问题,但不是每一次都报错,有时2秒就打开了,有时要等20秒超时才出现上面的错误。rnrn
矩阵键盘有时能输入数字,有时不能
在2440 wince5.0下,做2X4数字键盘驱动,采用中断方式 EINT0 EINT2 EINT11 EINT19。rn程序中按键中断发生后,就扫描哪个按键按下,然后通过keybd_event发送消息。rn现在按键输入数字的时候,有些按键一直可以正常输入,有的按键偶尔可以输入。rn在ADS下测试硬件按键是没问题的,请问可能是什么原因导致的呢? 谢谢各位啦!
98有时能访问2000,有时不能?
一台98的机器访问,我在2000的机器里添加了一个用户,而且已经开了guest,98登陆的时候,我用2000上的用户名和密码登陆的!有时候不能访问,但有时候提示不能访问呢 ?
IIS 有时能访问,有时不能?
请问哪位遇到过这样的问题?有哪些原因?rnIIS 5.0有时能访问,有时不能访问。rn我用的是win2k pro系统,fat32文件格式。rn谢谢解答!
dwr有时能得到有时得不到返回值
使用DWR调用三个方法,没有顺序的要求,有时可以获得返回值,有时得不到,有人说是同步的问题,加上rnDWREngine.setAsync(false);rn。。。。。rnDWREngine.setAsync(true);rn还是不行,到底是怎么回事呢?
为何有时能上网而有时却不能?
学校用专线上网,最近一段时间,有时服务器能上网但总有几台不确定的客户机上不去,有时又正相反。现在学校放假,只有服务器和几台客户机开着。这是什么原因?rn 过年了,不好意思给大家添麻烦了。过个好年啊!
为什么有时能上网,有时不能上网
我的电脑是window2000 ,为什么有时能上,有时不能上,重新启动后又可以上。rn网卡换了,pci也换了,系统重装了,但问题依然。请各位大下虾指点。
IIS 有时能访问,有时不能访问
我操作系统 是 Server 2003 sp2 + Sql 2008 rnrn出现的症状是 能访问 登录页面,登录时就死在那里了rnrn大部分时间可以正常访问网站, 有时不行, 不知道什么原因,rnrn后来我在同目录下把网站复制了一个 新建一个 虚拟目录指向他rnrn文件是一模一样的 ,发现当一个网站不能访问时,另外一个却能够访问, rnrn最近老是切换端口,汗,守在服务器旁,等高手指点
又发现一个问题,有时出有时不出,在线等
请把原理说出来, 出现异常的语句: conn.setAutoCommit(false);rnrnjava.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Can't start marnnual transaction mode because there are cloned connections.rn at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Sourcern)rn at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)rn at com.microsoft.jdbc.base.BaseConnection.setAutoCommit(Unknown Source)rn at com.perlong.poa.common.dao.ChitAction.sendChit(ChitAction.java:114)rn at com.perlong.poa.common.dao.servlet.ChitServlet.doGet(ChitServlet.javarn:61)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplrnicationFilterChain.java:252)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFrnilterChain.java:173)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperVrnalve.java:214)rn at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValvrneContext.java:104)rn at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.javrna:520)rn at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardrnContextValve.java:198)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextVrnalve.java:152)rn at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValvrneContext.java:104)rn at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.javrna:520)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.jrnava:137)rn at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValvrneContext.java:104)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.jrnava:118)rn at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValvrneContext.java:102)rn at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.javrna:520)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValrnve.java:109)rn at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValvrneContext.java:104)rn at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.javrna:520)rn at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)rnrn at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:16rn0)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.javarn:799)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.procernssConnection(Http11Protocol.java:705)rn at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.javarn:577)rn at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPrnool.java:684)rn at java.lang.Thread.run(Thread.java:595)rn
怎么会有时错误,有时正确?
Red Hat Linux 9rnrntest.crnrn#include rnrn/*简化了的代码*/rnint main()rn char str[256];rn FILE *fp;rn /*显示环境变量TTY,若无则用tty命令取得*/rn if((fp=popen("echo $TTY;tty","r"))!=NULL)rn while(fgets(str,256,fp))rn printf("%s",str);rn break; /*前面会经过其他处理,当条件达到就退出。*/rn ;rn pclose(fp);rn ;rn return(0);rn rnrn运行时有时提示“tty: 写入时发生错误: 断开的管道”,有时又没有这样的错误提示rnrn请问是什么原因造成这样不稳定呢?要怎么解决?
光驱有时能读有时不能读
[color=#0000FF]我是XPSP2,光驱有时能读盘有时不能读盘,但重启或注销时它又能读盘了。请问各位大下虾们这是什么原因?谢谢。[/color]
电脑硬盘有时找到有时找不到
[b][size=16px][b][b][b]我最近添了一块希捷160G 8M 串口硬盘 在BIOS里设置后 装完系统后运行一切正常。但是我挂上原有的40G并口硬盘后开机,有时BIOS检到了, 有时检不到。不知是什么原因?rn配置:rnCPU 赛扬D2.66rn主板 中凌 865PErn显卡 A9550rn电源 航嘉 300W[/size][/b]
WNetEnumResource有时成功有时失败
请教各位大虾 为什么同一段代码 用WNetEnumResource枚举网络资源获取IP有时成功而有时会失败?不知各位是否遇到过类似的问题?还望指教!
多文件上传,有时通过,有时不通过!
写了一个多文件上传(共2M左右),用的是孟子的方法,不过我是一次性出现四个框在本地测试很好,但在服务器上,开始可以用,但用久了就发现会丢失数据,也不出错,本来一次传4张的,结果只能传上一张,不知是什么原因!是不是服务器上要设置什么?webconfig也设置了!rn
显示器有时黑屏有时花屏
电脑一直好好的,我的显卡是集成的,今天上午,打开时,显示器没有任何反应,我重新插了下主机与显示器的插口,偶尔出来两下信号,但是很花,连进入BIOS时都是花的,后来多插了几下后,用其他的显示器,连花屏都没有了,直接黑屏,怎么弄都没信号,我重新弄了内存,应该没问题,但是我的显卡是集成的(我想说这句话的原因就是,一般集成显卡不容易出现问题,但我不确定),请问是怎么回事,给我一个方向,谢谢!!rn还有,我的显示器绝对没有问题,因为我的主机在其他显示器上试出现同样问题。
局域网有时通有时不通
主机A、主机B,主机C,路由器D。rn症状:A ping C 通,而C ping D 有时通有时不通。rnC装有杀毒软件。rnC至D的网线20米长的屏蔽线,已打过几次线头,还是一样。
数据源有时正常,有时抛出异常!!!!!!!!!!!
我是在TOMCAT4.01中配置的数据源,一般使用都很正常,但有时使用却出现rnjava.sql.SQLException: Communication link failure: java.io.EOFExcepionrn请问这个异常是什么原因引起的,该如何解决呢?
UDP服务器端求助,有时能收到数据,有时不能?
在一个端口上,即实现UDP广播,又实现接收消息。现在广播已经没有问题, 可是接收消息部分,有时启动服务能收到数据,有时启动服务不能收到数据,不知道是什么原因。以下是接收消息的线程代码。rnrn//LAN UDP服务器程序rn public void UDPListen()rn rn tryrn rn Socket soUdp = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);rnrn IPEndPoint localIpEndPoint = new IPEndPoint(IPAddress.Parse(serv_ip), LAN_port);rn soUdp.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);rn soUdp.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1);//设置为广播模式rnrn rn soUdp.Bind(localIpEndPoint);rnrn MessageBox.Show("UDP接收启动");rn rn while (true)rn rn Byte[] received = new Byte[256];rn //IPEndPoint tmpIpEndPoint = new IPEndPoint(IPAddress.Parse(serv_ip), LAN_port);rn //EndPoint remoteEP = (tmpIpEndPoint);rn //int bytesReceived = soUdp.ReceiveFrom(received, ref remoteEP);rn int bytesReceived = soUdp.Receive(received);rnrn String dataReceived = System.Text.Encoding.ASCII.GetString(received);rn MessageBox.Show("dataReceived:" + dataReceived);rnrn Data_chuli(received);rn /*rn String returningString = "The Server got your message through UDP: " ;rn rn Byte[] returningByte = System.Text.Encoding.ASCII.GetBytes(returningString.ToCharArray());rn MessageBox.Show("begin");rn rn soUdp.SendTo(returningByte,soUdp.RemoteEndPoint);rn MessageBox.Show("end");rn */rn rn rn rn catch (SocketException se)rn rn Console.WriteLine("A Socket Exception has occurred!" + se.ToString());rn rn rn void Data_chuli(Byte[] received)rn rn String dataReceived = System.Text.Encoding.ASCII.GetString(received);rnrn MessageBox.Show("shujuchuli SampleClient is connected through UDP.");rnrn MessageBox.Show(dataReceived);rnrn
表单提交有时能成功保存,有时不能成功保存。websphere!
在前台提交表单,在后台获取值,为对象的各个属性赋值,然后调用dao的方法保存,dao的保存方法也就是通过hibernate的save方法来实现的。rnrn在大多数情况下,能保存成功,但是偶尔会出现无法保存到数据库的情况,也没有明显的错误信息。rnrnrnrn环境:Hibernate3.5 +webwork2+webpshere6.1rnrn有一个属性的类型是blob.rnrn我的保存方法大致如下:rnrn Action里面定义了一个Stirng类型的属性content_,用来接收前台编辑器里的内容rnrn action里的添加方法类似如下rn rn InputStream fin = null;rnrn info_.setTitle(info.getTitle());rn 等等设置属性rnrn if (null != content_) rn fin = new ByteArrayInputStream(content_.getBytes());rn rn info_.setContent(Hibernate.createBlob(fin));//正文内容是blob类型rn infoDao.add(info_);rnrn大多数情况下是正常的,当抛出如下异常的时候,就没有保存成功。rnrn日志信息里面也没有出现自己的代码,不知为何,还望各位给予指点,不甚感激。rnrn[11-10-17 15:30:49:078 CST] 00000fd3 SystemErr R javax.servlet.ServletExceptionrn[11-10-17 15:30:49:078 CST] 00000fd3 SystemErr R at com.opensymphony.webwork.dispatcher.DispatcherUtils.serviceAction(DispatcherUtils.java:285)rn[11-10-17 15:30:49:078 CST] 00000fd3 SystemErr R at com.opensymphony.webwork.dispatcher.ServletDispatcher.service(ServletDispatcher.java:111)rn[11-10-17 15:30:49:078 CST] 00000fd3 SystemErr R at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)rn[11-10-17 15:30:49:078 CST] 00000fd3 SystemErr R at com.ibm.ws.cache.servlet.ServletWrapper.serviceProxied(ServletWrapper.java:275)rn[11-10-17 15:30:49:078 CST] 00000fd3 SystemErr R at com.ibm.ws.cache.servlet.CacheHook.handleFragment(CacheHook.java:461)rn[11-10-17 15:30:49:094 CST] 00000fd3 SystemErr R at com.ibm.ws.cache.servlet.CacheHook.handleServlet(CacheHook.java:283)rn[11-10-17 15:30:49:094 CST] 00000fd3 SystemErr R at com.ibm.ws.cache.servlet.ServletWrapper.service(ServletWrapper.java:255)rn[11-10-17 15:30:49:094 CST] 00000fd3 SystemErr R at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:966)rn[11-10-17 15:30:49:094 CST] 00000fd3 SystemErr R at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:907)rn[11-10-17 15:30:49:094 CST] 00000fd3 SystemErr R at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:145)rn[11-10-17 15:30:49:094 CST] 00000fd3 SystemErr R at com.thunis.util.HibernateFilter.doFilter(HibernateFilter.java:91)rn[11-10-17 15:30:49:094 CST] 00000fd3 SystemErr R at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:190)rn[11-10-17 15:30:49:094 CST] 00000fd3 SystemErr R at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:130)rn[11-10-17 15:30:49:094 CST] 00000fd3 SystemErr R at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:87)rn[11-10-17 15:30:49:094 CST] 00000fd3 SystemErr R at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:696)rn[11-10-17 15:30:49:094 CST] 00000fd3 SystemErr R at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:641)rn[11-10-17 15:30:49:094 CST] 00000fd3 SystemErr R at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:475)rn[11-10-17 15:30:49:094 CST] 00000fd3 SystemErr R at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:463)rn[11-10-17 15:30:49:094 CST] 00000fd3 SystemErr R at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3107)rn[11-10-17 15:30:49:094 CST] 00000fd3 SystemErr R at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:238)rn[11-10-17 15:30:49:094 CST] 00000fd3 SystemErr R at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:811)rn[11-10-17 15:30:49:094 CST] 00000fd3 SystemErr R at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1425)rn[11-10-17 15:30:49:094 CST] 00000fd3 SystemErr R at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:92)rn[11-10-17 15:30:49:094 CST] 00000fd3 SystemErr R at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:465)rn[11-10-17 15:30:49:094 CST] 00000fd3 SystemErr R at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:394)rn[11-10-17 15:30:49:094 CST] 00000fd3 SystemErr R at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:102)rn[11-10-17 15:30:49:094 CST] 00000fd3 SystemErr R at com.ibm.ws.ssl.channel.impl.SSLReadServiceContext$SSLReadCompletedCallback.complete(SSLReadServiceContext.java:1812)rn[11-10-17 15:30:49:094 CST] 00000fd3 SystemErr R at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:152)rn[11-10-17 15:30:49:094 CST] 00000fd3 SystemErr R at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:213)rn[11-10-17 15:30:49:094 CST] 00000fd3 SystemErr R at com.ibm.io.async.AbstractAsyncFuture.fireCompletionActions(AbstractAsyncFuture.java:195)rn[11-10-17 15:30:49:094 CST] 00000fd3 SystemErr R at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)rn[11-10-17 15:30:49:094 CST] 00000fd3 SystemErr R at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:193)rn[11-10-17 15:30:49:094 CST] 00000fd3 SystemErr R at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:725)rn[11-10-17 15:30:49:094 CST] 00000fd3 SystemErr R at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:847)rn[11-10-17 15:30:49:094 CST] 00000fd3 SystemErr R at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1498)rn
vb备份本地SQL,有时能连接有时不能连接
代码如下:有时能成功备份有时不能,提示:运行时错误'-2147467259(80004005)'SQL server 不存在或拒绝访问 rnrn A = Trim$(Str$(Year(Date))) & Trim$(Str$(Month(Date))) & Trim$(Str$(Day(Date))) & Trim$(Str$(Hour(Time))) & Trim$(Str$(Minute(Time)))rn Dim Rs_Qx3 As New ADODB.Connectionrn Dim cm As New ADODB.Commandrn Dim Rs As New ADODB.Recordsetrn Rs_Qx3.Open "Provider=SQLOLEDB;Data Source=127.0.0.1;uid=sa;pwd=003;database=northwind"rn Rs.CursorLocation = adUseClientrn cm.ActiveConnection = Cnrn cm.CommandText = "sp_dropdevice '数据备份'"rn cm.Executern cm.CommandText = "exec sp_addumpdevice 'disk','数据备份','D:\Mssql7\backup\" & A & "'"rn cm.Executern cm.CommandText = "backup database tl_wsy to 数据备份"rn cm.Executern Rs_Qx3.Closern MsgBox "本次数据备分成功!", vbInformation + vbOKOnly, "系统提示"
为什么图片显示不稳定,有时能显示,有时不能显示
我的图片存在数据库中,通过一个程序显示:rn别的页只需要 到用这个程序即可,rn但是不是总能显示,有时候如果打开一个需要显示图片的页时,如果没有显示,则怎么刷都没显示,而其他显示了图片的页怎么刷都显示。不知道什么原因?????rn郁闷………………rnrn程序如下,高手指点。rnrn//生成本页的主题部分rn private void cBody()rn rnrn string conStr="select photo from personalphoto where username='" + lookUid +"'";rn myConnection.Open();rnrn SqlCommand myCommand = new SqlCommand(conStr, myConnection);rn myCommand.CommandType = CommandType.Text;rn rn rn SqlDataReader dbReader;rn dbReader=myCommand.ExecuteReader(CommandBehavior.CloseConnection);rn if(dbReader.Read())rn rn Response.ContentType="image/*";rn Response.OutputStream.Write((byte[])dbReader["photo"],0,((byte[])dbReader["photo"]).Length);rn rn myCommand.Dispose();rn myConnection.Close();rn myConnection.Dispose();rnrn
一个打印函数,有时能正常打印,有时打出来的是空白
void CScrollDraw::Print()rnrn CDC memDC;rn CClientDC dc(this);rn rn int bmpWidth = cx+300;rn int bmpHeight = cy;rn memDC.CreateCompatibleDC( &dc );rn CBitmap * bitmap = new CBitmap();rnrn /*rn 这里设置的尺寸,某些尺寸可以正常打印,某些尺寸打出的是空白,怎么回事?rn */rn bitmap->CreateCompatibleBitmap(&dc,bmpWidth, bmpHeight);rnrn CBitmap * pOldBitmap = (CBitmap *) memDC.SelectObject( bitmap ); rn if (pOldBitmap == NULL) // if bitmap is very big, better check this !rn rn memDC.DeleteDC();rn delete bitmap;rn AfxMessageBox("Not enough resource for the bitmap. Either reduce the bitmap dimension or \nswitch to lower screen setting (e.g. 256-color mode), and try again.");rn return;rn rn //draw bitmap here, or it can be done in another functionrn memDC.BitBlt(0,0,cx,cy,&MemDC,0,0,SRCCOPY);rn rn CDC prtDC;rn CPrintInfo printInfo;rn CSize size;rn DOCINFO di;rn CString szPortName, szAppName, szPrintError;rn szAppName.LoadString(AFX_IDS_APP_TITLE);rn szPrintError = "";rnrn CSize paper_size; //printer paper size in mmrn int xLogPPI = 0;rn int yLogPPI = 0;rnrn if( AfxGetApp()->GetPrinterDeviceDefaults(&printInfo.m_pPD->m_pd) )rn rn HDC hDC = printInfo.m_pPD->m_pd.hDC;rn if (hDC == NULL)rn hDC = printInfo.m_pPD->CreatePrinterDC();rn if(hDC !=NULL)rn rn prtDC.Attach(hDC);rn paper_size.cx = prtDC.GetDeviceCaps(HORZSIZE);rn paper_size.cy = prtDC.GetDeviceCaps(VERTSIZE);rn xLogPPI = prtDC.GetDeviceCaps(LOGPIXELSX);rn yLogPPI = prtDC.GetDeviceCaps(LOGPIXELSY);rn rn else rn rn AfxMessageBox("Can not find printer. Please check installed/default printers.");rn return;rn rn rn int scr_xLogPPI = dc.GetDeviceCaps(LOGPIXELSX);rn int scr_yLogPPI = dc.GetDeviceCaps(LOGPIXELSY);rn int paper_width = (int) ((double) paper_size.cx * (double) xLogPPI / 25.4); //width of a printed page in pixelsrn int paper_height = (int) ((double) paper_size.cy * (double) yLogPPI / 25.4);rn double ratio_x = (double) xLogPPI / (double) scr_xLogPPI;rn double ratio_y = (double) yLogPPI / (double) scr_yLogPPI;rnrn CString strPageNumber = "";rn rn int page_info_left = (int) ( (double) paper_width * 0.9 );rn int page_info_right = paper_width;rn int page_info_top = (int) ( (double) paper_height * 0.99);rn int page_info_bottom = paper_height;rn CRect page_info_rect = CRect(page_info_left, page_info_top, rn page_info_right,page_info_bottom );rn int printed_pages = 0;rn int total_print_pages = 0;rn BOOL bAbort_print = FALSE;rnrn // calculate pagesrn int total_pages = (bmpWidth * ratio_x + paper_width - 1 ) / paper_width;rn //pop up printer dialogrn CPrintDialog prtDlg(FALSE, PD_PAGENUMS);rn rn prtDlg.m_pd.nMinPage = 1;rn prtDlg.m_pd.nMaxPage = total_pages;rn prtDlg.m_pd.nFromPage = 1;rn prtDlg.m_pd.nToPage = total_pages;rn rn if(prtDlg.DoModal() == IDOK )rn rn memset(&di, 0, sizeof(DOCINFO));rn di.cbSize = sizeof(DOCINFO);rn di.lpszDocName = szAppName;rn szPortName = prtDlg.GetPortName();rn di.lpszOutput = szPortName;rn prtDC.m_bPrinting = TRUE;rn rn elsern return; //Cancel button pressed, don't forget this!rnrn if(prtDC.StartDoc(&di) == -1)rn rn AfxMessageBox("Printing error occured. Unable to find printer.");rn prtDC.Detach();rn prtDC.DeleteDC();rn return;rn rn rn prtDC.SetMapMode(MM_TEXT);rn rn int i = 0;rn for(i = 0; i < total_pages; i++)rn rn prtDC.StartPage();rn strPageNumber.Format("Page:%d of %d", ++printed_pages, total_print_pages );rn rn if ( i == (total_pages - 1) && total_pages > 1 ) //last pagern rn int last_bmpWidth = bmpWidth - paper_width / ratio_x * i;rn prtDC.StretchBlt(0, 0, last_bmpWidth * ratio_x, bmpHeight* ratio_y, &memDC,rn paper_width * i / ratio_x, 0, last_bmpWidth, bmpHeight, SRCCOPY);rn rn elsern prtDC.StretchBlt(0, 0, paper_width, bmpHeight* ratio_y, &memDC,rn paper_width * i / ratio_x, 0, paper_width / ratio_x , bmpHeight, SRCCOPY);rn prtDC.TextOut(page_info_rect.left, page_info_rect.top, strPageNumber );rn rn prtDC.EndPage();rn rn memDC.SelectObject(pOldBitmap);rn delete bitmap;rn memDC.DeleteDC();rn rn prtDC.EndDoc();rn prtDC.Detach();rn prtDC.DeleteDC();rn return;rn
为何ppc 2002的模拟器有时能连上,有时连不上?
如题!谢谢各位!rn
为什么我的google地图有时能加载 有时却加载不了
很怪,在IE下加载地图有时能出来,有时却不能!现在更奇怪,看浏览器状态加载谷歌地图服务器,瞬间完成!同样的代码放在另一个路径下能正常运行,路径什么的都是对的!是不是跟网速有关还是google 地图服务器连接有限制?
ASP网站有时能访问有时不能访问
如题,有时访问正常,有时访问要1到2分钟,有时一直没有响应 。rnrn加入now.asp页面,无数据库连接,单纯显示服务器时间,访问情况也一样。rn加入html页面,访问正常。rn地址 http://www.szyouth.netrnrnrn服务器上其它几十家网站访问正常,我的也是最近几天才出现这样的问题
奇观现象,图片有时能出来有时不能
但是用鼠标右键显示图片,图片肯定能出来
线程中设置断点,为何有时能进入,有时进不去。
在线程中设置断点,rnThread thread=new Thread(new ThreadStart(targett));rnthread.Start();rn两处各设一断点,并且在targett方法中也设了断点,可是,调试时,按F11有时能进入线程中,有时进不去。为什么会这样?rn附:代码如下:rnrnusing System;rnusing System.Drawing;rnusing System.Collections;rnusing System.ComponentModel;rnusing System.Windows.Forms;rnusing System.Data;rnusing System.Net;rnusing System.Net.Sockets;rnusing System.Threading;rnusing System.Text;rnrnnamespace _1rnrn /// rn /// Summary description for Form1.rn /// rn public class Form1 : System.Windows.Forms.Formrn rn private System.Windows.Forms.Label label1;rn private System.Windows.Forms.TextBox textBox1;rn private System.Windows.Forms.TextBox textBox2;rn private System.Windows.Forms.Label label2;rn private System.Windows.Forms.Button button1;rn private System.Windows.Forms.Button button2;rn private System.Windows.Forms.StatusBar statusBar1;rn /// rn /// Required designer variable.rn /// rn private System.ComponentModel.Container components = null;rnrn private IPAddress myIP=IPAddress.Parse("127.0.0.1");rn private IPEndPoint myServer;rn private Socket sock;rn private Socket handler;rn private static ManualResetEvent done=new ManualResetEvent(false);rnrn public Form1()rn rn //rn // Required for Windows Form Designer supportrn //rn InitializeComponent();rnrn //rn // TODO: Add any constructor code after InitializeComponent callrn //rn rnrn /// rn /// Clean up any resources being used.rn /// rn protected override void Dispose( bool disposing )rn rn if( disposing )rn rn if (components != null) rn rn components.Dispose();rn rn rn base.Dispose( disposing );rn rnrn #region Windows Form Designer generated codern /// rn /// Required method for Designer support - do not modifyrn /// the contents of this method with the code editor.rn /// rn private void InitializeComponent()rn rn this.label1 = new System.Windows.Forms.Label();rn this.textBox1 = new System.Windows.Forms.TextBox();rn this.textBox2 = new System.Windows.Forms.TextBox();rn this.label2 = new System.Windows.Forms.Label();rn this.button1 = new System.Windows.Forms.Button();rn this.button2 = new System.Windows.Forms.Button();rn this.statusBar1 = new System.Windows.Forms.StatusBar();rn this.SuspendLayout();rn // rn // label1rn // rn this.label1.Location = new System.Drawing.Point(40, 48);rn this.label1.Name = "label1";rn this.label1.Size = new System.Drawing.Size(56, 16);rn this.label1.TabIndex = 0;rn this.label1.Text = "服务器";rn // rn // textBox1rn // rn this.textBox1.Location = new System.Drawing.Point(112, 40);rn this.textBox1.Name = "textBox1";rn this.textBox1.TabIndex = 1;rn this.textBox1.Text = "127.0.0.1";rn // rn // textBox2rn // rn this.textBox2.Location = new System.Drawing.Point(112, 80);rn this.textBox2.Name = "textBox2";rn this.textBox2.TabIndex = 3;rn this.textBox2.Text = "5895";rn // rn // label2rn // rn this.label2.Location = new System.Drawing.Point(40, 88);rn this.label2.Name = "label2";rn this.label2.Size = new System.Drawing.Size(56, 16);rn this.label2.TabIndex = 2;rn this.label2.Text = "监听端口";rn // rn // button1rn // rn this.button1.Location = new System.Drawing.Point(40, 144);rn this.button1.Name = "button1";rn this.button1.TabIndex = 4;rn this.button1.Text = "开始监听";rn this.button1.Click += new System.EventHandler(this.button1_Click);rn // rn // button2rn // rn this.button2.Location = new System.Drawing.Point(160, 144);rn this.button2.Name = "button2";rn this.button2.TabIndex = 5;rn this.button2.Text = "停止监听";rn // rn // statusBar1rn // rn this.statusBar1.Location = new System.Drawing.Point(0, 207);rn this.statusBar1.Name = "statusBar1";rn this.statusBar1.Size = new System.Drawing.Size(292, 22);rn this.statusBar1.TabIndex = 6;rn // rn // Form1rn // rn this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);rn this.ClientSize = new System.Drawing.Size(292, 229);rn this.Controls.Add(this.statusBar1);rn this.Controls.Add(this.button2);rn this.Controls.Add(this.button1);rn this.Controls.Add(this.textBox2);rn this.Controls.Add(this.label2);rn this.Controls.Add(this.textBox1);rn this.Controls.Add(this.label1);rn this.Name = "Form1";rn this.Text = "Form1";rn this.ResumeLayout(false);rnrn rn #endregionrnrn /// rn /// The main entry point for the application.rn /// rn [STAThread]rn static void Main() rn rn Application.Run(new Form1());rn rnrn private void button1_Click(object sender, System.EventArgs e)rn rn tryrn rn myIP=IPAddress.Parse(this.textBox1.Text.Trim());rn rn catch(Exception)rn rn MessageBox.Show("sorry,your server is wrong");rn rn tryrn rn myServer=new IPEndPoint(myIP,Int32.Parse(this.textBox2.Text.Trim()));rn sock=new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);rn sock.Bind(myServer);rn sock.Listen(50);rn this.statusBar1.Text="now starting listen";rn Thread thread=new Thread(new ThreadStart(targett));rn thread.Start();rn rn catch(Exception ex)rn rn MessageBox.Show(ex.Message);rn rn rnrn private void targett()rn rn while(true)rn rn done.Reset();rn sock.BeginAccept(new AsyncCallback(AcceptCallback),sock);rn done.WaitOne();rn rn rn private void AcceptCallback(IAsyncResult ar)rn rn done.Set();rn Socket listener=(Socket)ar.AsyncState;rn handler=listener.EndAccept(ar);rn StateObject state=new StateObject();rn state.workSocket=handler;rn this.statusBar1.Text="connected";rn rn rnrn
linux下安装的oracle,为什么有时能启动,有时不能启动?
我的linux 操作系统是ubuntu8.10,安装了oracle10g,其中在/etc下的profile文件的最后,增加了自己定义的进程:rnexport oracle_sid=lyd;在/etc下的oratab的最后,把进程设为自动启动:"lyd:/media/data/u01/app/oracle/product/11.1.0/db_1:Y"。rn但是现在遇到的问题是:当我在oracle@ubuntu:~$提示符下,先键入“export oralce_sid=lyd”,回车后再使用sqlplus "/as sysdba"命令时,会显示“-su:sqlplus:command not found”。等上一段时间(长度不等),再使用sqlplus "/as sysdba",就会出现:rnSQL*Plus: Release 11.1.0.6.0 - Production on Mon Jun 22 15:57:17 2009rnrnCopyright (c) 1982, 2007, Oracle. All rights reserved.rnrnERROR:rnORA-12162: TNS:net service name is incorrectly specifiedrn再等一段时间(长度不等),先键入“export oralce_sid=lyd”,回车后再使用sqlplus "/as sysdba"命令时,会显示:rnSQL*Plus: Release 11.1.0.6.0 - Production on Mon Jun 22 16:04:46 2009rnrnCopyright (c) 1982, 2007, Oracle. All rights reserved.rnrnConnected to an idle instance.rnrnSQL> rn我搞不清楚,在我等待的这段时间,究竟发生了什么?在此期间,我不过是到/etc下面,使用vim profile,vim oratab命令查看了这两个文件,但并没有做任何修改呀?rnrnrn
好奇怪的页面,有时能打开,有时不能打开···
IIS里面有几十个站,里面的网站我都测试过了,都可以打开,放在国内服务器没问题。rn我把这些站放到香港服务器,刚开始可以,过了十来分钟就打不开了,于是我把程序池换了,又可以了,可还是过了十分钟,又打不开,它打不开也不报错,浏览器显示一直在链接,显示空白!真无语。rn重启IIS又可以了。过来十分钟还是····rnrn我都要疯了!!!!!rn
有时浏览器能访问网站,有时就报错
在 ASP.*********_aspx.ProcessRequest(HttpContext context) 位置 c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\68e621e7\6e6de4f\App_Web_81avdxet.18.cs:行号 0rn
2440+7113,摄像头为何有时能收到图像,有时不能?
如题,我在ce下做了7113的驱动,摄像头是bnc口的,为何有时候能够取得摄像头的数据,有时候不能?取不到数据的时候,得到的是全黑的图像,得到图像的时候,也有两种情况,一种是正常图像(这种幸运的情况很少,偶尔),另一种情况得到的是错位的图像,画面上半部分显示正常图像的下半部分,画面下半部分显示正常图像的上半部分,而且画面抖动很厉害,不知道是哪里的问题。欢迎交流,请多多指教。
麻烦问题,有时能插入记录,有时又不可以
update ih_advice_fee set ramount1 =isnull(ramount1,0)+:ld_thamount where fee_no = :ls_feeno;rn if sqlca.sqlcode <> 0 thenrn rollback using sqlca;rn messagebox('提示:','在第'+string(ll_row)+'行更新费用信息出错,保存失败!')rn returnrn end ifrn rn insert into IH_ADVICE_FEE_SELF(FEE_RETURN_NO,FEE_NO,INHOS_NO,ADVICE_NO,ADVICE_CODE,FEE_CODE,OFFICE_LIST,OFFICE_EXE,FEE_NAME,AMOUNT,UNIT,PRICE,SUMMARY,CHECK_NAME,CHECK_TIME,ASK_TIME,EXEC_TIME,ASK_MAN,EXEC_MAN,DEAL_SIGN,DEAL_TIME,DEAL_MAN,APPLY_OFFICE_CODE,FEE_SPE)rn values(:ls_feereturnno,:ls_feeno,:ls_inhosno,:ls_adviceno,:ls_advicecode,:ls_feecode,:gs_officecode,:ls_exeoffice,:ls_feename,:ld_thamount,:ls_unit,:ld_price,:ld_taxsum,:gs_loginID,:ld_datetime,:ld_datetime,:ld_datetime,:ls_beddoctor,:gs_loginID,'1',:ld_datetime,:gs_loginID,:gs_officecode,:ls_feespe);rn if sqlca.sqlcode <> 0 thenrn rollback using sqlca;rn messagebox('提示:','在第'+string(ll_row)+'行更退药信息出错,保存失败!')rn returnrn end ifrnrn第二条插入记录有时能成功,有时不能成功,不知道什么原因,麻烦高手了
请教大侠,一段代码有时能运行有时不能
写了几行,运行之,发现有时能运行,有时又报错。结果如下: rn 1--能运行时:rn run:rn调用有参构造函数rn有参构造函数==坐标为(6,5)rntostringrn坐标为(6,5)rn===================rn调用get函数rn输入两个数rn8rn8rn调用set函数rn调用set函数==坐标为(8,8)rn成功生成(总时间:4 秒)rnrn 2--不能运行时:rn run:rnException in thread "main" java.lang.NoClassDefFoundError: suibi/Point (wrong name: suibi/point)rn at java.lang.ClassLoader.defineClass1(Native Method)rn at java.lang.ClassLoader.defineClass(Unknown Source)rn at java.security.SecureClassLoader.defineClass(Unknown Source)rn at java.net.URLClassLoader.defineClass(Unknown Source)rn at java.net.URLClassLoader.access$000(Unknown Source)rn at java.net.URLClassLoader$1.run(Unknown Source)rn at java.security.AccessController.doPrivileged(Native Method)rn at java.net.URLClassLoader.findClass(Unknown Source)rn at java.lang.ClassLoader.loadClass(Unknown Source)rn at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)rn at java.lang.ClassLoader.loadClass(Unknown Source)rn at java.lang.ClassLoader.loadClassInternal(Unknown Source)rn at suibi.point.main(point.java:49)rnJava Result: 1rn成功生成(总时间:0 秒)rnrnrn 代码如 java code:rnrnpackage point1;rnimport java.util.*;rnclass Point rn int x,y;rn public Point ()rn System.out.println("调用无参构造函数");rn rn public Point (int a,int b)rn System.out.println("调用有参构造函数");rn this.x=a;this.y=b;rn System.out.println("有参构造函数==坐标为("+x+","+y+")");rn rn public void set(int [] p)rn System.out.println("调用set函数");rn this.x=p[0];rn this.y=p[1];rn System.out.println("调用set函数==坐标为("+this.x+","+this.y+")");rn rn public int [] get()rn System.out.println("调用get函数");rn System.out.println("输入两个数");rn int [] s=new int[2];rn Scanner sc = new Scanner(System.in);rns[0]=sc.nextInt();rns[1]=sc.nextInt();rnreturn s;rn rn public String toString()rnrn return "坐标为("+this.x+","+this.y+")";rn rnrnrn/**rn *rn * @author Administratorrn */rnpublic class Main rnrn /**rn * @param args the command line argumentsrn */rn public static void main(String[] args) rn Object oo2=new Point(6,5);rn System.out.println("tostring");rn System.out.println(oo2.toString());rn System.out.println("===================");rn ((Point)oo2).set(((Point)oo2).get());rn // TODO code application logic herern rnrnrnrn code endrnrn高人们帮帮我,自己实在不知道为什么。rnrn
图片预览,有时能显示出来,有时显示不出来的问题!
环境IE8,IIS7rn用IE直接运行html文件可以预览图片,rn可是用IIS浏览html文件却预览不出图片了,这怎么解决啊?rn小弟请教高手!rn代码如下:rn[code=JScript]rnrnrnrn rnrnrn rnrn rn rnrnrnrn[/code]
奇怪!动态生成的构件,为什么有时能显示提示信息有时不能!!
奇怪!动态生成的构件,为什么有时能显示提示信息有时不能!! rnmy[k].Hint :='ok'+ADOQuery1.Fields[4].AsString +'.'+#13+my[k].Hint; rnmy[k].Font.Name :='宋体'; rnmy[k].Font.Color := clWhite; rnmy[k].Font.Size :=14; rnmy[k].ShowHint :=true; rnmy[k].Enabled :=true; rnmy[k].BevelInner:=bvRaised; rnmy[k].BorderStyle :=sbsSingle; rnmy[k].DragMode := dmAutomatic; rnmy[k].OnEndDrag := myEndDrag; rnmy[k].OnDragOver := myDragOver; rnmy[k].show; rn其他属性都能体现出来,数据库读出也是正常的,就是有时不能显示提示(hint),为什么啊? 有时是一切正常的,但机会不是很多! rn rn
为什么我在2000下有时能设置“休眠”,有时却不行?
如何设置呢?
用插入的网页为什么有时能显示,有时不能?
场景是点击一个按钮后下面插入一个网页rn原来的能显示的概率比较高rn我修改成我需要的样子后概率比较低了rn有什么道理么rn为什么会有时能显示出来,有时不能rn这个网路绝对没有问题,不确定性到底哪来的?rn
linux下串口程序,有时能接收数据,有时不能
刚学linux,按照视频讲座的源代码运行,发现有时候能够接收到串口数据,有时候不能。串口设备不停的发送16进制数据:rn3a 34 41 32 50 41 00 03 ...每次发送30字节,计算机串口接收。第一次运行程序./seri ,接收到3字节之后程序退出,正常。然后我再运行一遍./seri 结果就接收不到数据了。之后无论运行多少遍程序,都不能再接收到数据。后来我用windows下的串口调试助手接收一次数据,再运行./seri 就又可以接收到数据了。我用的是cygwin模拟linux运行环境的,请高手给指点一下,为什么这个程序关闭之后再次运行的时候就不能接收串口数据了?rn源码如下:rn#include rn#include rn#include rn#include rn#include rn#include rn#include rn#include rn#include rnrnint set_opt(int fd,int nSpeed, int nBits, char nEvent, int nStop)rnrn struct termios newtio,oldtio;rn if ( tcgetattr( fd,&oldtio) != 0) rn perror("SetupSerial 1");rn return -1;rn rn bzero( &newtio, sizeof( newtio ) );rn newtio.c_cflag |= CLOCAL | CREAD; rn newtio.c_cflag &= ~CSIZE; rnrn switch( nBits )rn rn case 7:rn newtio.c_cflag |= CS7;rn break;rn case 8:rn newtio.c_cflag |= CS8;rn break;rn rnrn switch( nEvent )rn rn case 'O':rn newtio.c_cflag |= PARENB;rn newtio.c_cflag |= PARODD;rn newtio.c_iflag |= (INPCK | ISTRIP);rn break;rn case 'E': rn newtio.c_iflag |= (INPCK | ISTRIP);rn newtio.c_cflag |= PARENB;rn newtio.c_cflag &= ~PARODD;rn break;rn case 'N': rn newtio.c_cflag &= ~PARENB;rn break;rn rnrnswitch( nSpeed )rn rn case 2400:rn cfsetispeed(&newtio, B2400);rn cfsetospeed(&newtio, B2400);rn break;rn case 4800:rn cfsetispeed(&newtio, B4800);rn cfsetospeed(&newtio, B4800);rn break;rn case 9600:rn cfsetispeed(&newtio, B9600);rn cfsetospeed(&newtio, B9600);rn break;rn case 115200:rn cfsetispeed(&newtio, B115200);rn cfsetospeed(&newtio, B115200);rn break;rn default:rn cfsetispeed(&newtio, B9600);rn cfsetospeed(&newtio, B9600);rn break;rn rn if( nStop == 1 )rn newtio.c_cflag &= ~CSTOPB;rn else if ( nStop == 2 )rn newtio.c_cflag |= CSTOPB;rn newtio.c_cc[VTIME] = 0;rn newtio.c_cc[VMIN] = 0;rn tcflush(fd,TCIFLUSH);rn if((tcsetattr(fd,TCSANOW,&newtio))!=0)rn rn perror("com set error");rn return -1;rn rn printf("set done!\n");rn return 0;rnrnrnint open_port(int fd,int comport)rnrn char *dev[]="/dev/ttyS0","/dev/ttyS1","/dev/ttyS2";rn long vdisable;rn if (comport==1)rn fd = open( "/dev/ttyS0", O_RDWR|O_NOCTTY|O_NDELAY);rn if (-1 == fd)rn perror("Can't Open Serial Port");rn return(-1);rn rn else rn printf("open ttyS0 .....\n");rn rn else if(comport==2)rn fd = open( "/dev/ttyS1", O_RDWR|O_NOCTTY|O_NDELAY);rn if (-1 == fd)rn perror("Can't Open Serial Port");rn return(-1);rn rn else rn printf("open ttyS1 .....\n");rn rn else if (comport==3)rn rn fd = open( "/dev/ttyS2", O_RDWR|O_NOCTTY|O_NDELAY);rn if (-1 == fd)rn perror("Can't Open Serial Port");rn return(-1);rn rn else rn printf("open ttyS2 .....\n");rn rn if(fcntl(fd, F_SETFL, 0)<0)rn printf("fcntl failed!\n");rn elsern printf("fcntl=%d\n",fcntl(fd, F_SETFL,0));rn if(isatty(STDIN_FILENO)==0)rn printf("standard input is not a terminal device\n");rn elsern printf("isatty success!\n");rn printf("fd-open=%d\n",fd);rn return fd;rnrnrnint main(void)rnrn int fd;rn int nread,i;rn char buff[]="Hello\n";rnrn if((fd=open_port(fd,1))<0)rn perror("open_port error");rn return;rn rn if((i=set_opt(fd,9600,8,'N',1))<0)rn perror("set_opt error");rn return;rn rn printf("fd=%d\n",fd);rn// fd=3;rn nread=read(fd,buff,3);rn printf("nread=%d,%s\n",nread,buff);rn close(fd);rn return;rn
相关热词 c++和c#哪个就业率高 c# 批量动态创建控件 c# 模块和程序集的区别 c# gmap 截图 c# 验证码图片生成类 c# 再次尝试 连接失败 c#开发编写规范 c# 压缩图片好麻烦 c#计算数组中的平均值 c#获取路由参数