C# 启动与Gameboy打印机.Net Gadgeteer的串行连接

C# 启动与Gameboy打印机.Net Gadgeteer的串行连接,c#,.net,serial-port,spi,.net-gadgeteer,C#,.net,Serial Port,Spi,.net Gadgeteer,我一直在做一个项目,使用Microsofts.NETGadgeteer模块与Gameboy打印机进行黑客攻击和通信。到目前为止,我一直在处理硬件(请参阅以下线程:) 我已经根据需要将打印机连接为SPI串行连接,现在我需要开始与打印机交换字节包以开始探索打印 我曾试图将一些代码组合在一起,但失败得很惨。我真的不知道怎么跟印刷工说话。我所取得的唯一进步是SPI配置,但实际的通信超出了我的理解范围。也许有人不能给我指出正确的方向 下面是我试图复制的代码: 我的主要参考资料是Thermaldotnet(

我一直在做一个项目,使用Microsofts.NETGadgeteer模块与Gameboy打印机进行黑客攻击和通信。到目前为止,我一直在处理硬件(请参阅以下线程:)

我已经根据需要将打印机连接为SPI串行连接,现在我需要开始与打印机交换字节包以开始探索打印

我曾试图将一些代码组合在一起,但失败得很惨。我真的不知道怎么跟印刷工说话。我所取得的唯一进步是SPI配置,但实际的通信超出了我的理解范围。也许有人不能给我指出正确的方向

下面是我试图复制的代码:

我的主要参考资料是Thermaldotnet(sparkfun打印机的库)github.com/yukimizake/Thermaldotnet

Spider上的SPI:tinycrr.com/forum/21/6621/

还有一个基本的SPI示例:*wiki.tinycr.com/index.php?title=SPI\uu-\uMP3\u解码器*

我如何看到字节传输来判断是否有任何东西在实际工作

到目前为止,我所拥有的:

using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;
using Microsoft.SPOT.Hardware;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;

namespace printTherm
{
public partial class Program
{
    static SPI MySPI = null;
    public static void Sub()
    {

        InputPort Therm;
        Therm = new InputPort(Cpu.Pin.GPIO_Pin8, false, Port.ResistorMode.PullUp);

        SPI.Configuration MyConfig =
             new SPI.Configuration(Cpu.Pin.GPIO_Pin8,
             false, 0, 0, true, true, 1000, SPI.SPI_module.SPI1);
        MySPI = new SPI(MyConfig);



        bool exit = false;
        do
        {
            byte[] tx_data = new byte[1];
            byte[] rx_data = new byte[0];
            while (Therm.Read() == true) ;

            tx_data[0] = 0x01;
            tx_data[1] = 0x00;

            MySPI.WriteRead(tx_data, rx_data);

            while (Therm.Read() == false) ;
            byte[] tx_data2 = new byte[28];
            byte[] rx_data2 = new byte[28];
            for (int i = 0; i < 28; i++)
            {
                tx_data2[i] = 0xFF;
                rx_data2[i] = 0x00;
            }
            MySPI.WriteRead(tx_data2, rx_data2);
        } while (exit == false);


        Thread.Sleep(100);
    }

    // This method is run when the mainboard is powered up or reset.   
    void ProgramStarted()
    {

        Debug.Print("Program Started");
    }
}
}
使用系统;
使用系统集合;
使用系统线程;
使用Microsoft.SPOT;
使用Microsoft.SPOT.Presentation;
使用Microsoft.SPOT.Presentation.Controls;
使用Microsoft.SPOT.Presentation.Media;
使用Microsoft.SPOT.Touch;
使用Microsoft.SPOT.Hardware;
使用Gadgeter。联网;
使用GT=Gadgeteer;
使用GTM=小工具模块;
使用gadgeter.Modules.GHIElectronics;
名称空间printTherm
{
公共部分课程
{
静态SPI MySPI=null;
公共静态void Sub()
{
输入端口温度;
Therm=新的输入端口(Cpu.Pin.GPIO_Pin8,false,Port.ResistorMode.PullUp);
SPI.配置MyConfig=
新SPI.配置(Cpu.Pin.GPIO_Pin8,
false,0,0,true,true,1000,SPI.SPI_module.SPI1);
MySPI=新SPI(MyConfig);
bool exit=false;
做
{
字节[]tx_data=新字节[1];
字节[]rx_数据=新字节[0];
while(Therm.Read()==true);
tx_数据[0]=0x01;
tx_数据[1]=0x00;
MySPI.WriteRead(发送数据、接收数据);
while(Therm.Read()==false);
字节[]tx_data2=新字节[28];
字节[]rx_data2=新字节[28];
对于(int i=0;i<28;i++)
{
tx_data2[i]=0xFF;
rx_数据2[i]=0x00;
}
MySPI.WriteRead(发送数据2,接收数据2);
}while(exit==false);
睡眠(100);
}
//此方法在主板通电或复位时运行。
void ProgramStarted()
{
打印(“程序启动”);
}
}
}
它几乎与上面的代码完全相同,只是我将Pin更改为8(MISO)并添加了一些数组内容。我现在真的快要失明了。我对这件事知之甚少,感到很难过,但任何小小的帮助都将不胜感激

对于对此感兴趣的任何人,请提供更多资源: 完整音乐盾代码:code.tinycrr.com/project/330/fez-music-shield/

文档:msdn.microsoft.com/en-us/library/ee436313.aspx 更多文档:netmf.com/Gadgeteer/docs/GadgeteerCore/2.41.500/html/0d40434b-2a84-2f72-ca4d-b0012535ea58.htm

对于非超链接表示抱歉+提前感谢