资源简介
51单片机8路高精度舵机下位机及C#上位机程序
代码片段和文件信息
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;
using System.Net;
using System.Net.Sockets;
using System.IO;
using Microsoft.Win32;
using System.Runtime.InteropServices;
namespace WifiVideo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//声明读写INI文件的API函数
[DllImport(“kernel32“)]
private static extern bool WritePrivateProfileString(string section string key string val string filePath);
[DllImport(“kernel32“)]
private static extern int GetPrivateProfileString(string section string key string def byte[] retVal int size string filePath);
static string FileName = (Application.StartupPath + @“\Config.ini“);
public string ReadIni(string Section string Ident string Default)
{
Byte[] Buffer = new Byte[65535];
int bufLen = GetPrivateProfileString(Section Ident Default Buffer Buffer.GetUpperBound(0) FileName);
string s = Encoding.GetEncoding(0).GetString(Buffer);
s = s.Substring(0 bufLen);
return s.Trim();
}
string CameraIp = ““;
string ControlIp = “192.168.1.1“;
string Port = “81“;
string CMD_Servo1_1 = ““ CMD_Servo1_2 = ““;
string CMD_Servo2_1 = ““ CMD_Servo2_2 = ““;
string CMD_Servo3_1 = ““ CMD_Servo3_2 = ““;
string CMD_Servo4_1 = ““ CMD_Servo4_2 = ““;
string CMD_Servo5_1 = ““ CMD_Servo5_2 = ““;
string CMD_Servo6_1 = ““ CMD_Servo6_2 = ““;
Socket socket = null;
private void timer1_Tick(object sender EventArgs e)
{
pictureBox1.ImageLocation = CameraIp;// “http://192.168.1.1:8080/?action=snapshot“;
}
void SendData(char char1 char char2)
{
try
{
label2.Text = Convert.ToInt16(char1) + ““ + Convert.ToInt16(char2);
byte[] bs = { Convert.ToByte(char1) Convert.ToByte(char2) };//Encoding.ASCII 是得不到8位ASCII码的
socket.Send(bs bs.Length 0);//发送测试信息
}
catch (Exception ec)
{
MessageBox.Show(ec.Message);
}
}
private void Form1_Load(object sender EventArgs e)
{
GetIni();
try
{
IPAddress ips = IPAddress.Parse(ControlIp.ToString());//(“192.168.2.1“);
IPEndPoint ipe = new IPEndPoint(ips Convert.ToInt32(Port.ToString()));//把ip和端口转化为IPEndPoint实例
socket = new Socket(AddressFamily.InterNetwork SocketType.Stream ProtocolType.Tcp);//创建一个Socket
socket.Connect(ipe);//连接到服务器
}
catch (Exception ec)
{
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2012-02-19 23:28 Debug\
文件 466 2012-01-04 21:50 Debug\Config.ini
文件 1627 2012-01-05 21:26 Debug\WifiVideo.application
文件 25600 2012-01-05 21:26 Debug\WifiVideo.exe
文件 3633 2012-01-05 21:26 Debug\WifiVideo.exe.manifest
文件 44544 2012-01-05 21:26 Debug\WifiVideo.pdb
文件 1627 2012-01-05 21:26 Debug\WifiVideo.vshost.application
文件 11608 2012-01-05 21:27 Debug\WifiVideo.vshost.exe
文件 3633 2012-01-05 21:26 Debug\WifiVideo.vshost.exe.manifest
文件 3417 2012-02-17 22:04 串口收发.hex
文件 5393 2012-02-17 22:04 串口收发.c
文件 7721 2012-01-08 23:40 Form1.cs
- 上一篇:高斯正反算C#实现
- 下一篇:基于keras多层LSTM实现数据集
评论
共有 条评论