资源简介
此demo为激光打标机的客户端代码,发送指令到服务端,使用到tcp通信中的socket来接收发送数据

代码片段和文件信息
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.IO;
using System.Threading;
using System.Collections;
namespace TcpConnectDemo
{
public partial class Form1 : Form
{
enum WorkState
{
START
PUT
GPRT
WAIT
};
private string gb_strFileName;
private SocketClient gb_sockClient;
private string gb_strIp = “192.168.1.100“;
// 服务端端口
private Int16 gb_nPort = 3875;
//工作线程
private Thread gb_wrokThread;
//工作流程
private static WorkState gb_State = WorkState.START;
//线程停止标志位
private static bool gb_bIsStop = true;
//线程发送消息标志位,每个流程只发送一次消息,发送后循环接收消息
private static bool gb_bIsSend = false;
private static bool gb_bIsGprt = false;
//存储标刻序列号,
//文本格式:
//AABBCC
//DDEEFF
//...
//一行数据:需要PUT的数据
private static ArrayList gb_arrayMarkData = new ArrayList();
//线程锁,防止线程改变标志位时冲突
public static object gb_lockStop = new object();
public static object gb_lockRecv = new object();
public static object gb_lockSend = new object();
public static object gb_lockGprt = new object();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender EventArgs e)
{
//初始化Sock类,设置IP、端口号
gb_sockClient = new SocketClient(gb_strIp gb_nPort);
//gb_sockClient.SetTexts += new SocketClient.SetText(SetText);
//设置按钮使能
btnStart.Enabled = false;
btnGprt.Enabled = false;
}
//打开文本数据,存储到gb_arrayMarkData
private void 打开文件ToolStripMenuItem_Click(object sender EventArgs e)
{
OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog();
openFileDialog.title = “打开“;
if(openFileDialog.ShowDialog() == DialogResult.OK)
{
string strFileName = openFileDialog.FileName;
if (!File.Exists(strFileName))
{
SetText(“文件不存在!“false);
return;
}
gb_strFileName = strFileName;
ReadTxtData();
if (gb_arrayMarkData.Count > 0)
{
SetText(“文件已打开!“ false);
}
else
{
SetText(“文件数据为空!“ false);
}
}
else
{
//SetText(“已取消打开文件!“ false);
return;
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-10-26 10:48 TcpConnectDemo\
目录 0 2019-10-26 10:48 TcpConnectDemo\.vs\
目录 0 2019-10-26 10:48 TcpConnectDemo\.vs\TcpConnectDemo\
目录 0 2019-10-26 10:48 TcpConnectDemo\.vs\TcpConnectDemo\v15\
文件 49664 2019-11-01 14:56 TcpConnectDemo\.vs\TcpConnectDemo\v15\.suo
目录 0 2019-10-26 10:48 TcpConnectDemo\.vs\TcpConnectDemo\v15\Server\
目录 0 2019-10-26 10:48 TcpConnectDemo\.vs\TcpConnectDemo\v15\Server\sqlite3\
文件 0 2019-10-24 15:01 TcpConnectDemo\.vs\TcpConnectDemo\v15\Server\sqlite3\db.lock
文件 573440 2019-10-26 09:38 TcpConnectDemo\.vs\TcpConnectDemo\v15\Server\sqlite3\storage.ide
文件 32768 2019-11-01 08:22 TcpConnectDemo\.vs\TcpConnectDemo\v15\Server\sqlite3\storage.ide-shm
文件 4140632 2019-11-01 08:22 TcpConnectDemo\.vs\TcpConnectDemo\v15\Server\sqlite3\storage.ide-wal
目录 0 2019-10-26 10:48 TcpConnectDemo\TcpConnectDemo\
文件 7412 2019-10-25 15:21 TcpConnectDemo\TcpConnectDemo\Form1.Designer.cs
文件 33471 2019-10-26 09:47 TcpConnectDemo\TcpConnectDemo\Form1.cs
文件 6015 2019-10-25 15:21 TcpConnectDemo\TcpConnectDemo\Form1.resx
文件 495 2019-10-24 15:01 TcpConnectDemo\TcpConnectDemo\Program.cs
目录 0 2019-10-26 10:48 TcpConnectDemo\TcpConnectDemo\Properties\
文件 1344 2019-10-24 15:01 TcpConnectDemo\TcpConnectDemo\Properties\AssemblyInfo.cs
文件 2841 2019-10-24 15:01 TcpConnectDemo\TcpConnectDemo\Properties\Resources.Designer.cs
文件 5612 2019-10-24 15:01 TcpConnectDemo\TcpConnectDemo\Properties\Resources.resx
文件 1101 2019-10-24 15:01 TcpConnectDemo\TcpConnectDemo\Properties\Settings.Designer.cs
文件 249 2019-10-24 15:01 TcpConnectDemo\TcpConnectDemo\Properties\Settings.settings
文件 4090 2019-10-26 09:17 TcpConnectDemo\TcpConnectDemo\SocketClient.cs
文件 3475 2019-10-24 16:54 TcpConnectDemo\TcpConnectDemo\TcpConnectDemo.csproj
目录 0 2019-10-26 10:48 TcpConnectDemo\TcpConnectDemo\bin\
目录 0 2019-10-26 10:48 TcpConnectDemo\TcpConnectDemo\bin\Debug\
文件 22016 2019-10-26 09:47 TcpConnectDemo\TcpConnectDemo\bin\Debug\TcpConnectDemo.exe
文件 54784 2019-10-26 09:47 TcpConnectDemo\TcpConnectDemo\bin\Debug\TcpConnectDemo.pdb
目录 0 2019-10-26 10:48 TcpConnectDemo\TcpConnectDemo\obj\
目录 0 2019-10-26 10:48 TcpConnectDemo\TcpConnectDemo\obj\Debug\
文件 1431 2019-10-25 09:20 TcpConnectDemo\TcpConnectDemo\obj\Debug\DesignTimeResolveAssemblyReferences.cache
............此处省略11个文件信息
- 上一篇:labview专用卸载工具
- 下一篇:LAStool读取和保存.las格式点云
相关资源
- WPF USB 网络 串口 通信软件
- B/S 网上订餐系统
- 通信软件的具体实例──基于Socket的
- 教室管理系统.rar
- 用Socket编程实现FTP
- 小鸡快跑游戏.
- websocket实现一对一聊天
-
分别适用于.NET fr
amework 2.0和4.0的E - 汽车租赁系统............................
- 德卡D8读写器关于读写感应卡的一些代
- halcon 测量助手
- 代码客:G-TcpServer(IOCP) 1.0 正式版及
- 图片存储到数据库保存二进制文件并
- SOCKET 网络编程 计算机网络 作业 客户
- linux 网络实验 ftp程序
- 用Socket写的简易FTP服务器和客户端
- 企业销售管理信息系统(全套)
- socket小工具(可方便建立TCP UDP的soc
- 串口操作类(justinio)
- socket客户端源码
- 基于Petri网的工作流(完整的原创源代
- 选择题自动考试系统
- 多线程实例:桌面智能弹球小游戏
- 基于CSocket的多人聊天室
- socket文件传输源码
- Socket自制系统
- HP用SOCKET实现(客户端---服务端)
- 土地信息管理系统
- ServiceStack V3.9 全部dll
- PDF pdfview.ocx 无水印
评论
共有 条评论