using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace ComReader_Sharp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
InitComPort();
// Send data out through the COM port
com.Output = "Serial Terminal Initialized";
} private void InitComPort()
{
// Set the com port to be 1
com.CommPort = 1; // This port is already open, close it to reset it.
if (com.PortOpen) com.PortOpen = false;
// Trigger the OnComm event whenever data is received
com.RThreshold = 1; // Set the port to 9600 baud, no parity bit, 8 data bits, 1 stop bit (all standard)
com.Settings = "9600,n,8,1"; // Force the DTR line high, used sometimes to hang up modems
com.DTREnable = true;
com.RTSEnable = true;
// No handshaking is used
com.Handshaking = MSCommLib.HandshakeConstants.comNone; // Don't mess with byte arrays, only works with simple data (characters A-Z and numbers)
com.InputMode = MSCommLib.InputModeConstants.comInputModeText; // Use this line instead for byte array input, best for most communications
//com.InputMode = MSCommLib.InputModeConstants.comInputModeText; // Read the entire waiting data when com.Input is used
com.InputLen = 0; // Don't discard nulls, 0x00 is a useful byte
com.NullDiscard = false; // Attach the event handler
com.OnComm += new System.EventHandler(this.OnComm); // Open the com port
com.PortOpen = true;
}
private void OnComm(object sender, EventArgs e) // MSCommLib OnComm Event Handler
{
// If data is waiting in the buffer, process it.
// Note: This is using the string method for simple data, be sure
// to use byte arrays (described below) for more generic data.
if (com.InBufferCount > 0) ProcessComData();
}
private void ProcessComData()
{
// Send incoming data to a Rich Text Box
char input =Convert.ToChar ( com.Input);
rtfTerminal.AppendText(input.ToString() + "\n"); //rtfTerminal 是richTextBox
}////////////////////////////////////////////
用来读取单片机程序的
现在读取来成数据不对
大家帮我验证一下再附上单片机端的代码吧
看看到底那块不对
#include <c8051f340.h>
#define uchar unsigned char
#define uint unsigned int
void PORT_Init (void)
{
XBR0 = 0x01; // Port I/O Crossbar Control 0
XBR1 = 0x40; //Port I/O Crossbar Control 1
P0MDOUT = 0x10; //Port 0 Output Mode Configuration 输出模式配置 }void UART0_Init (void)
{
SCON0 |= 0x10; // Port I/O Crossbar Control 0
CKCON = 0x01; // Clock Control时钟控制
TH1 = 0x64; //波特率为9600 // Timer/Counter 1 High 计时器一高位
TL1 = TH1; // Timer/Counter 1 Low 计时器一低位
TMOD = 0x20; // Timer/Counter Mode 时间计数模式
TR1 = 1; /// Timer1 on/off control 启动time1
TI0 = 1; //Transmit interrupt flag 传输中断标示
}void delay(void)
{
uint i;
for(i=1000;i>0;i--); }
void main()
{
char g;
PCA0MD &= ~0x40; // PCA0 Mode 模式
OSCICN |= 0x03; // Internal Oscillator Control 内部振荡器控制
PORT_Init(); //端口初始化
UART0_Init(); //串口初始化
g=9;
while(1)
{
delay();
SBUF0=g;//每次发送一个'9'
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace ComReader_Sharp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
InitComPort();
// Send data out through the COM port
com.Output = "Serial Terminal Initialized";
} private void InitComPort()
{
// Set the com port to be 1
com.CommPort = 1; // This port is already open, close it to reset it.
if (com.PortOpen) com.PortOpen = false;
// Trigger the OnComm event whenever data is received
com.RThreshold = 1; // Set the port to 9600 baud, no parity bit, 8 data bits, 1 stop bit (all standard)
com.Settings = "9600,n,8,1"; // Force the DTR line high, used sometimes to hang up modems
com.DTREnable = true;
com.RTSEnable = true;
// No handshaking is used
com.Handshaking = MSCommLib.HandshakeConstants.comNone; // Don't mess with byte arrays, only works with simple data (characters A-Z and numbers)
com.InputMode = MSCommLib.InputModeConstants.comInputModeText; // Use this line instead for byte array input, best for most communications
//com.InputMode = MSCommLib.InputModeConstants.comInputModeText; // Read the entire waiting data when com.Input is used
com.InputLen = 0; // Don't discard nulls, 0x00 is a useful byte
com.NullDiscard = false; // Attach the event handler
com.OnComm += new System.EventHandler(this.OnComm); // Open the com port
com.PortOpen = true;
}
private void OnComm(object sender, EventArgs e) // MSCommLib OnComm Event Handler
{
// If data is waiting in the buffer, process it.
// Note: This is using the string method for simple data, be sure
// to use byte arrays (described below) for more generic data.
if (com.InBufferCount > 0) ProcessComData();
}
private void ProcessComData()
{
// Send incoming data to a Rich Text Box
char input =Convert.ToChar ( com.Input);
rtfTerminal.AppendText(input.ToString() + "\n"); //rtfTerminal 是richTextBox
}////////////////////////////////////////////
用来读取单片机程序的
现在读取来成数据不对
大家帮我验证一下再附上单片机端的代码吧
看看到底那块不对
#include <c8051f340.h>
#define uchar unsigned char
#define uint unsigned int
void PORT_Init (void)
{
XBR0 = 0x01; // Port I/O Crossbar Control 0
XBR1 = 0x40; //Port I/O Crossbar Control 1
P0MDOUT = 0x10; //Port 0 Output Mode Configuration 输出模式配置 }void UART0_Init (void)
{
SCON0 |= 0x10; // Port I/O Crossbar Control 0
CKCON = 0x01; // Clock Control时钟控制
TH1 = 0x64; //波特率为9600 // Timer/Counter 1 High 计时器一高位
TL1 = TH1; // Timer/Counter 1 Low 计时器一低位
TMOD = 0x20; // Timer/Counter Mode 时间计数模式
TR1 = 1; /// Timer1 on/off control 启动time1
TI0 = 1; //Transmit interrupt flag 传输中断标示
}void delay(void)
{
uint i;
for(i=1000;i>0;i--); }
void main()
{
char g;
PCA0MD &= ~0x40; // PCA0 Mode 模式
OSCICN |= 0x03; // Internal Oscillator Control 内部振荡器控制
PORT_Init(); //端口初始化
UART0_Init(); //串口初始化
g=9;
while(1)
{
delay();
SBUF0=g;//每次发送一个'9'
}
}
解决方案 »
- 关于C/S架构
- 通过WMI取出来的CPU ID 为null值,还有其他方法取CPU ID吗?
- Winform怎么将两个窗体的内容都同时传到一个窗体中
- c# 中动态生成类文件以及添加相应属性
- 有没有人做过手机开发?能不能谈点经验!
- 我把一个List<T> 作为一个Object对象传到一个方法里了,那这个方法怎么获取List里面的值呢?
- 在网页上删除文件,
- datatable 导入 excel (有关图片) 谢谢
- .net的FrameWork是否相当于java的虚拟机
- 用中文vs.net2003开发的英文程序在英文windows2000 中安装失败,好像也是乱码怎么办呀?
- 请高手指点下c#浏览器跳转默认浏览器问题
- 关于GRIDVIEW根据VALUE显示不同TEXT的方法
单片机端发送这个数据:
char g;
g=9;
SBUF0=g;//每次发送一个'9'在PC端要通过Com口读取到‘9’!但是
g=‘9’是 读取的是/r/r/r/r/r/r/r/r/r/r/r/r/r/r/r/r..........
g=‘a’时 读取的是乱码了 但是很多
char g;
g=9;
SBUF0=g;//每次发送一个'9'在PC端要通过Com口读取到‘9’!但是
g=‘9’是 读取的是/r/r/r/r/r/r/r/r/r/r/r/r/r/r/r/r..........
g=‘a’时 读取的是乱码了 但是很多