小编Mat*_*och的帖子

pySerial程序无法正确读取串行

我使用pySerial有问题,我不知道从哪里开始寻找.我有一个64位Windows 7操作系统,Python 2.7.5(32位),pySerial和Arduino(Arduino正常工作)已经安装.

我的Arduino代码如下:

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the serial in 19200 baud rate
  Serial.begin(19200);     
}

// the loop routine runs over and over again forever:
void loop() {
  delay(1000);               // wait for a second
  Serial.print("hello");
}
Run Code Online (Sandbox Code Playgroud)

(Arduino在COM8中连接,使用串行监视器时我可以看到它敬礼)

我的PySerial代码如下所示:

import serial
import time

arduino = serial.Serial("COM8", 19200)
time.sleep(2)  

while True:
    print arduino.readline()
Run Code Online (Sandbox Code Playgroud)

当我启动这个脚本时,程序运行,但我看不到串行输出(我认为Python脚本中的配置是正常的,因为如果有什么东西 - 例如端口 - 是错误的,它会崩溃).

我不知道如何找到解决方案.你能帮助我吗?

python windows serial-port arduino pyserial

3
推荐指数
1
解决办法
4953
查看次数

如何防止"坏"实现中毒MEF中的GetExportedValues?

我正在使用MEF来发现和实例化插件,并希望尽可能使该过程更加健壮.特别是我不希望编写错误的插件对主机或其他插件的执行产生负面影响.

不幸的是,我发现当使用GetExportedValues()从任何实现类构造函数抛出的异常有效地"毒化"容器时,会阻止所有"好"实现被返回.

以下代码演示了这一点:

using System;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.Linq;

namespace MefPoisoning {
    class Program {
        static void Main(string[] args) {
            var catalog = new TypeCatalog(
                typeof(GoodImplementation), 
                typeof(BadImplementation));

            using (var container = new CompositionContainer(catalog)) {
                try {
                    var implementations =
                        container.GetExportedValues<IInterface>();
                    Console.WriteLine("Found {0} implementations",
                        implementations.Count());
                }
                catch (CompositionException e) {
                    Console.WriteLine(e.Message);
                }
            }
        }
    }

    [InheritedExport]
    public interface IInterface {
    }

    public sealed class GoodImplementation : IInterface {
    }

    public sealed class BadImplementation : IInterface …
Run Code Online (Sandbox Code Playgroud)

.net mef

3
推荐指数
1
解决办法
716
查看次数

我想了解一些调试WCF Web服务异常的技巧

我已经创建了一个WCF服务,当我浏览到端点时,我得到以下错误:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
    <s:Fault>
      <faultcode 
            xmlns:a="http://schemas.microsoft.com/ws/2005/05/addressing/none">
            a:ActionNotSupported
      </faultcode> 
      <faultstring xml:lang="en-GB">
            The message with Action '' cannot be processed at the receiver,
            due to a ContractFilter mismatch at the EndpointDispatcher. 
            This may be because of either a contract mismatch (mismatched
            Actions between sender and receiver) or a binding/security
            mismatch between the sender and the receiver. Check that sender
            and receiver have the same contract and the same binding
            (including security requirements, e.g. Message, Transport, None).
      </faultstring> 
    </s:Fault>
  </s:Body>
</s:Envelope>
Run Code Online (Sandbox Code Playgroud)

我已经解决了这个问题,但没有享受到这种体验!有没有人有任何提示或工具来调试这样的问题?

.net wcf web-services

2
推荐指数
1
解决办法
4096
查看次数

如何保持略有不同的软件?

我有一些在自定义硬件上运行的项目.现在硬件已经改变,这需要一些软件更改.因此,"旧硬件"有源A,"新硬件"有源B,95%相同.

如果将来添加新功能,则必须为两个版本执行此功能.换句话说,A和B将并排存在,从现在开始将始终需要相同的变化.

我刚刚开始使用Subversion,因此我对所有可能性都不是很熟悉.

据我了解,B的新分支将从那一点开始分离,这不是我需要的.

维护A和B的最佳方法是什么,以便将来的更改适用于两个版本而无需手动应用它们两次?

svn version-control

2
推荐指数
1
解决办法
309
查看次数

2
推荐指数
1
解决办法
6012
查看次数

我为什么要__stdcall?

我开始做一些directX编程.我正在使用我从互联网上找到的这个教程.

我只是想知道为什么CALLBACK被定义为_stdcall以及为什么WINAPI也是如此.

我认为__stdcall是在导出将被编译为dll的函数时使用的.

但是,由于WindowProc和WINAPI永远不会被导出,为什么这些函数被声明为__stdcall?

非常感谢任何建议,

// WindowProc function prototype
LRESULT CALLBACK WindowProc(HWND hWnd, 
                            UINT message, 
                            WPARAM wParam, 
                            LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{

}
Run Code Online (Sandbox Code Playgroud)

c++

2
推荐指数
2
解决办法
378
查看次数

使用.Net写入COM端口

我将如何写入COM端口,尝试将以下示例转换为.Net(C#),特别是PHP部分?如果可能,有更简单的方法写出USB?

.net php c# arduino

2
推荐指数
1
解决办法
4364
查看次数

Lua - 表格打印和排序中的表格

T = {
{Name = "Mark", HP = 54, Breed = "Ghost"},
{Name = "Stan", HP = 24, Breed = "Zombie"},
{Name = "Juli", HP = 100, Breed = "Human"}},
Run Code Online (Sandbox Code Playgroud)

问题:

我怎么打印这些名字?

我如何通过HP对其进行排序?

lua

2
推荐指数
1
解决办法
5176
查看次数

我应该使用Sharepoint Number列类型来存储货币值吗?

在SharePoint中,我可以创建"Number"类型的列表列.我需要存储货币金额,并希望能够使用此列类型而不必创建新的列类型.

SharePoint是否存储和操作此类型的值(例如,在列表视图中对值进行求和时)以防止精度损失(即不是某种近似浮点类型)?

我查看了货币列,但它们似乎强制显示一个货币单位,这在我的申请中没有意义(我怀疑它们被存储为发动机罩下的'数字').

sharepoint currency

2
推荐指数
1
解决办法
3474
查看次数

不确定ConcurrentModificationException的原因

这是我的代码,用于构建一个可能的城市之旅Locale l(这不是最佳的,只是为了让我的AI搜索起步).

我得到了一个ConcurrentModificationException,据我所知,当多个代码访问变量/集合并尝试修改它时.导致此代码变得不快乐:

final void checkForComodification() {
    if (modCount != expectedModCount)
        throw new ConcurrentModificationException();
}
Run Code Online (Sandbox Code Playgroud)

我修改它,因为我正在添加一个元素,但由于Iterator没有添加(仅删除)的方法,我正在使用集合的方法.

所以,我的问题是:

  1. 我添加元素是什么导致问题?
  2. 如果是,如何正确添加它以便modCount正确,我没有得到ConcurrentModificationException

下面的完整方法,对ConcurrentModificationException发生的行进行评论:

public void construct() {
    tour = new ArrayList();
    ArrayList<City> lcl = new ArrayList(l.getCitys());

    tour.add(lcl.remove(0));
    tour.add(lcl.remove(1));

    while (!this.tourComplete()) {
        System.out.println(tour.size());
        Iterator tourit = tour.iterator();
        City g1 = (City) tourit.next();
        City g2 = (City) tour.get(lcl.indexOf(g1)+1);

        int gapDist = l.distanceBetweenCitys(g1, g2);

        while (tourit.hasNext()) {
            City C = null;
            int best = Integer.MAX_VALUE;

            for …
Run Code Online (Sandbox Code Playgroud)

java collections concurrency

2
推荐指数
1
解决办法
940
查看次数